winhttp_api_wrapper_impl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef SERVICES_PROXY_RESOLVER_WIN_WINHTTP_API_WRAPPER_IMPL_H_
  5. #define SERVICES_PROXY_RESOLVER_WIN_WINHTTP_API_WRAPPER_IMPL_H_
  6. #include <windows.h>
  7. #include <winhttp.h>
  8. #include <string>
  9. #include "services/proxy_resolver_win/winhttp_api_wrapper.h"
  10. namespace proxy_resolver_win {
  11. // This is a utility class that encapsulates the memory management necessary for
  12. // WINHTTP_CURRENT_USER_IE_PROXY_CONFIG in RAII style.
  13. class ScopedIEConfig final {
  14. public:
  15. ScopedIEConfig();
  16. ScopedIEConfig(const ScopedIEConfig&) = delete;
  17. ScopedIEConfig& operator=(const ScopedIEConfig&) = delete;
  18. ~ScopedIEConfig();
  19. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config() { return &ie_config; }
  20. private:
  21. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0};
  22. };
  23. // This is the implementation of WinHttpAPIWrapper that gets used in the
  24. // product.
  25. class WinHttpAPIWrapperImpl final : public WinHttpAPIWrapper {
  26. public:
  27. WinHttpAPIWrapperImpl();
  28. WinHttpAPIWrapperImpl(const WinHttpAPIWrapperImpl&) = delete;
  29. WinHttpAPIWrapperImpl& operator=(const WinHttpAPIWrapperImpl&) = delete;
  30. ~WinHttpAPIWrapperImpl() override;
  31. // WinHttpAPIWrapper Implementation
  32. bool CallWinHttpOpen() override;
  33. bool CallWinHttpSetTimeouts(int resolve_timeout,
  34. int connect_timeout,
  35. int send_timeout,
  36. int receive_timeout) override;
  37. bool CallWinHttpSetStatusCallback(
  38. WINHTTP_STATUS_CALLBACK internet_callback) override;
  39. bool CallWinHttpGetIEProxyConfigForCurrentUser(
  40. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* ie_proxy_config) override;
  41. bool CallWinHttpCreateProxyResolver(HINTERNET* out_resolver_handle) override;
  42. bool CallWinHttpGetProxyForUrlEx(HINTERNET resolver_handle,
  43. const std::string& url,
  44. WINHTTP_AUTOPROXY_OPTIONS* autoproxy_options,
  45. DWORD_PTR context) override;
  46. bool CallWinHttpGetProxyResult(HINTERNET resolver_handle,
  47. WINHTTP_PROXY_RESULT* proxy_result) override;
  48. void CallWinHttpFreeProxyResult(WINHTTP_PROXY_RESULT* proxy_result) override;
  49. void CallWinHttpCloseHandle(HINTERNET internet_handle) override;
  50. private:
  51. // Closes |session_handle_|.
  52. void CloseSessionHandle();
  53. HINTERNET session_handle_ = nullptr;
  54. };
  55. } // namespace proxy_resolver_win
  56. #endif // SERVICES_PROXY_RESOLVER_WIN_WINHTTP_API_WRAPPER_IMPL_H_