| 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/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/task.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 17 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 19 #include "chrome/browser/extensions/extension_info_map.h" |
| 18 #include "chrome/browser/extensions/extension_protocols.h" | 20 #include "chrome/browser/extensions/extension_protocols.h" |
| 19 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
| 20 #include "chrome/browser/media/media_internals.h" | 22 #include "chrome/browser/media/media_internals.h" |
| 21 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 23 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 22 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" | 24 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" |
| 23 #include "chrome/browser/net/chrome_net_log.h" | 25 #include "chrome/browser/net/chrome_net_log.h" |
| 24 #include "chrome/browser/net/chrome_network_delegate.h" | 26 #include "chrome/browser/net/chrome_network_delegate.h" |
| 25 #include "chrome/browser/net/pref_proxy_config_service.h" | 27 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 26 #include "chrome/browser/net/proxy_service_factory.h" | 28 #include "chrome/browser/net/proxy_service_factory.h" |
| 27 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 29 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/prerender/prerender_manager.h" | 31 #include "chrome/browser/prerender/prerender_manager.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 33 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
| 32 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
| 33 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 38 #include "content/browser/appcache/chrome_appcache_service.h" |
| 36 #include "content/browser/browser_thread.h" | 39 #include "content/browser/browser_thread.h" |
| 40 #include "content/browser/chrome_blob_storage_context.h" |
| 37 #include "content/browser/host_zoom_map.h" | 41 #include "content/browser/host_zoom_map.h" |
| 38 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 42 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 39 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 43 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 40 #include "content/browser/resource_context.h" | 44 #include "content/browser/resource_context.h" |
| 41 #include "content/common/notification_service.h" | 45 #include "content/common/notification_service.h" |
| 42 #include "net/http/http_transaction_factory.h" | 46 #include "net/http/http_transaction_factory.h" |
| 43 #include "net/http/http_util.h" | 47 #include "net/http/http_util.h" |
| 44 #include "net/proxy/proxy_config_service_fixed.h" | 48 #include "net/proxy/proxy_config_service_fixed.h" |
| 45 #include "net/proxy/proxy_script_fetcher_impl.h" | 49 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 46 #include "net/proxy/proxy_service.h" | 50 #include "net/proxy/proxy_service.h" |
| 47 #include "net/url_request/url_request.h" | 51 #include "net/url_request/url_request.h" |
| 48 #include "webkit/blob/blob_data.h" | 52 #include "webkit/blob/blob_data.h" |
| 49 #include "webkit/blob/blob_url_request_job_factory.h" | 53 #include "webkit/blob/blob_url_request_job_factory.h" |
| 54 #include "webkit/fileapi/file_system_context.h" |
| 50 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 55 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
| 51 #include "webkit/database/database_tracker.h" | 56 #include "webkit/database/database_tracker.h" |
| 52 #include "webkit/quota/quota_manager.h" | 57 #include "webkit/quota/quota_manager.h" |
| 53 | 58 |
| 54 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
| 55 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 60 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
| 56 #endif // defined(OS_CHROMEOS) | 61 #endif // defined(OS_CHROMEOS) |
| 57 | 62 |
| 58 namespace { | 63 namespace { |
| 59 | 64 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 profile_id(Profile::kInvalidProfileId) {} | 301 profile_id(Profile::kInvalidProfileId) {} |
| 297 ProfileIOData::ProfileParams::~ProfileParams() {} | 302 ProfileIOData::ProfileParams::~ProfileParams() {} |
| 298 | 303 |
| 299 ProfileIOData::ProfileIOData(bool is_incognito) | 304 ProfileIOData::ProfileIOData(bool is_incognito) |
| 300 : initialized_(false), | 305 : initialized_(false), |
| 301 ALLOW_THIS_IN_INITIALIZER_LIST(resource_context_(this)) { | 306 ALLOW_THIS_IN_INITIALIZER_LIST(resource_context_(this)) { |
| 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 303 } | 308 } |
| 304 | 309 |
| 305 ProfileIOData::~ProfileIOData() { | 310 ProfileIOData::~ProfileIOData() { |
| 306 // If we have never initialized ProfileIOData, then Handle may hold the only | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 307 // reference to it. The important thing is to make sure it hasn't been | |
| 308 // initialized yet, because the lazily initialized variables are supposed to | |
| 309 // live on the IO thread. | |
| 310 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) | |
| 311 DCHECK(!initialized_); | |
| 312 else | |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 314 } | 312 } |
| 315 | 313 |
| 316 // static | 314 // static |
| 317 bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { | 315 bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { |
| 318 DCHECK_EQ(scheme, StringToLowerASCII(scheme)); | 316 DCHECK_EQ(scheme, StringToLowerASCII(scheme)); |
| 319 static const char* const kProtocolList[] = { | 317 static const char* const kProtocolList[] = { |
| 320 chrome::kExtensionScheme, | 318 chrome::kExtensionScheme, |
| 321 chrome::kChromeUIScheme, | 319 chrome::kChromeUIScheme, |
| 322 chrome::kChromeDevToolsScheme, | 320 chrome::kChromeDevToolsScheme, |
| 323 #if defined(OS_CHROMEOS) | 321 #if defined(OS_CHROMEOS) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 335 | 333 |
| 336 bool ProfileIOData::IsHandledURL(const GURL& url) { | 334 bool ProfileIOData::IsHandledURL(const GURL& url) { |
| 337 if (!url.is_valid()) { | 335 if (!url.is_valid()) { |
| 338 // We handle error cases. | 336 // We handle error cases. |
| 339 return true; | 337 return true; |
| 340 } | 338 } |
| 341 | 339 |
| 342 return IsHandledProtocol(url.scheme()); | 340 return IsHandledProtocol(url.scheme()); |
| 343 } | 341 } |
| 344 | 342 |
| 343 const content::ResourceContext& ProfileIOData::GetResourceContext() const { |
| 344 return resource_context_; |
| 345 } |
| 346 |
| 347 ChromeURLDataManagerBackend* |
| 348 ProfileIOData::GetChromeURLDataManagerBackend() const { |
| 349 LazyInitialize(); |
| 350 return chrome_url_data_manager_backend_.get(); |
| 351 } |
| 352 |
| 345 scoped_refptr<ChromeURLRequestContext> | 353 scoped_refptr<ChromeURLRequestContext> |
| 346 ProfileIOData::GetMainRequestContext() const { | 354 ProfileIOData::GetMainRequestContext() const { |
| 347 LazyInitialize(); | 355 LazyInitialize(); |
| 348 scoped_refptr<RequestContext> context = main_request_context_; | 356 scoped_refptr<RequestContext> context = main_request_context_; |
| 349 context->set_profile_io_data(const_cast<ProfileIOData*>(this)); | 357 context->set_profile_io_data(const_cast<ProfileIOData*>(this)); |
| 350 main_request_context_ = NULL; | 358 main_request_context_ = NULL; |
| 351 return context; | 359 return context; |
| 352 } | 360 } |
| 353 | 361 |
| 354 scoped_refptr<ChromeURLRequestContext> | 362 scoped_refptr<ChromeURLRequestContext> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 382 scoped_refptr<RequestContext> request_context = | 390 scoped_refptr<RequestContext> request_context = |
| 383 AcquireIsolatedAppRequestContext(main_context, app_id); | 391 AcquireIsolatedAppRequestContext(main_context, app_id); |
| 384 request_context->set_profile_io_data(const_cast<ProfileIOData*>(this)); | 392 request_context->set_profile_io_data(const_cast<ProfileIOData*>(this)); |
| 385 app_request_context_map_[app_id] = request_context; | 393 app_request_context_map_[app_id] = request_context; |
| 386 context = request_context; | 394 context = request_context; |
| 387 } | 395 } |
| 388 DCHECK(context); | 396 DCHECK(context); |
| 389 return context; | 397 return context; |
| 390 } | 398 } |
| 391 | 399 |
| 392 const content::ResourceContext& ProfileIOData::GetResourceContext() const { | |
| 393 return resource_context_; | |
| 394 } | |
| 395 | |
| 396 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { | 400 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { |
| 397 return extension_info_map_; | 401 return extension_info_map_; |
| 398 } | 402 } |
| 399 | 403 |
| 400 HostContentSettingsMap* ProfileIOData::GetHostContentSettingsMap() const { | 404 HostContentSettingsMap* ProfileIOData::GetHostContentSettingsMap() const { |
| 401 return host_content_settings_map_; | 405 return host_content_settings_map_; |
| 402 } | 406 } |
| 403 | 407 |
| 404 DesktopNotificationService* ProfileIOData::GetNotificationService() const { | 408 DesktopNotificationService* ProfileIOData::GetNotificationService() const { |
| 405 return notification_service_; | 409 return notification_service_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 466 } |
| 463 bool set_protocol = job_factory_->SetProtocolHandler( | 467 bool set_protocol = job_factory_->SetProtocolHandler( |
| 464 chrome::kExtensionScheme, | 468 chrome::kExtensionScheme, |
| 465 CreateExtensionProtocolHandler(profile_params_->is_incognito, | 469 CreateExtensionProtocolHandler(profile_params_->is_incognito, |
| 466 profile_params_->extension_info_map)); | 470 profile_params_->extension_info_map)); |
| 467 DCHECK(set_protocol); | 471 DCHECK(set_protocol); |
| 468 set_protocol = job_factory_->SetProtocolHandler( | 472 set_protocol = job_factory_->SetProtocolHandler( |
| 469 chrome::kChromeUIScheme, | 473 chrome::kChromeUIScheme, |
| 470 ChromeURLDataManagerBackend::CreateProtocolHandler( | 474 ChromeURLDataManagerBackend::CreateProtocolHandler( |
| 471 chrome_url_data_manager_backend_.get(), | 475 chrome_url_data_manager_backend_.get(), |
| 472 profile_params_->appcache_service)); | 476 profile_params_->appcache_service, |
| 477 profile_params_->blob_storage_context->controller())); |
| 473 DCHECK(set_protocol); | 478 DCHECK(set_protocol); |
| 474 set_protocol = job_factory_->SetProtocolHandler( | 479 set_protocol = job_factory_->SetProtocolHandler( |
| 475 chrome::kChromeDevToolsScheme, | 480 chrome::kChromeDevToolsScheme, |
| 476 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend_.get())); | 481 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend_.get())); |
| 477 DCHECK(set_protocol); | 482 DCHECK(set_protocol); |
| 478 set_protocol = job_factory_->SetProtocolHandler( | 483 set_protocol = job_factory_->SetProtocolHandler( |
| 479 chrome::kBlobScheme, | 484 chrome::kBlobScheme, |
| 480 new ChromeBlobProtocolHandler( | 485 new ChromeBlobProtocolHandler( |
| 481 profile_params_->blob_storage_context->controller(), | 486 profile_params_->blob_storage_context->controller(), |
| 482 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 487 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 533 |
| 529 void ProfileIOData::ApplyProfileParamsToContext( | 534 void ProfileIOData::ApplyProfileParamsToContext( |
| 530 ChromeURLRequestContext* context) const { | 535 ChromeURLRequestContext* context) const { |
| 531 context->set_is_incognito(profile_params_->is_incognito); | 536 context->set_is_incognito(profile_params_->is_incognito); |
| 532 context->set_accept_language(profile_params_->accept_language); | 537 context->set_accept_language(profile_params_->accept_language); |
| 533 context->set_accept_charset(profile_params_->accept_charset); | 538 context->set_accept_charset(profile_params_->accept_charset); |
| 534 context->set_referrer_charset(profile_params_->referrer_charset); | 539 context->set_referrer_charset(profile_params_->referrer_charset); |
| 535 context->set_transport_security_state( | 540 context->set_transport_security_state( |
| 536 profile_params_->transport_security_state); | 541 profile_params_->transport_security_state); |
| 537 context->set_ssl_config_service(profile_params_->ssl_config_service); | 542 context->set_ssl_config_service(profile_params_->ssl_config_service); |
| 538 context->set_appcache_service(profile_params_->appcache_service); | |
| 539 context->set_blob_storage_context(profile_params_->blob_storage_context); | |
| 540 context->set_file_system_context(profile_params_->file_system_context); | |
| 541 context->set_extension_info_map(profile_params_->extension_info_map); | |
| 542 } | 543 } |
| 543 | 544 |
| 544 void ProfileIOData::ShutdownOnUIThread() { | 545 void ProfileIOData::ShutdownOnUIThread() { |
| 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 546 enable_referrers_.Destroy(); | 547 enable_referrers_.Destroy(); |
| 547 clear_local_state_on_exit_.Destroy(); | 548 clear_local_state_on_exit_.Destroy(); |
| 549 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 550 new ReleaseTask<ProfileIOData>(this)); |
| 548 } | 551 } |
| OLD | NEW |