| OLD | NEW |
| 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 "chrome/browser/profiles/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 15 #include "chrome/browser/extensions/user_script_master.h" | 15 #include "chrome/browser/extensions/user_script_master.h" |
| 16 #include "chrome/browser/io_thread.h" | 16 #include "chrome/browser/io_thread.h" |
| 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 17 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 18 #include "chrome/browser/net/pref_proxy_config_service.h" | 18 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 19 #include "chrome/browser/net/proxy_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 24 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
| 25 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
| 26 #include "net/proxy/proxy_config_service_fixed.h" | 28 #include "net/proxy/proxy_config_service_fixed.h" |
| 27 #include "net/proxy/proxy_script_fetcher_impl.h" | 29 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 28 #include "net/proxy/proxy_service.h" | 30 #include "net/proxy/proxy_service.h" |
| 29 | 31 |
| 30 #if defined(OS_CHROMEOS) | |
| 31 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 32 #include "chrome/browser/chromeos/cros/libcros_service_library.h" | |
| 33 #include "chrome/browser/chromeos/proxy_config_service.h" | |
| 34 #endif // defined(OS_CHROMEOS) | |
| 35 | |
| 36 namespace { | 32 namespace { |
| 37 | 33 |
| 38 // ---------------------------------------------------------------------------- | 34 // ---------------------------------------------------------------------------- |
| 39 // CookieMonster::Delegate implementation | 35 // CookieMonster::Delegate implementation |
| 40 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
| 41 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | 37 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { |
| 42 public: | 38 public: |
| 43 explicit ChromeCookieMonsterDelegate(Profile* profile) { | 39 explicit ChromeCookieMonsterDelegate(Profile* profile) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 45 profile_getter_ = new ProfileGetter(profile); | 41 profile_getter_ = new ProfileGetter(profile); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 params->ssl_config_service = profile->GetSSLConfigService(); | 162 params->ssl_config_service = profile->GetSSLConfigService(); |
| 167 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); | 163 params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile); |
| 168 params->database_tracker = profile->GetDatabaseTracker(); | 164 params->database_tracker = profile->GetDatabaseTracker(); |
| 169 params->appcache_service = profile->GetAppCacheService(); | 165 params->appcache_service = profile->GetAppCacheService(); |
| 170 params->blob_storage_context = profile->GetBlobStorageContext(); | 166 params->blob_storage_context = profile->GetBlobStorageContext(); |
| 171 params->file_system_context = profile->GetFileSystemContext(); | 167 params->file_system_context = profile->GetFileSystemContext(); |
| 172 params->extension_info_map = profile->GetExtensionInfoMap(); | 168 params->extension_info_map = profile->GetExtensionInfoMap(); |
| 173 params->prerender_manager = profile->GetPrerenderManager(); | 169 params->prerender_manager = profile->GetPrerenderManager(); |
| 174 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); | 170 params->protocol_handler_registry = profile->GetProtocolHandlerRegistry(); |
| 175 | 171 |
| 176 params->proxy_config_service.reset(CreateProxyConfigService(profile)); | 172 params->proxy_config_service.reset( |
| 173 ProxyServiceFactory::CreateProxyConfigService( |
| 174 profile->GetProxyConfigTracker())); |
| 177 params->profile_id = profile->GetRuntimeId(); | 175 params->profile_id = profile->GetRuntimeId(); |
| 178 } | 176 } |
| 179 | 177 |
| 180 ProfileIOData::RequestContext::RequestContext() {} | 178 ProfileIOData::RequestContext::RequestContext() {} |
| 181 ProfileIOData::RequestContext::~RequestContext() {} | 179 ProfileIOData::RequestContext::~RequestContext() {} |
| 182 | 180 |
| 183 ProfileIOData::ProfileParams::ProfileParams() | 181 ProfileIOData::ProfileParams::ProfileParams() |
| 184 : is_off_the_record(false), | 182 : is_off_the_record(false), |
| 185 clear_local_state_on_exit(false) {} | 183 clear_local_state_on_exit(false) {} |
| 186 ProfileIOData::ProfileParams::~ProfileParams() {} | 184 ProfileIOData::ProfileParams::~ProfileParams() {} |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 context->set_transport_security_state( | 249 context->set_transport_security_state( |
| 252 profile_params.transport_security_state); | 250 profile_params.transport_security_state); |
| 253 context->set_ssl_config_service(profile_params.ssl_config_service); | 251 context->set_ssl_config_service(profile_params.ssl_config_service); |
| 254 context->set_database_tracker(profile_params.database_tracker); | 252 context->set_database_tracker(profile_params.database_tracker); |
| 255 context->set_appcache_service(profile_params.appcache_service); | 253 context->set_appcache_service(profile_params.appcache_service); |
| 256 context->set_blob_storage_context(profile_params.blob_storage_context); | 254 context->set_blob_storage_context(profile_params.blob_storage_context); |
| 257 context->set_file_system_context(profile_params.file_system_context); | 255 context->set_file_system_context(profile_params.file_system_context); |
| 258 context->set_extension_info_map(profile_params.extension_info_map); | 256 context->set_extension_info_map(profile_params.extension_info_map); |
| 259 context->set_prerender_manager(profile_params.prerender_manager); | 257 context->set_prerender_manager(profile_params.prerender_manager); |
| 260 } | 258 } |
| 261 | |
| 262 // static | |
| 263 net::ProxyConfigService* ProfileIOData::CreateProxyConfigService( | |
| 264 Profile* profile) { | |
| 265 // The linux gconf-based proxy settings getter relies on being initialized | |
| 266 // from the UI thread. | |
| 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 268 | |
| 269 // Create a baseline service that provides proxy configuration in case nothing | |
| 270 // is configured through prefs (Note: prefs include command line and | |
| 271 // configuration policy). | |
| 272 net::ProxyConfigService* base_service = NULL; | |
| 273 | |
| 274 // TODO(port): the IO and FILE message loops are only used by Linux. Can | |
| 275 // that code be moved to chrome/browser instead of being in net, so that it | |
| 276 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354. | |
| 277 #if defined(OS_CHROMEOS) | |
| 278 base_service = new chromeos::ProxyConfigService( | |
| 279 profile->GetChromeOSProxyConfigServiceImpl()); | |
| 280 #else | |
| 281 base_service = net::ProxyService::CreateSystemProxyConfigService( | |
| 282 g_browser_process->io_thread()->message_loop(), | |
| 283 g_browser_process->file_thread()->message_loop()); | |
| 284 #endif // defined(OS_CHROMEOS) | |
| 285 | |
| 286 return new PrefProxyConfigService(profile->GetProxyConfigTracker(), | |
| 287 base_service); | |
| 288 } | |
| 289 | |
| 290 // static | |
| 291 net::ProxyService* ProfileIOData::CreateProxyService( | |
| 292 net::NetLog* net_log, | |
| 293 net::URLRequestContext* context, | |
| 294 net::ProxyConfigService* proxy_config_service, | |
| 295 const CommandLine& command_line) { | |
| 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 297 | |
| 298 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | |
| 299 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | |
| 300 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | |
| 301 // to understand why we have this limitation. | |
| 302 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | |
| 303 use_v8 = false; // Fallback to non-v8 implementation. | |
| 304 } | |
| 305 | |
| 306 size_t num_pac_threads = 0u; // Use default number of threads. | |
| 307 | |
| 308 // Check the command line for an override on the number of proxy resolver | |
| 309 // threads to use. | |
| 310 if (command_line.HasSwitch(switches::kNumPacThreads)) { | |
| 311 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); | |
| 312 | |
| 313 // Parse the switch (it should be a positive integer formatted as decimal). | |
| 314 int n; | |
| 315 if (base::StringToInt(s, &n) && n > 0) { | |
| 316 num_pac_threads = static_cast<size_t>(n); | |
| 317 } else { | |
| 318 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 net::ProxyService* proxy_service; | |
| 323 if (use_v8) { | |
| 324 proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( | |
| 325 proxy_config_service, | |
| 326 num_pac_threads, | |
| 327 new net::ProxyScriptFetcherImpl(context), | |
| 328 context->host_resolver(), | |
| 329 net_log); | |
| 330 } else { | |
| 331 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( | |
| 332 proxy_config_service, | |
| 333 num_pac_threads, | |
| 334 net_log); | |
| 335 } | |
| 336 | |
| 337 #if defined(OS_CHROMEOS) | |
| 338 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
| 339 chromeos::CrosLibrary::Get()->GetLibCrosServiceLibrary()-> | |
| 340 RegisterNetworkProxyHandler(proxy_service); | |
| 341 } | |
| 342 #endif // defined(OS_CHROMEOS) | |
| 343 | |
| 344 return proxy_service; | |
| 345 } | |
| OLD | NEW |