| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/storage_partition_impl_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "content/browser/appcache/chrome_appcache_service.h" | 16 #include "content/browser/appcache/chrome_appcache_service.h" |
| 17 #include "content/browser/fileapi/browser_file_system_helper.h" | 17 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 19 #include "content/browser/histogram_internals_request_job.h" | |
| 20 #include "content/browser/loader/resource_request_info_impl.h" | 19 #include "content/browser/loader/resource_request_info_impl.h" |
| 21 #include "content/browser/net/view_blob_internals_job_factory.h" | |
| 22 #include "content/browser/net/view_http_cache_job_factory.h" | |
| 23 #include "content/browser/resource_context_impl.h" | 20 #include "content/browser/resource_context_impl.h" |
| 24 #include "content/browser/storage_partition_impl.h" | 21 #include "content/browser/storage_partition_impl.h" |
| 25 #include "content/browser/tcmalloc_internals_request_job.h" | |
| 26 #include "content/browser/webui/url_data_manager_backend.h" | 22 #include "content/browser/webui/url_data_manager_backend.h" |
| 27 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 28 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/content_browser_client.h" | 25 #include "content/public/browser/content_browser_client.h" |
| 30 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 31 #include "content/public/common/content_constants.h" | 27 #include "content/public/common/content_constants.h" |
| 32 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 33 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
| 34 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 35 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
| 36 #include "webkit/appcache/view_appcache_internals_job.h" | |
| 37 #include "webkit/blob/blob_data.h" | 32 #include "webkit/blob/blob_data.h" |
| 38 #include "webkit/blob/blob_url_request_job_factory.h" | 33 #include "webkit/blob/blob_url_request_job_factory.h" |
| 39 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 34 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
| 40 | 35 |
| 41 using appcache::AppCacheService; | 36 using appcache::AppCacheService; |
| 42 using fileapi::FileSystemContext; | 37 using fileapi::FileSystemContext; |
| 43 using webkit_blob::BlobStorageController; | 38 using webkit_blob::BlobStorageController; |
| 44 | 39 |
| 45 namespace content { | 40 namespace content { |
| 46 | 41 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 95 |
| 101 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 96 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 102 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 97 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 103 | 98 |
| 104 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | 99 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> |
| 105 webkit_blob_protocol_handler_impl_; | 100 webkit_blob_protocol_handler_impl_; |
| 106 | 101 |
| 107 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 102 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
| 108 }; | 103 }; |
| 109 | 104 |
| 110 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | |
| 111 // handler because we want to reuse the chrome://scheme (everyone is familiar | |
| 112 // with it, and no need to expose the content/chrome separation through our UI). | |
| 113 class DeveloperProtocolHandler | |
| 114 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 115 public: | |
| 116 DeveloperProtocolHandler( | |
| 117 AppCacheService* appcache_service, | |
| 118 ChromeBlobStorageContext* blob_storage_context) | |
| 119 : appcache_service_(appcache_service), | |
| 120 blob_storage_context_(blob_storage_context) {} | |
| 121 virtual ~DeveloperProtocolHandler() {} | |
| 122 | |
| 123 virtual net::URLRequestJob* MaybeCreateJob( | |
| 124 net::URLRequest* request, | |
| 125 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 126 // Check for chrome://view-http-cache/*, which uses its own job type. | |
| 127 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | |
| 128 return ViewHttpCacheJobFactory::CreateJobForRequest(request, | |
| 129 network_delegate); | |
| 130 | |
| 131 // Next check for chrome://appcache-internals/, which uses its own job type. | |
| 132 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | |
| 133 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { | |
| 134 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | |
| 135 request, network_delegate, appcache_service_); | |
| 136 } | |
| 137 | |
| 138 // Next check for chrome://blob-internals/, which uses its own job type. | |
| 139 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { | |
| 140 return ViewBlobInternalsJobFactory::CreateJobForRequest( | |
| 141 request, network_delegate, blob_storage_context_->controller()); | |
| 142 } | |
| 143 | |
| 144 #if defined(USE_TCMALLOC) | |
| 145 // Next check for chrome://tcmalloc/, which uses its own job type. | |
| 146 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | |
| 147 request->url().host() == chrome::kChromeUITcmallocHost) { | |
| 148 return new TcmallocInternalsRequestJob(request, network_delegate); | |
| 149 } | |
| 150 #endif | |
| 151 | |
| 152 // Next check for chrome://histograms/, which uses its own job type. | |
| 153 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | |
| 154 request->url().host() == chrome::kChromeUIHistogramHost) { | |
| 155 return new HistogramInternalsRequestJob(request, network_delegate); | |
| 156 } | |
| 157 | |
| 158 return NULL; | |
| 159 } | |
| 160 | |
| 161 private: | |
| 162 AppCacheService* appcache_service_; | |
| 163 ChromeBlobStorageContext* blob_storage_context_; | |
| 164 }; | |
| 165 | |
| 166 // These constants are used to create the directory structure under the profile | 105 // These constants are used to create the directory structure under the profile |
| 167 // where renderers with a non-default storage partition keep their persistent | 106 // where renderers with a non-default storage partition keep their persistent |
| 168 // state. This will contain a set of directories that partially mirror the | 107 // state. This will contain a set of directories that partially mirror the |
| 169 // directory structure of BrowserContext::GetPath(). | 108 // directory structure of BrowserContext::GetPath(). |
| 170 // | 109 // |
| 171 // The kStoragePartitionDirname contains an extensions directory which is | 110 // The kStoragePartitionDirname contains an extensions directory which is |
| 172 // further partitioned by extension id, followed by another level of directories | 111 // further partitioned by extension id, followed by another level of directories |
| 173 // for the "default" extension storage partition and one directory for each | 112 // for the "default" extension storage partition and one directory for each |
| 174 // persistent partition used by a webview tag. Example: | 113 // persistent partition used by a webview tag. Example: |
| 175 // | 114 // |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 base::FilePath partition_path = | 379 base::FilePath partition_path = |
| 441 browser_context_->GetPath().Append( | 380 browser_context_->GetPath().Append( |
| 442 GetStoragePartitionPath(partition_domain, partition_name)); | 381 GetStoragePartitionPath(partition_domain, partition_name)); |
| 443 StoragePartitionImpl* partition = | 382 StoragePartitionImpl* partition = |
| 444 StoragePartitionImpl::Create(browser_context_, in_memory, | 383 StoragePartitionImpl::Create(browser_context_, in_memory, |
| 445 partition_path); | 384 partition_path); |
| 446 partitions_[partition_config] = partition; | 385 partitions_[partition_config] = partition; |
| 447 | 386 |
| 448 ChromeBlobStorageContext* blob_storage_context = | 387 ChromeBlobStorageContext* blob_storage_context = |
| 449 ChromeBlobStorageContext::GetFor(browser_context_); | 388 ChromeBlobStorageContext::GetFor(browser_context_); |
| 450 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( | 389 ProtocolHandlerMap protocol_handlers; |
| 451 new BlobProtocolHandler(blob_storage_context, | 390 protocol_handlers[chrome::kBlobScheme] = |
| 452 partition->GetFileSystemContext())); | 391 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 453 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 392 new BlobProtocolHandler(blob_storage_context, |
| 454 file_system_protocol_handler( | 393 partition->GetFileSystemContext())); |
| 455 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | 394 protocol_handlers[chrome::kFileSystemScheme] = |
| 456 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 395 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 457 developer_protocol_handler( | 396 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); |
| 458 new DeveloperProtocolHandler(partition->GetAppCacheService(), | 397 protocol_handlers[chrome::kChromeUIScheme] = |
| 459 blob_storage_context)); | 398 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 460 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 461 chrome_protocol_handler( | |
| 462 URLDataManagerBackend::CreateProtocolHandler( | 399 URLDataManagerBackend::CreateProtocolHandler( |
| 463 browser_context_->GetResourceContext(), | 400 browser_context_->GetResourceContext(), |
| 464 browser_context_->IsOffTheRecord())); | 401 browser_context_->IsOffTheRecord(), |
| 465 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 402 partition->GetAppCacheService(), |
| 466 chrome_devtools_protocol_handler( | 403 blob_storage_context)); |
| 404 std::vector<std::string> additional_webui_schemes = |
| 405 GetContentClient()->browser()->GetAdditionalWebUISchemes(); |
| 406 for (std::vector<std::string>::const_iterator it = |
| 407 additional_webui_schemes.begin(); |
| 408 it != additional_webui_schemes.end(); |
| 409 ++it) { |
| 410 protocol_handlers[*it] = |
| 411 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 412 URLDataManagerBackend::CreateProtocolHandler( |
| 413 browser_context_->GetResourceContext(), |
| 414 browser_context_->IsOffTheRecord(), |
| 415 partition->GetAppCacheService(), |
| 416 blob_storage_context)); |
| 417 } |
| 418 protocol_handlers[chrome::kChromeDevToolsScheme] = |
| 419 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 467 CreateDevToolsProtocolHandler(browser_context_->GetResourceContext(), | 420 CreateDevToolsProtocolHandler(browser_context_->GetResourceContext(), |
| 468 browser_context_->IsOffTheRecord())); | 421 browser_context_->IsOffTheRecord())); |
| 469 | 422 |
| 470 // These calls must happen after StoragePartitionImpl::Create(). | 423 // These calls must happen after StoragePartitionImpl::Create(). |
| 471 if (partition_domain.empty()) { | 424 if (partition_domain.empty()) { |
| 472 partition->SetURLRequestContext( | 425 partition->SetURLRequestContext( |
| 473 GetContentClient()->browser()->CreateRequestContext(browser_context_, | 426 GetContentClient()->browser()->CreateRequestContext( |
| 474 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), | 427 browser_context_, |
| 475 developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), | 428 &protocol_handlers)); |
| 476 chrome_devtools_protocol_handler.Pass())); | |
| 477 } else { | 429 } else { |
| 478 partition->SetURLRequestContext( | 430 partition->SetURLRequestContext( |
| 479 GetContentClient()->browser()->CreateRequestContextForStoragePartition( | 431 GetContentClient()->browser()->CreateRequestContextForStoragePartition( |
| 480 browser_context_, partition->GetPath(), in_memory, | 432 browser_context_, partition->GetPath(), in_memory, |
| 481 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), | 433 &protocol_handlers)); |
| 482 developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), | |
| 483 chrome_devtools_protocol_handler.Pass())); | |
| 484 } | 434 } |
| 485 partition->SetMediaURLRequestContext( | 435 partition->SetMediaURLRequestContext( |
| 486 partition_domain.empty() ? | 436 partition_domain.empty() ? |
| 487 browser_context_->GetMediaRequestContext() : | 437 browser_context_->GetMediaRequestContext() : |
| 488 browser_context_->GetMediaRequestContextForStoragePartition( | 438 browser_context_->GetMediaRequestContextForStoragePartition( |
| 489 partition->GetPath(), in_memory)); | 439 partition->GetPath(), in_memory)); |
| 490 | 440 |
| 491 PostCreateInitialization(partition, in_memory); | 441 PostCreateInitialization(partition, in_memory); |
| 492 | 442 |
| 493 return partition; | 443 return partition; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 552 |
| 603 // We do not call InitializeURLRequestContext() for media contexts because, | 553 // We do not call InitializeURLRequestContext() for media contexts because, |
| 604 // other than the HTTP cache, the media contexts share the same backing | 554 // other than the HTTP cache, the media contexts share the same backing |
| 605 // objects as their associated "normal" request context. Thus, the previous | 555 // objects as their associated "normal" request context. Thus, the previous |
| 606 // call serves to initialize the media request context for this storage | 556 // call serves to initialize the media request context for this storage |
| 607 // partition as well. | 557 // partition as well. |
| 608 } | 558 } |
| 609 } | 559 } |
| 610 | 560 |
| 611 } // namespace content | 561 } // namespace content |
| OLD | NEW |