scoped_hinternet.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_
  5. #define COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_
  6. #include <windows.h>
  7. #include <winhttp.h>
  8. #include "base/scoped_generic.h"
  9. namespace winhttp {
  10. namespace internal {
  11. struct ScopedHInternetTraits {
  12. static HINTERNET InvalidValue() { return nullptr; }
  13. static void Free(HINTERNET handle) {
  14. if (handle != InvalidValue())
  15. WinHttpCloseHandle(handle);
  16. }
  17. };
  18. } // namespace internal
  19. // Manages the lifetime of HINTERNET handles allocated by WinHTTP.
  20. using ScopedHInternet =
  21. base::ScopedGeneric<HINTERNET, internal::ScopedHInternetTraits>;
  22. // Creates a new WinHttp session using the given user agent and properly
  23. // configured for the Windows OS version.
  24. ScopedHInternet CreateSessionHandle(const wchar_t* user_agent,
  25. int proxy_access_type);
  26. } // namespace winhttp
  27. #endif // COMPONENTS_WINHTTP_SCOPED_HINTERNET_H_