Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: content/browser/resource_context_impl.cc

Issue 10878041: Remove silly uses of ResourceContext that unnecessarily violate the Law of Demeter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: only the IO thread may grab the controller. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/browser_context.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, blob_storage_context->contr oller()));
michaeln 2012/08/25 01:18:09 line length
181 GetBlobStorageControllerForResourceContext(resource_context)));
182 183
183 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! 184 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here!
184 } 185 }
185 186
186 } // namespace 187 } // namespace
187 188
188 AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) { 189 AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
190 return UserDataAdapter<ChromeAppCacheService>::Get( 191 return UserDataAdapter<ChromeAppCacheService>::Get(
191 context, kAppCacheServiceKeyName); 192 context, kAppCacheServiceKeyName);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 resource_context->SetUserData( 278 resource_context->SetUserData(
278 kHostZoomMapKeyName, 279 kHostZoomMapKeyName,
279 new NonOwningZoomData( 280 new NonOwningZoomData(
280 HostZoomMap::GetForBrowserContext(browser_context))); 281 HostZoomMap::GetForBrowserContext(browser_context)));
281 282
282 // Add content's URLRequestContext's hooks. 283 // Add content's URLRequestContext's hooks.
283 // Check first to avoid memory leak in unittests. 284 // Check first to avoid memory leak in unittests.
284 // TODO(creis): Do equivalent initializations for isolated app and isolated 285 // TODO(creis): Do equivalent initializations for isolated app and isolated
285 // media request contexts. 286 // media request contexts.
286 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 287 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
288 // TODO(ajwong): Move this whole block into
289 // StoragePartitionImplMap::PostCreateInitialization after we're certain
290 // this is safe to happen before InitializeResourceContext, and after we've
291 // found the right URLRequestContext for a storage partition. Otherwise,
292 // our isolated URLRequestContext getters will do the wrong thing for blobs,
293 // and FileSystemContext.
294 //
295 // http://crbug.com/85121
296
287 BrowserThread::PostTask( 297 BrowserThread::PostTask(
288 BrowserThread::IO, FROM_HERE, 298 BrowserThread::IO, FROM_HERE,
289 base::Bind(&InitializeRequestContext, 299 base::Bind(
290 resource_context, 300 &InitializeRequestContext,
291 make_scoped_refptr(browser_context->GetRequestContext()))); 301 make_scoped_refptr(browser_context->GetRequestContext()),
302 BrowserContext::GetAppCacheService(browser_context),
michaeln 2012/08/25 01:18:09 specifically, i wonder if BrowserContext::GetAppCa
303 make_scoped_refptr(
304 BrowserContext::GetFileSystemContext(browser_context)),
305 make_scoped_refptr(
306 ChromeBlobStorageContext::GetFor(browser_context))));
292 BrowserThread::PostTask( 307 BrowserThread::PostTask(
293 BrowserThread::IO, FROM_HERE, 308 BrowserThread::IO, FROM_HERE,
294 base::Bind(&InitializeRequestContext, 309 base::Bind(
295 resource_context, 310 &InitializeRequestContext,
296 make_scoped_refptr( 311 make_scoped_refptr(browser_context->GetMediaRequestContext()),
297 browser_context->GetMediaRequestContext()))); 312 BrowserContext::GetAppCacheService(browser_context),
313 make_scoped_refptr(
314 BrowserContext::GetFileSystemContext(browser_context)),
315 make_scoped_refptr(
316 ChromeBlobStorageContext::GetFor(browser_context))));
298 } 317 }
299 } 318 }
300 319
301 } // namespace content 320 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698