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

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

Issue 10909182: Make FileSystemContext respect StoragePartitions. filesystem:// urls will be properly isolated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch unittest fix from michael Created 8 years, 3 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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 class NonOwningZoomData : public base::SupportsUserData::Data { 48 class NonOwningZoomData : public base::SupportsUserData::Data {
49 public: 49 public:
50 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {} 50 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {}
51 HostZoomMap* host_zoom_map() { return host_zoom_map_; } 51 HostZoomMap* host_zoom_map() { return host_zoom_map_; }
52 52
53 private: 53 private:
54 HostZoomMap* host_zoom_map_; 54 HostZoomMap* host_zoom_map_;
55 }; 55 };
56 56
57 class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler {
58 public:
59 BlobProtocolHandler(
60 webkit_blob::BlobStorageController* blob_storage_controller,
61 base::MessageLoopProxy* loop_proxy)
62 : webkit_blob::BlobProtocolHandler(blob_storage_controller,
63 loop_proxy) {}
64
65 virtual ~BlobProtocolHandler() {}
66
67 private:
68 virtual scoped_refptr<webkit_blob::BlobData>
69 LookupBlobData(net::URLRequest* request) const {
70 const ResourceRequestInfoImpl* info =
71 ResourceRequestInfoImpl::ForRequest(request);
72 if (!info)
73 return NULL;
74 return info->requested_blob_data();
75 }
76
77 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler);
78 };
79
80 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol
81 // handler because we want to reuse the chrome://scheme (everyone is familiar
82 // with it, and no need to expose the content/chrome separation through our UI).
83 class DeveloperProtocolHandler
84 : public net::URLRequestJobFactory::Interceptor {
85 public:
86 DeveloperProtocolHandler(
87 AppCacheService* appcache_service,
88 BlobStorageController* blob_storage_controller)
89 : appcache_service_(appcache_service),
90 blob_storage_controller_(blob_storage_controller) {}
91 virtual ~DeveloperProtocolHandler() {}
92
93 virtual net::URLRequestJob* MaybeIntercept(
94 net::URLRequest* request,
95 net::NetworkDelegate* network_delegate) const OVERRIDE {
96 // Check for chrome://view-http-cache/*, which uses its own job type.
97 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url()))
98 return ViewHttpCacheJobFactory::CreateJobForRequest(request,
99 network_delegate);
100
101 // Next check for chrome://appcache-internals/, which uses its own job type.
102 if (request->url().SchemeIs(chrome::kChromeUIScheme) &&
103 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) {
104 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest(
105 request, network_delegate, appcache_service_);
106 }
107
108 // Next check for chrome://blob-internals/, which uses its own job type.
109 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) {
110 return ViewBlobInternalsJobFactory::CreateJobForRequest(
111 request, network_delegate, blob_storage_controller_);
112 }
113
114 #if defined(USE_TCMALLOC)
115 // Next check for chrome://tcmalloc/, which uses its own job type.
116 if (request->url().SchemeIs(chrome::kChromeUIScheme) &&
117 request->url().host() == chrome::kChromeUITcmallocHost) {
118 return new TcmallocInternalsRequestJob(request, network_delegate);
119 }
120 #endif
121
122 // Next check for chrome://histograms/, which uses its own job type.
123 if (request->url().SchemeIs(chrome::kChromeUIScheme) &&
124 request->url().host() == chrome::kChromeUIHistogramHost) {
125 return new HistogramInternalsRequestJob(request, network_delegate);
126 }
127
128 return NULL;
129 }
130
131 virtual net::URLRequestJob* MaybeInterceptRedirect(
132 const GURL& location,
133 net::URLRequest* request,
134 net::NetworkDelegate* network_delegate) const OVERRIDE {
135 return NULL;
136 }
137
138 virtual net::URLRequestJob* MaybeInterceptResponse(
139 net::URLRequest* request,
140 net::NetworkDelegate* network_delegate) const OVERRIDE {
141 return NULL;
142 }
143
144 virtual bool WillHandleProtocol(const std::string& protocol) const {
145 return protocol == chrome::kChromeUIScheme;
146 }
147
148 private:
149 AppCacheService* appcache_service_;
150 BlobStorageController* blob_storage_controller_;
151 };
152
153 void InitializeRequestContext(
154 scoped_refptr<net::URLRequestContextGetter> context_getter,
155 AppCacheService* appcache_service,
156 FileSystemContext* file_system_context,
157 ChromeBlobStorageContext* blob_storage_context) {
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
159 if (!context_getter)
160 return; // tests.
161 net::URLRequestContext* context = context_getter->GetURLRequestContext();
162 net::URLRequestJobFactory* job_factory =
163 const_cast<net::URLRequestJobFactory*>(context->job_factory());
164 if (job_factory->IsHandledProtocol(chrome::kBlobScheme))
165 return; // Already initialized this RequestContext.
166
167 bool set_protocol = job_factory->SetProtocolHandler(
168 chrome::kBlobScheme,
169 new BlobProtocolHandler(
170 blob_storage_context->controller(),
171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
172 DCHECK(set_protocol);
173 set_protocol = job_factory->SetProtocolHandler(
174 chrome::kFileSystemScheme,
175 CreateFileSystemProtocolHandler(file_system_context));
176 DCHECK(set_protocol);
177
178 job_factory->AddInterceptor(
179 new DeveloperProtocolHandler(appcache_service,
180 blob_storage_context->controller()));
181
182 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here!
183 }
184
185 } // namespace 57 } // namespace
186 58
187 59
188 ResourceContext::ResourceContext() { 60 ResourceContext::ResourceContext() {
189 if (ResourceDispatcherHostImpl::Get()) 61 if (ResourceDispatcherHostImpl::Get())
190 ResourceDispatcherHostImpl::Get()->AddResourceContext(this); 62 ResourceDispatcherHostImpl::Get()->AddResourceContext(this);
191 } 63 }
192 64
193 ResourceContext::~ResourceContext() { 65 ResourceContext::~ResourceContext() {
194 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); 66 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get();
(...skipping 25 matching lines...) Expand all
220 new UserDataAdapter<ChromeBlobStorageContext>( 92 new UserDataAdapter<ChromeBlobStorageContext>(
221 ChromeBlobStorageContext::GetFor(browser_context))); 93 ChromeBlobStorageContext::GetFor(browser_context)));
222 94
223 // This object is owned by the BrowserContext and not ResourceContext, so 95 // This object is owned by the BrowserContext and not ResourceContext, so
224 // store a non-owning pointer here. 96 // store a non-owning pointer here.
225 resource_context->SetUserData( 97 resource_context->SetUserData(
226 kHostZoomMapKeyName, 98 kHostZoomMapKeyName,
227 new NonOwningZoomData( 99 new NonOwningZoomData(
228 HostZoomMap::GetForBrowserContext(browser_context))); 100 HostZoomMap::GetForBrowserContext(browser_context)));
229 resource_context->DetachUserDataThread(); 101 resource_context->DetachUserDataThread();
230
231 StoragePartition* storage_partition =
232 BrowserContext::GetDefaultStoragePartition(browser_context);
233
234 // Add content's URLRequestContext's hooks.
235 // Check first to avoid memory leak in unittests.
236 // TODO(creis): Do equivalent initializations for isolated app and isolated
237 // media request contexts.
238 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
239 // TODO(ajwong): Move this whole block into
240 // StoragePartitionImplMap::PostCreateInitialization after we're certain
241 // this is safe to happen before InitializeResourceContext, and after we've
242 // found the right URLRequestContext for a storage partition. Otherwise,
243 // our isolated URLRequestContext getters will do the wrong thing for blobs,
244 // and FileSystemContext.
245 //
246 // http://crbug.com/85121
247
248 BrowserThread::PostTask(
249 BrowserThread::IO, FROM_HERE,
250 base::Bind(
251 &InitializeRequestContext,
252 make_scoped_refptr(browser_context->GetRequestContext()),
253 storage_partition->GetAppCacheService(),
254 make_scoped_refptr(
255 storage_partition->GetFileSystemContext()),
256 make_scoped_refptr(
257 ChromeBlobStorageContext::GetFor(browser_context))));
258 BrowserThread::PostTask(
259 BrowserThread::IO, FROM_HERE,
260 base::Bind(
261 &InitializeRequestContext,
262 make_scoped_refptr(browser_context->GetMediaRequestContext()),
263 storage_partition->GetAppCacheService(),
264 make_scoped_refptr(
265 storage_partition->GetFileSystemContext()),
266 make_scoped_refptr(
267 ChromeBlobStorageContext::GetFor(browser_context))));
268 }
269 } 102 }
270 103
271 } // namespace content 104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698