Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: net/proxy/proxy_config_service_mac.cc

Issue 8528013: Convert plain C-style casts to use CFCastStrict and GetValueFromDictionary template (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/proxy/proxy_resolver_mac.cc » ('j') | net/proxy/proxy_resolver_mac.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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/foundation_util.h"
11 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
12 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "net/proxy/proxy_config.h" 17 #include "net/proxy/proxy_config.h"
17 #include "net/proxy/proxy_info.h" 18 #include "net/proxy/proxy_info.h"
18 #include "net/proxy/proxy_server.h" 19 #include "net/proxy/proxy_server.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 namespace { 23 namespace {
23 24
24 const int kPollIntervalSec = 5; 25 const int kPollIntervalSec = 5;
25 26
26 // Utility function to pull out a boolean value from a dictionary and return it, 27 // Utility function to pull out a boolean value from a dictionary and return it,
27 // returning a default value if the key is not present. 28 // returning a default value if the key is not present.
28 bool GetBoolFromDictionary(CFDictionaryRef dict, 29 bool GetBoolFromDictionary(CFDictionaryRef dict,
29 CFStringRef key, 30 CFStringRef key,
30 bool default_value) { 31 bool default_value) {
31 CFNumberRef number = (CFNumberRef)base::mac::GetValueFromDictionary( 32 CFNumberRef number =
32 dict, key, CFNumberGetTypeID()); 33 base::mac::CFCastStrict<CFNumberRef>(
Ryan Sleevi 2011/11/11 00:26:42 nit: You can align this to the previous line, and
KushalP 2011/11/11 11:03:19 In the case of GetValueFromDictionary() it should
Ryan Sleevi 2011/11/11 17:23:11 I think you misunderstood. I believe CFArrayGetVal
34 base::mac::GetValueFromDictionary(dict, key, CFNumberGetTypeID()));
33 if (!number) 35 if (!number)
34 return default_value; 36 return default_value;
35 37
36 int int_value; 38 int int_value;
37 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) 39 if (CFNumberGetValue(number, kCFNumberIntType, &int_value))
38 return int_value; 40 return int_value;
39 else 41 else
40 return default_value; 42 return default_value;
41 } 43 }
42 44
(...skipping 10 matching lines...) Expand all
53 config->set_auto_detect( 55 config->set_auto_detect(
54 GetBoolFromDictionary(config_dict.get(), 56 GetBoolFromDictionary(config_dict.get(),
55 kSCPropNetProxiesProxyAutoDiscoveryEnable, 57 kSCPropNetProxiesProxyAutoDiscoveryEnable,
56 false)); 58 false));
57 59
58 // PAC file 60 // PAC file
59 61
60 if (GetBoolFromDictionary(config_dict.get(), 62 if (GetBoolFromDictionary(config_dict.get(),
61 kSCPropNetProxiesProxyAutoConfigEnable, 63 kSCPropNetProxiesProxyAutoConfigEnable,
62 false)) { 64 false)) {
63 CFStringRef pac_url_ref = (CFStringRef)base::mac::GetValueFromDictionary( 65 CFStringRef pac_url_ref =
64 config_dict.get(), 66 base::mac::CFCastStrict<CFStringRef>(
65 kSCPropNetProxiesProxyAutoConfigURLString, 67 base::mac::GetValueFromDictionary(
66 CFStringGetTypeID()); 68 config_dict.get(),
69 kSCPropNetProxiesProxyAutoConfigURLString,
70 CFStringGetTypeID()));
67 if (pac_url_ref) 71 if (pac_url_ref)
68 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); 72 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref)));
69 } 73 }
70 74
71 // proxies (for now ftp, http, https, and SOCKS) 75 // proxies (for now ftp, http, https, and SOCKS)
72 76
73 if (GetBoolFromDictionary(config_dict.get(), 77 if (GetBoolFromDictionary(config_dict.get(),
74 kSCPropNetProxiesFTPEnable, 78 kSCPropNetProxiesFTPEnable,
75 false)) { 79 false)) {
76 ProxyServer proxy_server = 80 ProxyServer proxy_server =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (proxy_server.is_valid()) { 127 if (proxy_server.is_valid()) {
124 config->proxy_rules().type = 128 config->proxy_rules().type =
125 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; 129 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
126 config->proxy_rules().fallback_proxy = proxy_server; 130 config->proxy_rules().fallback_proxy = proxy_server;
127 } 131 }
128 } 132 }
129 133
130 // proxy bypass list 134 // proxy bypass list
131 135
132 CFArrayRef bypass_array_ref = 136 CFArrayRef bypass_array_ref =
133 (CFArrayRef)base::mac::GetValueFromDictionary( 137 base::mac::CFCastStrict<CFArrayRef>(base::mac::GetValueFromDictionary(
134 config_dict.get(), 138 config_dict.get(),
135 kSCPropNetProxiesExceptionsList, 139 kSCPropNetProxiesExceptionsList,
136 CFArrayGetTypeID()); 140 CFArrayGetTypeID()));
137 if (bypass_array_ref) { 141 if (bypass_array_ref) {
138 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); 142 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref);
139 for (CFIndex i = 0; i < bypass_array_count; ++i) { 143 for (CFIndex i = 0; i < bypass_array_count; ++i) {
140 CFStringRef bypass_item_ref = 144 CFStringRef bypass_item_ref = base::mac::CFCastStrict<CFStringRef>(
141 (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); 145 CFArrayGetValueAtIndex(bypass_array_ref, i));
142 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { 146 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) {
143 LOG(WARNING) << "Expected value for item " << i 147 LOG(WARNING) << "Expected value for item " << i
144 << " in the kSCPropNetProxiesExceptionsList" 148 << " in the kSCPropNetProxiesExceptionsList"
145 " to be a CFStringRef but it was not"; 149 " to be a CFStringRef but it was not";
146 150
147 } else { 151 } else {
148 config->proxy_rules().bypass_rules.AddRuleFromString( 152 config->proxy_rules().bypass_rules.AddRuleFromString(
149 base::SysCFStringRefToUTF8(bypass_item_ref)); 153 base::SysCFStringRefToUTF8(bypass_item_ref));
150 } 154 }
151 } 155 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // Keep track of the last value we have seen. 268 // Keep track of the last value we have seen.
265 has_fetched_config_ = true; 269 has_fetched_config_ = true;
266 last_config_fetched_ = new_config; 270 last_config_fetched_ = new_config;
267 271
268 // Notify all the observers. 272 // Notify all the observers.
269 FOR_EACH_OBSERVER(Observer, observers_, 273 FOR_EACH_OBSERVER(Observer, observers_,
270 OnProxyConfigChanged(new_config, CONFIG_VALID)); 274 OnProxyConfigChanged(new_config, CONFIG_VALID));
271 } 275 }
272 276
273 } // namespace net 277 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/proxy/proxy_resolver_mac.cc » ('j') | net/proxy/proxy_resolver_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698