OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ | 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ |
6 #define NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ | 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <winhttp.h> | 9 #include <winhttp.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/win/object_watcher.h" | |
16 #include "net/proxy/polling_proxy_config_service.h" | 15 #include "net/proxy/polling_proxy_config_service.h" |
17 | 16 |
17 namespace base { | |
18 namespace win { | |
19 class RegKey; | |
20 } | |
21 } // namespace base. | |
22 | |
18 namespace net { | 23 namespace net { |
19 | 24 |
20 // Implementation of ProxyConfigService that retrieves the system proxy | 25 // Implementation of ProxyConfigService that retrieves the system proxy |
21 // settings. | 26 // settings. |
22 // | 27 // |
23 // It works by calling WinHttpGetIEProxyConfigForCurrentUser() to fetch the | 28 // It works by calling WinHttpGetIEProxyConfigForCurrentUser() to fetch the |
24 // Internet Explorer proxy settings. | 29 // Internet Explorer proxy settings. |
25 // | 30 // |
26 // We use two different strategies to notice when the configuration has | 31 // We use two different strategies to notice when the configuration has |
27 // changed: | 32 // changed: |
28 // | 33 // |
29 // (1) Watch the internet explorer settings registry keys for changes. When | 34 // (1) Watch the internet explorer settings registry keys for changes. When |
30 // one of the registry keys pertaining to proxy settings has changed, we | 35 // one of the registry keys pertaining to proxy settings has changed, we |
31 // call WinHttpGetIEProxyConfigForCurrentUser() again to read the | 36 // call WinHttpGetIEProxyConfigForCurrentUser() again to read the |
32 // configuration's new value. | 37 // configuration's new value. |
33 // | 38 // |
34 // (2) Do regular polling every 10 seconds during network activity to see if | 39 // (2) Do regular polling every 10 seconds during network activity to see if |
35 // WinHttpGetIEProxyConfigForCurrentUser() returns something different. | 40 // WinHttpGetIEProxyConfigForCurrentUser() returns something different. |
36 // | 41 // |
37 // Ideally strategy (1) should be sufficient to pick up all of the changes. | 42 // Ideally strategy (1) should be sufficient to pick up all of the changes. |
38 // However we still do the regular polling as a precaution in case the | 43 // However we still do the regular polling as a precaution in case the |
39 // implementation details of WinHttpGetIEProxyConfigForCurrentUser() ever | 44 // implementation details of WinHttpGetIEProxyConfigForCurrentUser() ever |
40 // change, or in case we got it wrong (and are not checking all possible | 45 // change, or in case we got it wrong (and are not checking all possible |
41 // registry dependencies). | 46 // registry dependencies). |
42 class NET_EXPORT_PRIVATE ProxyConfigServiceWin | 47 class NET_EXPORT_PRIVATE ProxyConfigServiceWin |
43 : public PollingProxyConfigService, | 48 : public PollingProxyConfigService { |
44 public base::win::ObjectWatcher::Delegate { | |
45 public: | 49 public: |
46 ProxyConfigServiceWin(); | 50 ProxyConfigServiceWin(); |
47 virtual ~ProxyConfigServiceWin(); | 51 virtual ~ProxyConfigServiceWin(); |
48 | 52 |
49 // Overrides a function from PollingProxyConfigService. | 53 // Overrides a function from PollingProxyConfigService. |
50 virtual void AddObserver(Observer* observer) OVERRIDE; | 54 virtual void AddObserver(Observer* observer) OVERRIDE; |
51 | 55 |
52 private: | 56 private: |
53 FRIEND_TEST_ALL_PREFIXES(ProxyConfigServiceWinTest, SetFromIEConfig); | 57 FRIEND_TEST_ALL_PREFIXES(ProxyConfigServiceWinTest, SetFromIEConfig); |
54 class KeyEntry; | 58 typedef std::vector<base::win::RegKey*> KeyEntryList; |
eroman
2014/10/10 21:34:35
Can you rename this to RegKeyList ?
rvargas (doing something else)
2014/10/10 22:22:05
Done.
| |
55 typedef std::vector<KeyEntry*> KeyEntryList; | |
56 | 59 |
57 // Registers change observers on the registry keys relating to proxy settings. | 60 // Registers change observers on the registry keys relating to proxy settings. |
58 void StartWatchingRegistryForChanges(); | 61 void StartWatchingRegistryForChanges(); |
59 | 62 |
60 // Creates a new KeyEntry and appends it to |keys_to_watch_|. If the key | 63 // Creates a new KeyEntry and appends it to |keys_to_watch_|. If the key |
eroman
2014/10/10 21:34:35
Remove reference to KeyEntry
rvargas (doing something else)
2014/10/10 22:22:05
Done.
| |
61 // fails to be created, it is not appended to the list and we return false. | 64 // fails to be created, it is not appended to the list and we return false. |
62 bool AddKeyToWatchList(HKEY rootkey, const wchar_t* subkey); | 65 bool AddKeyToWatchList(HKEY rootkey, const wchar_t* subkey); |
63 | 66 |
64 // ObjectWatcher::Delegate methods: | 67 // ObjectWatcher::Delegate methods: |
eroman
2014/10/10 21:34:36
This line is no longer applicable.
rvargas (doing something else)
2014/10/10 22:22:05
Done.
| |
65 // This is called whenever one of the registry keys we are watching change. | 68 // This is called whenever one of the registry keys we are watching change. |
66 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 69 void OnObjectSignaled(base::win::RegKey* key); |
67 | 70 |
68 static void GetCurrentProxyConfig(ProxyConfig* config); | 71 static void GetCurrentProxyConfig(ProxyConfig* config); |
69 | 72 |
70 // Set |config| using the proxy configuration values of |ie_config|. | 73 // Set |config| using the proxy configuration values of |ie_config|. |
71 static void SetFromIEConfig( | 74 static void SetFromIEConfig( |
72 ProxyConfig* config, | 75 ProxyConfig* config, |
73 const WINHTTP_CURRENT_USER_IE_PROXY_CONFIG& ie_config); | 76 const WINHTTP_CURRENT_USER_IE_PROXY_CONFIG& ie_config); |
74 | 77 |
75 KeyEntryList keys_to_watch_; | 78 KeyEntryList keys_to_watch_; |
76 }; | 79 }; |
77 | 80 |
78 } // namespace net | 81 } // namespace net |
79 | 82 |
80 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ | 83 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ |
OLD | NEW |