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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 }; | 137 }; |
138 | 138 |
139 void InitializeURLRequestContext( | 139 void InitializeURLRequestContext( |
140 net::URLRequestContextGetter* context_getter, | 140 net::URLRequestContextGetter* context_getter, |
141 AppCacheService* appcache_service, | 141 AppCacheService* appcache_service, |
142 FileSystemContext* file_system_context, | 142 FileSystemContext* file_system_context, |
143 ChromeBlobStorageContext* blob_storage_context) { | 143 ChromeBlobStorageContext* blob_storage_context) { |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
145 if (!context_getter) | 145 if (!context_getter) |
146 return; // tests. | 146 return; // tests. |
| 147 |
| 148 // This code only modifies the URLRequestJobFactory on the context |
| 149 // to handle blob: URLs, filesystem: URLs, and to let AppCache intercept |
| 150 // the appropriate requests. This is in addition to the slew of other |
| 151 // initializtion that is done in during creation of the URLRequestContext. |
| 152 // We cannot yet centralize this code because URLRequestContext needs |
| 153 // to be created before the StoragePartition context. |
| 154 // |
| 155 // TODO(ajwong): Fix the ordering so all the initialization is in one spot. |
147 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | 156 net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
148 net::URLRequestJobFactory* job_factory = | 157 net::URLRequestJobFactory* job_factory = |
149 const_cast<net::URLRequestJobFactory*>(context->job_factory()); | 158 const_cast<net::URLRequestJobFactory*>(context->job_factory()); |
| 159 |
| 160 // Note: if this is called twice with 2 request contexts that share one job |
| 161 // factory (as is the case with a media request context and its related |
| 162 // normal request context) then this will early exit. |
150 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) | 163 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) |
151 return; // Already initialized this RequestContext. | 164 return; // Already initialized this JobFactory. |
152 | 165 |
153 bool set_protocol = job_factory->SetProtocolHandler( | 166 bool set_protocol = job_factory->SetProtocolHandler( |
154 chrome::kBlobScheme, | 167 chrome::kBlobScheme, |
155 new BlobProtocolHandler( | 168 new BlobProtocolHandler( |
156 blob_storage_context->controller(), | 169 blob_storage_context->controller(), |
157 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
158 DCHECK(set_protocol); | 171 DCHECK(set_protocol); |
159 set_protocol = job_factory->SetProtocolHandler( | 172 set_protocol = job_factory->SetProtocolHandler( |
160 chrome::kFileSystemScheme, | 173 chrome::kFileSystemScheme, |
161 CreateFileSystemProtocolHandler(file_system_context)); | 174 CreateFileSystemProtocolHandler(file_system_context)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // Add content's URLRequestContext's hooks. | 259 // Add content's URLRequestContext's hooks. |
247 BrowserThread::PostTask( | 260 BrowserThread::PostTask( |
248 BrowserThread::IO, FROM_HERE, | 261 BrowserThread::IO, FROM_HERE, |
249 base::Bind( | 262 base::Bind( |
250 &InitializeURLRequestContext, | 263 &InitializeURLRequestContext, |
251 make_scoped_refptr(partition->GetURLRequestContext()), | 264 make_scoped_refptr(partition->GetURLRequestContext()), |
252 make_scoped_refptr(partition->GetAppCacheService()), | 265 make_scoped_refptr(partition->GetAppCacheService()), |
253 make_scoped_refptr(partition->GetFileSystemContext()), | 266 make_scoped_refptr(partition->GetFileSystemContext()), |
254 make_scoped_refptr( | 267 make_scoped_refptr( |
255 ChromeBlobStorageContext::GetFor(browser_context_)))); | 268 ChromeBlobStorageContext::GetFor(browser_context_)))); |
256 BrowserThread::PostTask( | 269 |
257 BrowserThread::IO, FROM_HERE, | 270 // We do not call InitializeURLRequestContext() for media contexts because, |
258 base::Bind( | 271 // other than the HTTP cache, the media contexts share the same backing |
259 &InitializeURLRequestContext, | 272 // objects as their associated "normal" request context. Thus, the previous |
260 make_scoped_refptr(partition->GetMediaURLRequestContext()), | 273 // call serves to initialize the media request context for this storage |
261 make_scoped_refptr(partition->GetAppCacheService()), | 274 // partition as well. |
262 make_scoped_refptr(partition->GetFileSystemContext()), | |
263 make_scoped_refptr( | |
264 ChromeBlobStorageContext::GetFor(browser_context_)))); | |
265 } | 275 } |
266 } | 276 } |
267 | 277 |
268 } // namespace content | 278 } // namespace content |
OLD | NEW |