diff options
author | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 10:37:27 +0000 |
---|---|---|
committer | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 10:37:27 +0000 |
commit | a9944f08e4c9730993d012496a688039cf48936e (patch) | |
tree | 595999cb4b26d8eb72d7c4d8033e7d71b7cffb38 /net/proxy/proxy_server_mac.cc | |
parent | c0ce9d8162a70abb545e3ca7376003a492b08490 (diff) | |
download | chromium_src-a9944f08e4c9730993d012496a688039cf48936e.zip chromium_src-a9944f08e4c9730993d012496a688039cf48936e.tar.gz chromium_src-a9944f08e4c9730993d012496a688039cf48936e.tar.bz2 |
Separate ProxyResolverMac and ProxyConfigServiceMac into their own files and extract common utility functions into other files.
TEST=trybot and MacUtilTest in base_unittests
BUG=27310
Review URL: http://codereview.chromium.org/463028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34243 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_server_mac.cc')
-rw-r--r-- | net/proxy/proxy_server_mac.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/net/proxy/proxy_server_mac.cc b/net/proxy/proxy_server_mac.cc new file mode 100644 index 0000000..44c21cd --- /dev/null +++ b/net/proxy/proxy_server_mac.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/proxy/proxy_server.h" + +#include <CoreFoundation/CoreFoundation.h> + +#include <string> + +#include "base/logging.h" +#include "base/mac_util.h" +#include "base/sys_string_conversions.h" + +namespace net { + +// static +ProxyServer ProxyServer::FromDictionary(Scheme scheme, + CFDictionaryRef dict, + CFStringRef host_key, + CFStringRef port_key) { + if (scheme == SCHEME_INVALID || scheme == SCHEME_DIRECT) { + // No hostname port to extract; we are done. + return ProxyServer(scheme, std::string(), -1); + } + + CFStringRef host_ref = + (CFStringRef)mac_util::GetValueFromDictionary(dict, host_key, + CFStringGetTypeID()); + if (!host_ref) { + LOG(WARNING) << "Could not find expected key " + << base::SysCFStringRefToUTF8(host_key) + << " in the proxy dictionary"; + return ProxyServer(); // Invalid. + } + std::string host = base::SysCFStringRefToUTF8(host_ref); + + CFNumberRef port_ref = + (CFNumberRef)mac_util::GetValueFromDictionary(dict, port_key, + CFNumberGetTypeID()); + int port; + if (port_ref) { + CFNumberGetValue(port_ref, kCFNumberIntType, &port); + } else { + port = GetDefaultPortForScheme(scheme); + } + + return ProxyServer(scheme, host, port); +} + +} // namespace net |