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_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 38 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
39 | 39 |
40 using appcache::AppCacheService; | 40 using appcache::AppCacheService; |
41 using fileapi::FileSystemContext; | 41 using fileapi::FileSystemContext; |
42 using webkit_blob::BlobStorageController; | 42 using webkit_blob::BlobStorageController; |
43 | 43 |
44 namespace content { | 44 namespace content { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { | 48 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
49 public: | 49 public: |
50 BlobProtocolHandler( | 50 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, |
51 webkit_blob::BlobStorageController* blob_storage_controller, | 51 fileapi::FileSystemContext* file_system_context) |
52 fileapi::FileSystemContext* file_system_context, | 52 : blob_storage_context_(blob_storage_context), |
53 base::MessageLoopProxy* loop_proxy) | 53 file_system_context_(file_system_context) {} |
54 : webkit_blob::BlobProtocolHandler(blob_storage_controller, | |
55 file_system_context, | |
56 loop_proxy) {} | |
57 | 54 |
58 virtual ~BlobProtocolHandler() {} | 55 virtual ~BlobProtocolHandler() {} |
59 | 56 |
57 virtual net::URLRequestJob* MaybeCreateJob( | |
58 net::URLRequest* request, | |
59 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
61 if (!webkit_blob_protocol_handler_impl_) { | |
62 webkit_blob_protocol_handler_impl_.reset( | |
63 new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), | |
64 file_system_context_)); | |
65 } | |
66 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, | |
67 network_delegate); | |
68 } | |
69 | |
60 private: | 70 private: |
61 virtual scoped_refptr<webkit_blob::BlobData> | 71 // An implementation of webkit_blob::BlobProtocolHandler that gets |
62 LookupBlobData(net::URLRequest* request) const { | 72 // the BlobData from ResourceRequestInfoImpl. |
63 const ResourceRequestInfoImpl* info = | 73 class WebKitBlobProtocolHandlerImpl |
64 ResourceRequestInfoImpl::ForRequest(request); | 74 : public webkit_blob::BlobProtocolHandler { |
65 if (!info) | 75 public: |
66 return NULL; | 76 WebKitBlobProtocolHandlerImpl( |
67 return info->requested_blob_data(); | 77 webkit_blob::BlobStorageController* blob_storage_controller, |
68 } | 78 fileapi::FileSystemContext* file_system_context) |
79 : webkit_blob::BlobProtocolHandler( | |
80 blob_storage_controller, file_system_context, | |
81 BrowserThread::GetMessageLoopProxyForThread( | |
82 BrowserThread::FILE)) {} | |
83 | |
84 virtual ~WebKitBlobProtocolHandlerImpl() {} | |
85 | |
86 private: | |
87 // webkit_blob::BlobProtocolHandler implementation. | |
88 virtual scoped_refptr<webkit_blob::BlobData> | |
89 LookupBlobData(net::URLRequest* request) const OVERRIDE { | |
90 const ResourceRequestInfoImpl* info = | |
91 ResourceRequestInfoImpl::ForRequest(request); | |
92 if (!info) | |
93 return NULL; | |
94 return info->requested_blob_data(); | |
95 } | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | |
98 }; | |
99 | |
100 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | |
101 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | |
102 | |
103 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | |
104 webkit_blob_protocol_handler_impl_; | |
69 | 105 |
70 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 106 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
71 }; | 107 }; |
72 | 108 |
73 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | 109 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol |
74 // handler because we want to reuse the chrome://scheme (everyone is familiar | 110 // handler because we want to reuse the chrome://scheme (everyone is familiar |
75 // with it, and no need to expose the content/chrome separation through our UI). | 111 // with it, and no need to expose the content/chrome separation through our UI). |
76 class DeveloperProtocolHandler | 112 class DeveloperProtocolHandler |
77 : public net::URLRequestJobFactory::Interceptor { | 113 : public net::URLRequestJobFactory::Interceptor { |
78 public: | 114 public: |
79 DeveloperProtocolHandler( | 115 DeveloperProtocolHandler( |
80 AppCacheService* appcache_service, | 116 AppCacheService* appcache_service, |
81 BlobStorageController* blob_storage_controller) | 117 ChromeBlobStorageContext* blob_storage_context) |
82 : appcache_service_(appcache_service), | 118 : appcache_service_(appcache_service), |
83 blob_storage_controller_(blob_storage_controller) {} | 119 blob_storage_context_(blob_storage_context) {} |
84 virtual ~DeveloperProtocolHandler() {} | 120 virtual ~DeveloperProtocolHandler() {} |
85 | 121 |
86 virtual net::URLRequestJob* MaybeIntercept( | 122 virtual net::URLRequestJob* MaybeIntercept( |
87 net::URLRequest* request, | 123 net::URLRequest* request, |
88 net::NetworkDelegate* network_delegate) const OVERRIDE { | 124 net::NetworkDelegate* network_delegate) const OVERRIDE { |
89 // Check for chrome://view-http-cache/*, which uses its own job type. | 125 // Check for chrome://view-http-cache/*, which uses its own job type. |
90 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 126 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
91 return ViewHttpCacheJobFactory::CreateJobForRequest(request, | 127 return ViewHttpCacheJobFactory::CreateJobForRequest(request, |
92 network_delegate); | 128 network_delegate); |
93 | 129 |
94 // Next check for chrome://appcache-internals/, which uses its own job type. | 130 // Next check for chrome://appcache-internals/, which uses its own job type. |
95 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 131 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
96 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { | 132 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { |
97 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | 133 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( |
98 request, network_delegate, appcache_service_); | 134 request, network_delegate, appcache_service_); |
99 } | 135 } |
100 | 136 |
101 // Next check for chrome://blob-internals/, which uses its own job type. | 137 // Next check for chrome://blob-internals/, which uses its own job type. |
102 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { | 138 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { |
103 return ViewBlobInternalsJobFactory::CreateJobForRequest( | 139 return ViewBlobInternalsJobFactory::CreateJobForRequest( |
104 request, network_delegate, blob_storage_controller_); | 140 request, network_delegate, blob_storage_context_->controller()); |
105 } | 141 } |
106 | 142 |
107 #if defined(USE_TCMALLOC) | 143 #if defined(USE_TCMALLOC) |
108 // Next check for chrome://tcmalloc/, which uses its own job type. | 144 // Next check for chrome://tcmalloc/, which uses its own job type. |
109 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 145 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
110 request->url().host() == chrome::kChromeUITcmallocHost) { | 146 request->url().host() == chrome::kChromeUITcmallocHost) { |
111 return new TcmallocInternalsRequestJob(request, network_delegate); | 147 return new TcmallocInternalsRequestJob(request, network_delegate); |
112 } | 148 } |
113 #endif | 149 #endif |
114 | 150 |
(...skipping 18 matching lines...) Expand all Loading... | |
133 net::NetworkDelegate* network_delegate) const OVERRIDE { | 169 net::NetworkDelegate* network_delegate) const OVERRIDE { |
134 return NULL; | 170 return NULL; |
135 } | 171 } |
136 | 172 |
137 virtual bool WillHandleProtocol(const std::string& protocol) const { | 173 virtual bool WillHandleProtocol(const std::string& protocol) const { |
138 return protocol == chrome::kChromeUIScheme; | 174 return protocol == chrome::kChromeUIScheme; |
139 } | 175 } |
140 | 176 |
141 private: | 177 private: |
142 AppCacheService* appcache_service_; | 178 AppCacheService* appcache_service_; |
143 BlobStorageController* blob_storage_controller_; | 179 ChromeBlobStorageContext* blob_storage_context_; |
144 }; | 180 }; |
145 | 181 |
146 void InitializeURLRequestContext( | |
147 net::URLRequestContextGetter* context_getter, | |
148 AppCacheService* appcache_service, | |
149 FileSystemContext* file_system_context, | |
150 ChromeBlobStorageContext* blob_storage_context) { | |
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
152 if (!context_getter) | |
153 return; // tests. | |
154 | |
155 // This code only modifies the URLRequestJobFactory on the context | |
156 // to handle blob: URLs, filesystem: URLs, and to let AppCache intercept | |
157 // the appropriate requests. This is in addition to the slew of other | |
158 // initializtion that is done in during creation of the URLRequestContext. | |
159 // We cannot yet centralize this code because URLRequestContext needs | |
160 // to be created before the StoragePartition context. | |
161 // | |
162 // TODO(ajwong): Fix the ordering so all the initialization is in one spot. | |
163 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | |
164 net::URLRequestJobFactory* job_factory = | |
165 const_cast<net::URLRequestJobFactory*>(context->job_factory()); | |
166 | |
167 // Note: if this is called twice with 2 request contexts that share one job | |
168 // factory (as is the case with a media request context and its related | |
169 // normal request context) then this will early exit. | |
170 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) | |
171 return; // Already initialized this JobFactory. | |
172 | |
173 bool set_protocol = job_factory->SetProtocolHandler( | |
174 chrome::kBlobScheme, | |
175 new BlobProtocolHandler( | |
176 blob_storage_context->controller(), | |
177 file_system_context, | |
178 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
179 DCHECK(set_protocol); | |
180 set_protocol = job_factory->SetProtocolHandler( | |
181 chrome::kFileSystemScheme, | |
182 CreateFileSystemProtocolHandler(file_system_context)); | |
183 DCHECK(set_protocol); | |
184 | |
185 job_factory->AddInterceptor( | |
186 new DeveloperProtocolHandler(appcache_service, | |
187 blob_storage_context->controller())); | |
188 | |
189 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | |
190 } | |
191 | |
192 // These constants are used to create the directory structure under the profile | 182 // These constants are used to create the directory structure under the profile |
193 // where renderers with a non-default storage partition keep their persistent | 183 // where renderers with a non-default storage partition keep their persistent |
194 // state. This will contain a set of directories that partially mirror the | 184 // state. This will contain a set of directories that partially mirror the |
195 // directory structure of BrowserContext::GetPath(). | 185 // directory structure of BrowserContext::GetPath(). |
196 // | 186 // |
197 // The kStoragePartitionDirname contains an extensions directory which is | 187 // The kStoragePartitionDirname contains an extensions directory which is |
198 // further partitioned by extension id, followed by another level of directories | 188 // further partitioned by extension id, followed by another level of directories |
199 // for the "default" extension storage partition and one directory for each | 189 // for the "default" extension storage partition and one directory for each |
200 // persistent partition used by a webview tag. Example: | 190 // persistent partition used by a webview tag. Example: |
201 // | 191 // |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 return it->second; | 462 return it->second; |
473 | 463 |
474 FilePath partition_path = | 464 FilePath partition_path = |
475 browser_context_->GetPath().Append( | 465 browser_context_->GetPath().Append( |
476 GetStoragePartitionPath(partition_domain, partition_name)); | 466 GetStoragePartitionPath(partition_domain, partition_name)); |
477 StoragePartitionImpl* partition = | 467 StoragePartitionImpl* partition = |
478 StoragePartitionImpl::Create(browser_context_, in_memory, | 468 StoragePartitionImpl::Create(browser_context_, in_memory, |
479 partition_path); | 469 partition_path); |
480 partitions_[partition_config] = partition; | 470 partitions_[partition_config] = partition; |
481 | 471 |
472 ChromeBlobStorageContext* blob_storage_context = | |
473 ChromeBlobStorageContext::GetFor(browser_context_); | |
474 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( | |
475 new BlobProtocolHandler(blob_storage_context, | |
476 partition->GetFileSystemContext())); | |
477 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
478 file_system_protocol_handler( | |
mmenke
2013/01/25 18:38:58
Hmm...Is this indentation right? Know that's what
awong
2013/01/25 19:52:57
Yah...filesystem_protocol_handlers should be in 4
| |
479 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | |
480 scoped_ptr<net::URLRequestJobFactory::Interceptor> developer_protocol_handler( | |
481 new DeveloperProtocolHandler(partition->GetAppCacheService(), | |
482 blob_storage_context)); | |
483 | |
482 // These calls must happen after StoragePartitionImpl::Create(). | 484 // These calls must happen after StoragePartitionImpl::Create(). |
483 partition->SetURLRequestContext( | 485 partition->SetURLRequestContext( |
484 partition_domain.empty() ? | 486 partition_domain.empty() ? |
485 browser_context_->GetRequestContext() : | 487 GetContentClient()->browser()->CreateRequestContext(browser_context_, |
486 browser_context_->GetRequestContextForStoragePartition( | 488 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
487 partition->GetPath(), in_memory)); | 489 developer_protocol_handler.Pass()) : |
490 GetContentClient()->browser()->CreateRequestContextForStoragePartition( | |
491 browser_context_, partition->GetPath(), in_memory, | |
492 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), | |
493 developer_protocol_handler.Pass())); | |
488 partition->SetMediaURLRequestContext( | 494 partition->SetMediaURLRequestContext( |
489 partition_domain.empty() ? | 495 partition_domain.empty() ? |
490 browser_context_->GetMediaRequestContext() : | 496 browser_context_->GetMediaRequestContext() : |
491 browser_context_->GetMediaRequestContextForStoragePartition( | 497 browser_context_->GetMediaRequestContextForStoragePartition( |
492 partition->GetPath(), in_memory)); | 498 partition->GetPath(), in_memory)); |
493 | 499 |
494 PostCreateInitialization(partition, in_memory); | 500 PostCreateInitialization(partition, in_memory); |
495 | 501 |
496 return partition; | 502 return partition; |
497 } | 503 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 BrowserThread::IO, FROM_HERE, | 592 BrowserThread::IO, FROM_HERE, |
587 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 593 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
588 partition->GetAppCacheService(), | 594 partition->GetAppCacheService(), |
589 in_memory ? FilePath() : | 595 in_memory ? FilePath() : |
590 partition->GetPath().Append(kAppCacheDirname), | 596 partition->GetPath().Append(kAppCacheDirname), |
591 browser_context_->GetResourceContext(), | 597 browser_context_->GetResourceContext(), |
592 make_scoped_refptr(partition->GetURLRequestContext()), | 598 make_scoped_refptr(partition->GetURLRequestContext()), |
593 make_scoped_refptr( | 599 make_scoped_refptr( |
594 browser_context_->GetSpecialStoragePolicy()))); | 600 browser_context_->GetSpecialStoragePolicy()))); |
595 | 601 |
596 // Add content's URLRequestContext's hooks. | |
597 BrowserThread::PostTask( | |
598 BrowserThread::IO, FROM_HERE, | |
599 base::Bind( | |
600 &InitializeURLRequestContext, | |
601 make_scoped_refptr(partition->GetURLRequestContext()), | |
602 make_scoped_refptr(partition->GetAppCacheService()), | |
603 make_scoped_refptr(partition->GetFileSystemContext()), | |
604 make_scoped_refptr( | |
605 ChromeBlobStorageContext::GetFor(browser_context_)))); | |
606 | |
607 // We do not call InitializeURLRequestContext() for media contexts because, | 602 // We do not call InitializeURLRequestContext() for media contexts because, |
608 // other than the HTTP cache, the media contexts share the same backing | 603 // other than the HTTP cache, the media contexts share the same backing |
609 // objects as their associated "normal" request context. Thus, the previous | 604 // objects as their associated "normal" request context. Thus, the previous |
610 // call serves to initialize the media request context for this storage | 605 // call serves to initialize the media request context for this storage |
611 // partition as well. | 606 // partition as well. |
612 } | 607 } |
613 } | 608 } |
614 | 609 |
615 } // namespace content | 610 } // namespace content |
OLD | NEW |