OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_mac.h" | 5 #include "net/proxy/proxy_config_service_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <SystemConfiguration/SystemConfiguration.h> | 8 #include <SystemConfiguration/SystemConfiguration.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
16 #include "net/proxy/proxy_info.h" | 16 #include "net/proxy/proxy_info.h" |
17 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kPollIntervalSec = 5; | 23 const int kPollIntervalSec = 5; |
24 | 24 |
25 // Utility function to pull out a boolean value from a dictionary and return it, | 25 // Utility function to pull out a boolean value from a dictionary and return it, |
26 // returning a default value if the key is not present. | 26 // returning a default value if the key is not present. |
27 bool GetBoolFromDictionary(CFDictionaryRef dict, | 27 bool GetBoolFromDictionary(CFDictionaryRef dict, |
28 CFStringRef key, | 28 CFStringRef key, |
29 bool default_value) { | 29 bool default_value) { |
30 CFNumberRef number = (CFNumberRef)mac_util::GetValueFromDictionary( | 30 CFNumberRef number = (CFNumberRef)base::mac::GetValueFromDictionary( |
31 dict, key, CFNumberGetTypeID()); | 31 dict, key, CFNumberGetTypeID()); |
32 if (!number) | 32 if (!number) |
33 return default_value; | 33 return default_value; |
34 | 34 |
35 int int_value; | 35 int int_value; |
36 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) | 36 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) |
37 return int_value; | 37 return int_value; |
38 else | 38 else |
39 return default_value; | 39 return default_value; |
40 } | 40 } |
(...skipping 11 matching lines...) Expand all Loading... |
52 config->set_auto_detect( | 52 config->set_auto_detect( |
53 GetBoolFromDictionary(config_dict.get(), | 53 GetBoolFromDictionary(config_dict.get(), |
54 kSCPropNetProxiesProxyAutoDiscoveryEnable, | 54 kSCPropNetProxiesProxyAutoDiscoveryEnable, |
55 false)); | 55 false)); |
56 | 56 |
57 // PAC file | 57 // PAC file |
58 | 58 |
59 if (GetBoolFromDictionary(config_dict.get(), | 59 if (GetBoolFromDictionary(config_dict.get(), |
60 kSCPropNetProxiesProxyAutoConfigEnable, | 60 kSCPropNetProxiesProxyAutoConfigEnable, |
61 false)) { | 61 false)) { |
62 CFStringRef pac_url_ref = (CFStringRef)mac_util::GetValueFromDictionary( | 62 CFStringRef pac_url_ref = (CFStringRef)base::mac::GetValueFromDictionary( |
63 config_dict.get(), | 63 config_dict.get(), |
64 kSCPropNetProxiesProxyAutoConfigURLString, | 64 kSCPropNetProxiesProxyAutoConfigURLString, |
65 CFStringGetTypeID()); | 65 CFStringGetTypeID()); |
66 if (pac_url_ref) | 66 if (pac_url_ref) |
67 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); | 67 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); |
68 } | 68 } |
69 | 69 |
70 // proxies (for now ftp, http, https, and SOCKS) | 70 // proxies (for now ftp, http, https, and SOCKS) |
71 | 71 |
72 if (GetBoolFromDictionary(config_dict.get(), | 72 if (GetBoolFromDictionary(config_dict.get(), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (proxy_server.is_valid()) { | 122 if (proxy_server.is_valid()) { |
123 config->proxy_rules().type = | 123 config->proxy_rules().type = |
124 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 124 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
125 config->proxy_rules().fallback_proxy = proxy_server; | 125 config->proxy_rules().fallback_proxy = proxy_server; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 // proxy bypass list | 129 // proxy bypass list |
130 | 130 |
131 CFArrayRef bypass_array_ref = | 131 CFArrayRef bypass_array_ref = |
132 (CFArrayRef)mac_util::GetValueFromDictionary( | 132 (CFArrayRef)base::mac::GetValueFromDictionary( |
133 config_dict.get(), | 133 config_dict.get(), |
134 kSCPropNetProxiesExceptionsList, | 134 kSCPropNetProxiesExceptionsList, |
135 CFArrayGetTypeID()); | 135 CFArrayGetTypeID()); |
136 if (bypass_array_ref) { | 136 if (bypass_array_ref) { |
137 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); | 137 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); |
138 for (CFIndex i = 0; i < bypass_array_count; ++i) { | 138 for (CFIndex i = 0; i < bypass_array_count; ++i) { |
139 CFStringRef bypass_item_ref = | 139 CFStringRef bypass_item_ref = |
140 (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); | 140 (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); |
141 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { | 141 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { |
142 LOG(WARNING) << "Expected value for item " << i | 142 LOG(WARNING) << "Expected value for item " << i |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 259 |
260 // Keep track of the last value we have seen. | 260 // Keep track of the last value we have seen. |
261 has_fetched_config_ = true; | 261 has_fetched_config_ = true; |
262 last_config_fetched_ = new_config; | 262 last_config_fetched_ = new_config; |
263 | 263 |
264 // Notify all the observers. | 264 // Notify all the observers. |
265 FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(new_config)); | 265 FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(new_config)); |
266 } | 266 } |
267 | 267 |
268 } // namespace net | 268 } // namespace net |
OLD | NEW |