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/resource_context_impl.h" | 5 #include "content/browser/resource_context_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/appcache/chrome_appcache_service.h" | 8 #include "content/browser/appcache/chrome_appcache_service.h" |
9 #include "content/browser/fileapi/browser_file_system_helper.h" | 9 #include "content/browser/fileapi/browser_file_system_helper.h" |
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 virtual bool WillHandleProtocol(const std::string& protocol) const { | 147 virtual bool WillHandleProtocol(const std::string& protocol) const { |
148 return protocol == chrome::kChromeUIScheme; | 148 return protocol == chrome::kChromeUIScheme; |
149 } | 149 } |
150 | 150 |
151 private: | 151 private: |
152 AppCacheService* appcache_service_; | 152 AppCacheService* appcache_service_; |
153 BlobStorageController* blob_storage_controller_; | 153 BlobStorageController* blob_storage_controller_; |
154 }; | 154 }; |
155 | 155 |
156 void InitializeRequestContext( | 156 void InitializeRequestContext( |
157 ResourceContext* resource_context, | 157 scoped_refptr<net::URLRequestContextGetter> context_getter, |
158 scoped_refptr<net::URLRequestContextGetter> context_getter) { | 158 AppCacheService* appcache_service, |
| 159 FileSystemContext* file_system_context, |
| 160 ChromeBlobStorageContext* blob_storage_context) { |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
159 if (!context_getter) | 162 if (!context_getter) |
160 return; // tests. | 163 return; // tests. |
161 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | 164 net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
162 net::URLRequestJobFactory* job_factory = | 165 net::URLRequestJobFactory* job_factory = |
163 const_cast<net::URLRequestJobFactory*>(context->job_factory()); | 166 const_cast<net::URLRequestJobFactory*>(context->job_factory()); |
164 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) | 167 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) |
165 return; // Already initialized this RequestContext. | 168 return; // Already initialized this RequestContext. |
166 | 169 |
167 bool set_protocol = job_factory->SetProtocolHandler( | 170 bool set_protocol = job_factory->SetProtocolHandler( |
168 chrome::kBlobScheme, | 171 chrome::kBlobScheme, |
169 new BlobProtocolHandler( | 172 new BlobProtocolHandler( |
170 GetBlobStorageControllerForResourceContext(resource_context), | 173 blob_storage_context->controller(), |
171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 174 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
172 DCHECK(set_protocol); | 175 DCHECK(set_protocol); |
173 set_protocol = job_factory->SetProtocolHandler( | 176 set_protocol = job_factory->SetProtocolHandler( |
174 chrome::kFileSystemScheme, | 177 chrome::kFileSystemScheme, |
175 CreateFileSystemProtocolHandler( | 178 CreateFileSystemProtocolHandler(file_system_context)); |
176 GetFileSystemContextForResourceContext(resource_context))); | |
177 DCHECK(set_protocol); | 179 DCHECK(set_protocol); |
178 | 180 |
179 job_factory->AddInterceptor(new DeveloperProtocolHandler( | 181 job_factory->AddInterceptor( |
180 ResourceContext::GetAppCacheService(resource_context), | 182 new DeveloperProtocolHandler(appcache_service, |
181 GetBlobStorageControllerForResourceContext(resource_context))); | 183 blob_storage_context->controller())); |
182 | 184 |
183 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | 185 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! |
184 } | 186 } |
185 | 187 |
186 } // namespace | 188 } // namespace |
187 | 189 |
188 AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) { | 190 AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) { |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
190 return UserDataAdapter<ChromeAppCacheService>::Get( | 192 return UserDataAdapter<ChromeAppCacheService>::Get( |
191 context, kAppCacheServiceKeyName); | 193 context, kAppCacheServiceKeyName); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 resource_context->SetUserData( | 279 resource_context->SetUserData( |
278 kHostZoomMapKeyName, | 280 kHostZoomMapKeyName, |
279 new NonOwningZoomData( | 281 new NonOwningZoomData( |
280 HostZoomMap::GetForBrowserContext(browser_context))); | 282 HostZoomMap::GetForBrowserContext(browser_context))); |
281 | 283 |
282 // Add content's URLRequestContext's hooks. | 284 // Add content's URLRequestContext's hooks. |
283 // Check first to avoid memory leak in unittests. | 285 // Check first to avoid memory leak in unittests. |
284 // TODO(creis): Do equivalent initializations for isolated app and isolated | 286 // TODO(creis): Do equivalent initializations for isolated app and isolated |
285 // media request contexts. | 287 // media request contexts. |
286 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 288 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 289 // TODO(ajwong): Move this whole block into |
| 290 // StoragePartitionImplMap::PostCreateInitialization after we're certain |
| 291 // this is safe to happen before InitializeResourceContext, and after we've |
| 292 // found the right URLRequestContext for a storage partition. Otherwise, |
| 293 // our isolated URLRequestContext getters will do the wrong thing for blobs, |
| 294 // and FileSystemContext. |
| 295 // |
| 296 // http://crbug.com/85121 |
| 297 |
287 BrowserThread::PostTask( | 298 BrowserThread::PostTask( |
288 BrowserThread::IO, FROM_HERE, | 299 BrowserThread::IO, FROM_HERE, |
289 base::Bind(&InitializeRequestContext, | 300 base::Bind( |
290 resource_context, | 301 &InitializeRequestContext, |
291 make_scoped_refptr(browser_context->GetRequestContext()))); | 302 make_scoped_refptr(browser_context->GetRequestContext()), |
| 303 BrowserContext::GetAppCacheService(browser_context), |
| 304 make_scoped_refptr( |
| 305 BrowserContext::GetFileSystemContext(browser_context)), |
| 306 make_scoped_refptr( |
| 307 ChromeBlobStorageContext::GetFor(browser_context)))); |
292 BrowserThread::PostTask( | 308 BrowserThread::PostTask( |
293 BrowserThread::IO, FROM_HERE, | 309 BrowserThread::IO, FROM_HERE, |
294 base::Bind(&InitializeRequestContext, | 310 base::Bind( |
295 resource_context, | 311 &InitializeRequestContext, |
296 make_scoped_refptr( | 312 make_scoped_refptr(browser_context->GetMediaRequestContext()), |
297 browser_context->GetMediaRequestContext()))); | 313 BrowserContext::GetAppCacheService(browser_context), |
| 314 make_scoped_refptr( |
| 315 BrowserContext::GetFileSystemContext(browser_context)), |
| 316 make_scoped_refptr( |
| 317 ChromeBlobStorageContext::GetFor(browser_context)))); |
298 } | 318 } |
299 } | 319 } |
300 | 320 |
301 } // namespace content | 321 } // namespace content |
OLD | NEW |