summaryrefslogtreecommitdiff
path: root/chromium/components/winhttp/scoped_hinternet.h
blob: c6ebfb17fb867e74cf3d59f6e9afbdb66274cd23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_
#define COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_

#include <windows.h>
#include <winhttp.h>

#include "base/scoped_generic.h"

namespace winhttp {

namespace internal {

struct ScopedHInternetTraits {
  static HINTERNET InvalidValue() { return nullptr; }
  static void Free(HINTERNET handle) {
    if (handle != InvalidValue())
      WinHttpCloseHandle(handle);
  }
};

}  // namespace internal

// Manages the lifetime of HINTERNET handles allocated by WinHTTP.
using ScopedHInternet =
    base::ScopedGeneric<HINTERNET, internal::ScopedHInternetTraits>;

// Creates a new WinHttp session using the given user agent and properly
// configured for the Windows OS version.
ScopedHInternet CreateSessionHandle(const wchar_t* user_agent,
                                    int proxy_access_type);

}  // namespace winhttp

#endif  // COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_