winhttp_proxy_resolver_functions.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2020 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. #include "services/proxy_resolver_win/winhttp_proxy_resolver_functions.h"
  5. #include "base/no_destructor.h"
  6. namespace proxy_resolver_win {
  7. WinHttpProxyResolverFunctions::WinHttpProxyResolverFunctions() {
  8. HMODULE winhttp_module =
  9. LoadLibraryEx(L"winhttp.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
  10. if (winhttp_module) {
  11. create_proxy_resolver = reinterpret_cast<WinHttpCreateProxyResolverFunc>(
  12. ::GetProcAddress(winhttp_module, "WinHttpCreateProxyResolver"));
  13. get_proxy_for_url_ex = reinterpret_cast<WinHttpGetProxyForUrlExFunc>(
  14. ::GetProcAddress(winhttp_module, "WinHttpGetProxyForUrlEx"));
  15. get_proxy_result = reinterpret_cast<WinHttpGetProxyResultFunc>(
  16. ::GetProcAddress(winhttp_module, "WinHttpGetProxyResult"));
  17. free_proxy_result = reinterpret_cast<WinHttpFreeProxyResultFunc>(
  18. ::GetProcAddress(winhttp_module, "WinHttpFreeProxyResult"));
  19. }
  20. }
  21. // Never called due to base::NoDestructor.
  22. WinHttpProxyResolverFunctions::~WinHttpProxyResolverFunctions() = default;
  23. bool WinHttpProxyResolverFunctions::are_all_functions_loaded() const {
  24. return create_proxy_resolver && get_proxy_for_url_ex && get_proxy_result &&
  25. free_proxy_result;
  26. }
  27. // static
  28. const WinHttpProxyResolverFunctions&
  29. WinHttpProxyResolverFunctions::GetInstance() {
  30. // This is a singleton for performance reasons. This avoids having to load
  31. // proxy resolver functions multiple times.
  32. static base::NoDestructor<WinHttpProxyResolverFunctions> instance;
  33. return *instance;
  34. }
  35. } // namespace proxy_resolver_win