| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "net/proxy/proxy_config_service_win.h" | 5 #include "net/proxy/proxy_config_service_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <winhttp.h> | 8 #include <winhttp.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/string_tokenizer.h" | 12 #include "base/string_tokenizer.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "base/thread_restrictions.h" | |
| 16 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/proxy/proxy_config.h" | 17 #include "net/proxy/proxy_config.h" |
| 19 | 18 |
| 20 #pragma comment(lib, "winhttp.lib") | 19 #pragma comment(lib, "winhttp.lib") |
| 21 | 20 |
| 22 namespace net { | 21 namespace net { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 base::ObjectWatcher watcher_; | 65 base::ObjectWatcher watcher_; |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 ProxyConfigServiceWin::ProxyConfigServiceWin() | 68 ProxyConfigServiceWin::ProxyConfigServiceWin() |
| 70 : PollingProxyConfigService( | 69 : PollingProxyConfigService( |
| 71 base::TimeDelta::FromSeconds(kPollIntervalSec), | 70 base::TimeDelta::FromSeconds(kPollIntervalSec), |
| 72 &ProxyConfigServiceWin::GetCurrentProxyConfig) { | 71 &ProxyConfigServiceWin::GetCurrentProxyConfig) { |
| 73 } | 72 } |
| 74 | 73 |
| 75 ProxyConfigServiceWin::~ProxyConfigServiceWin() { | 74 ProxyConfigServiceWin::~ProxyConfigServiceWin() { |
| 76 // The registry functions below will end up going to disk. Do this on another | |
| 77 // thread to avoid slowing the IO thread. http://crbug.com/61453 | |
| 78 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 79 STLDeleteElements(&keys_to_watch_); | 75 STLDeleteElements(&keys_to_watch_); |
| 80 } | 76 } |
| 81 | 77 |
| 82 void ProxyConfigServiceWin::AddObserver(Observer* observer) { | 78 void ProxyConfigServiceWin::AddObserver(Observer* observer) { |
| 83 // Lazily-initialize our registry watcher. | 79 // Lazily-initialize our registry watcher. |
| 84 StartWatchingRegistryForChanges(); | 80 StartWatchingRegistryForChanges(); |
| 85 | 81 |
| 86 // Let the super-class do its work now. | 82 // Let the super-class do its work now. |
| 87 PollingProxyConfigService::AddObserver(observer); | 83 PollingProxyConfigService::AddObserver(observer); |
| 88 } | 84 } |
| 89 | 85 |
| 90 void ProxyConfigServiceWin::StartWatchingRegistryForChanges() { | 86 void ProxyConfigServiceWin::StartWatchingRegistryForChanges() { |
| 91 if (!keys_to_watch_.empty()) | 87 if (!keys_to_watch_.empty()) |
| 92 return; // Already initialized. | 88 return; // Already initialized. |
| 93 | 89 |
| 94 // The registry functions below will end up going to disk. Do this on another | |
| 95 // thread to avoid slowing the IO thread. http://crbug.com/61453 | |
| 96 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 97 | |
| 98 // There are a number of different places where proxy settings can live | 90 // There are a number of different places where proxy settings can live |
| 99 // in the registry. In some cases it appears in a binary value, in other | 91 // in the registry. In some cases it appears in a binary value, in other |
| 100 // cases string values. Furthermore winhttp and wininet appear to have | 92 // cases string values. Furthermore winhttp and wininet appear to have |
| 101 // separate stores, and proxy settings can be configured per-machine | 93 // separate stores, and proxy settings can be configured per-machine |
| 102 // or per-user. | 94 // or per-user. |
| 103 // | 95 // |
| 104 // This function is probably not exhaustive in the registry locations it | 96 // This function is probably not exhaustive in the registry locations it |
| 105 // watches for changes, however it should catch the majority of the | 97 // watches for changes, however it should catch the majority of the |
| 106 // cases. In case we have missed some less common triggers (likely), we | 98 // cases. In case we have missed some less common triggers (likely), we |
| 107 // will catch them during the periodic (10 second) polling, so things | 99 // will catch them during the periodic (10 second) polling, so things |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 while (proxy_server_bypass_list.GetNext()) { | 175 while (proxy_server_bypass_list.GetNext()) { |
| 184 std::string bypass_url_domain = proxy_server_bypass_list.token(); | 176 std::string bypass_url_domain = proxy_server_bypass_list.token(); |
| 185 config->proxy_rules().bypass_rules.AddRuleFromString(bypass_url_domain); | 177 config->proxy_rules().bypass_rules.AddRuleFromString(bypass_url_domain); |
| 186 } | 178 } |
| 187 } | 179 } |
| 188 if (ie_config.lpszAutoConfigUrl) | 180 if (ie_config.lpszAutoConfigUrl) |
| 189 config->set_pac_url(GURL(ie_config.lpszAutoConfigUrl)); | 181 config->set_pac_url(GURL(ie_config.lpszAutoConfigUrl)); |
| 190 } | 182 } |
| 191 | 183 |
| 192 } // namespace net | 184 } // namespace net |
| OLD | NEW |