Commit 685db360 authored by kushi.p@gmail.com's avatar kushi.p@gmail.com

Convert plain C-style casts to use CFCastStrict and GetValueFromDictionary template.

These updates keep CF casts between CFTypeRef and specific CoreFoundation types consistent across the project.

BUG=104200

Review URL: http://codereview.chromium.org/8528013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110173 0039d316-1c4b-4281-b951-d872f2087c98
parent 1cb44aac
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <SystemConfiguration/SystemConfiguration.h> #include <SystemConfiguration/SystemConfiguration.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -28,8 +29,8 @@ const int kPollIntervalSec = 5; ...@@ -28,8 +29,8 @@ const int kPollIntervalSec = 5;
bool GetBoolFromDictionary(CFDictionaryRef dict, bool GetBoolFromDictionary(CFDictionaryRef dict,
CFStringRef key, CFStringRef key,
bool default_value) { bool default_value) {
CFNumberRef number = (CFNumberRef)base::mac::GetValueFromDictionary( CFNumberRef number = base::mac::GetValueFromDictionary<CFNumberRef>(dict,
dict, key, CFNumberGetTypeID()); key);
if (!number) if (!number)
return default_value; return default_value;
...@@ -60,10 +61,8 @@ void GetCurrentProxyConfig(ProxyConfig* config) { ...@@ -60,10 +61,8 @@ void GetCurrentProxyConfig(ProxyConfig* config) {
if (GetBoolFromDictionary(config_dict.get(), if (GetBoolFromDictionary(config_dict.get(),
kSCPropNetProxiesProxyAutoConfigEnable, kSCPropNetProxiesProxyAutoConfigEnable,
false)) { false)) {
CFStringRef pac_url_ref = (CFStringRef)base::mac::GetValueFromDictionary( CFStringRef pac_url_ref = base::mac::GetValueFromDictionary<CFStringRef>(
config_dict.get(), config_dict.get(), kSCPropNetProxiesProxyAutoConfigURLString);
kSCPropNetProxiesProxyAutoConfigURLString,
CFStringGetTypeID());
if (pac_url_ref) if (pac_url_ref)
config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref)));
} }
...@@ -129,17 +128,14 @@ void GetCurrentProxyConfig(ProxyConfig* config) { ...@@ -129,17 +128,14 @@ void GetCurrentProxyConfig(ProxyConfig* config) {
// proxy bypass list // proxy bypass list
CFArrayRef bypass_array_ref = CFArrayRef bypass_array_ref = base::mac::GetValueFromDictionary<CFArrayRef>(
(CFArrayRef)base::mac::GetValueFromDictionary( config_dict.get(), kSCPropNetProxiesExceptionsList);
config_dict.get(),
kSCPropNetProxiesExceptionsList,
CFArrayGetTypeID());
if (bypass_array_ref) { if (bypass_array_ref) {
CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref);
for (CFIndex i = 0; i < bypass_array_count; ++i) { for (CFIndex i = 0; i < bypass_array_count; ++i) {
CFStringRef bypass_item_ref = CFStringRef bypass_item_ref = base::mac::CFCast<CFStringRef>(
(CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); CFArrayGetValueAtIndex(bypass_array_ref, i));
if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { if (!bypass_item_ref) {
LOG(WARNING) << "Expected value for item " << i LOG(WARNING) << "Expected value for item " << i
<< " in the kSCPropNetProxiesExceptionsList" << " in the kSCPropNetProxiesExceptionsList"
" to be a CFStringRef but it was not"; " to be a CFStringRef but it was not";
......
...@@ -130,8 +130,9 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url, ...@@ -130,8 +130,9 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url,
CFRelease(result); CFRelease(result);
return ERR_FAILED; return ERR_FAILED;
} }
DCHECK(CFGetTypeID(result) == CFArrayGetTypeID()); base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref(
base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref((CFArrayRef)result); base::mac::CFCastStrict<CFArrayRef>(result));
DCHECK(proxy_array_ref != NULL);
// This string will be an ordered list of <proxy-uri> entries, separated by // This string will be an ordered list of <proxy-uri> entries, separated by
// semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects. // semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects.
...@@ -141,9 +142,9 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url, ...@@ -141,9 +142,9 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url,
CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get()); CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get());
for (CFIndex i = 0; i < proxy_array_count; ++i) { for (CFIndex i = 0; i < proxy_array_count; ++i) {
CFDictionaryRef proxy_dictionary = CFDictionaryRef proxy_dictionary = base::mac::CFCastStrict<CFDictionaryRef>(
(CFDictionaryRef)CFArrayGetValueAtIndex(proxy_array_ref.get(), i); CFArrayGetValueAtIndex(proxy_array_ref.get(), i));
DCHECK(CFGetTypeID(proxy_dictionary) == CFDictionaryGetTypeID()); DCHECK(proxy_dictionary != NULL);
// The dictionary may have the following keys: // The dictionary may have the following keys:
// - kCFProxyTypeKey : The type of the proxy // - kCFProxyTypeKey : The type of the proxy
...@@ -159,10 +160,8 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url, ...@@ -159,10 +160,8 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url,
// - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another // - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another
// PAC file, I'm going home. // PAC file, I'm going home.
CFStringRef proxy_type = CFStringRef proxy_type = base::mac::GetValueFromDictionary<CFStringRef>(
(CFStringRef)base::mac::GetValueFromDictionary(proxy_dictionary, proxy_dictionary, kCFProxyTypeKey);
kCFProxyTypeKey,
CFStringGetTypeID());
ProxyServer proxy_server = ProxyServer::FromDictionary( ProxyServer proxy_server = ProxyServer::FromDictionary(
GetProxyServerScheme(proxy_type), GetProxyServerScheme(proxy_type),
proxy_dictionary, proxy_dictionary,
......
...@@ -25,8 +25,7 @@ ProxyServer ProxyServer::FromDictionary(Scheme scheme, ...@@ -25,8 +25,7 @@ ProxyServer ProxyServer::FromDictionary(Scheme scheme,
} }
CFStringRef host_ref = CFStringRef host_ref =
(CFStringRef)base::mac::GetValueFromDictionary(dict, host_key, base::mac::GetValueFromDictionary<CFStringRef>(dict, host_key);
CFStringGetTypeID());
if (!host_ref) { if (!host_ref) {
LOG(WARNING) << "Could not find expected key " LOG(WARNING) << "Could not find expected key "
<< base::SysCFStringRefToUTF8(host_key) << base::SysCFStringRefToUTF8(host_key)
...@@ -36,8 +35,7 @@ ProxyServer ProxyServer::FromDictionary(Scheme scheme, ...@@ -36,8 +35,7 @@ ProxyServer ProxyServer::FromDictionary(Scheme scheme,
std::string host = base::SysCFStringRefToUTF8(host_ref); std::string host = base::SysCFStringRefToUTF8(host_ref);
CFNumberRef port_ref = CFNumberRef port_ref =
(CFNumberRef)base::mac::GetValueFromDictionary(dict, port_key, base::mac::GetValueFromDictionary<CFNumberRef>(dict, port_key);
CFNumberGetTypeID());
int port; int port;
if (port_ref) { if (port_ref) {
CFNumberGetValue(port_ref, kCFNumberIntType, &port); CFNumberGetValue(port_ref, kCFNumberIntType, &port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment