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