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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 11308362: Add StoragePartition's ProtocolHandlers at URLRequestContext construction time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync (r175140) Created 7 years, 11 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 "chrome/browser/net/chrome_url_request_context.h" 5 #include "chrome/browser/net/chrome_url_request_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 22 matching lines...) Expand all
33 33
34 namespace { 34 namespace {
35 35
36 // ---------------------------------------------------------------------------- 36 // ----------------------------------------------------------------------------
37 // Helper factories 37 // Helper factories
38 // ---------------------------------------------------------------------------- 38 // ----------------------------------------------------------------------------
39 39
40 // Factory that creates the main ChromeURLRequestContext. 40 // Factory that creates the main ChromeURLRequestContext.
41 class FactoryForMain : public ChromeURLRequestContextFactory { 41 class FactoryForMain : public ChromeURLRequestContextFactory {
42 public: 42 public:
43 explicit FactoryForMain(const ProfileIOData* profile_io_data) 43 FactoryForMain(
44 : profile_io_data_(profile_io_data) {} 44 const ProfileIOData* profile_io_data,
45 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
46 blob_protocol_handler,
47 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
48 file_system_protocol_handler,
49 scoped_ptr<net::URLRequestJobFactory::Interceptor>
50 developer_protocol_handler)
51 : profile_io_data_(profile_io_data),
52 blob_protocol_handler_(blob_protocol_handler.Pass()),
53 file_system_protocol_handler_(file_system_protocol_handler.Pass()),
54 developer_protocol_handler_(developer_protocol_handler.Pass()) {}
45 55
46 virtual ChromeURLRequestContext* Create() OVERRIDE { 56 virtual ChromeURLRequestContext* Create() OVERRIDE {
57 profile_io_data_->Init(blob_protocol_handler_.Pass(),
58 file_system_protocol_handler_.Pass(),
59 developer_protocol_handler_.Pass());
47 return profile_io_data_->GetMainRequestContext(); 60 return profile_io_data_->GetMainRequestContext();
48 } 61 }
49 62
50 private: 63 private:
51 const ProfileIOData* const profile_io_data_; 64 const ProfileIOData* const profile_io_data_;
65 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler_;
66 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
67 file_system_protocol_handler_;
68 scoped_ptr<net::URLRequestJobFactory::Interceptor>
69 developer_protocol_handler_;
52 }; 70 };
53 71
54 // Factory that creates the ChromeURLRequestContext for extensions. 72 // Factory that creates the ChromeURLRequestContext for extensions.
55 class FactoryForExtensions : public ChromeURLRequestContextFactory { 73 class FactoryForExtensions : public ChromeURLRequestContextFactory {
56 public: 74 public:
57 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) 75 explicit FactoryForExtensions(const ProfileIOData* profile_io_data)
58 : profile_io_data_(profile_io_data) {} 76 : profile_io_data_(profile_io_data) {}
59 77
60 virtual ChromeURLRequestContext* Create() OVERRIDE { 78 virtual ChromeURLRequestContext* Create() OVERRIDE {
61 return profile_io_data_->GetExtensionsRequestContext(); 79 return profile_io_data_->GetExtensionsRequestContext();
62 } 80 }
63 81
64 private: 82 private:
65 const ProfileIOData* const profile_io_data_; 83 const ProfileIOData* const profile_io_data_;
66 }; 84 };
67 85
68 // Factory that creates the ChromeURLRequestContext for a given isolated app. 86 // Factory that creates the ChromeURLRequestContext for a given isolated app.
69 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { 87 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory {
70 public: 88 public:
71 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, 89 FactoryForIsolatedApp(const ProfileIOData* profile_io_data,
72 const StoragePartitionDescriptor& partition_descriptor, 90 const StoragePartitionDescriptor& partition_descriptor,
73 ChromeURLRequestContextGetter* main_context, 91 ChromeURLRequestContextGetter* main_context,
74 scoped_ptr<net::URLRequestJobFactory::Interceptor> 92 scoped_ptr<net::URLRequestJobFactory::Interceptor>
75 protocol_handler_interceptor) 93 protocol_handler_interceptor,
94 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
95 blob_protocol_handler,
96 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
97 file_system_protocol_handler,
98 scoped_ptr<net::URLRequestJobFactory::Interceptor>
99 developer_protocol_handler)
76 : profile_io_data_(profile_io_data), 100 : profile_io_data_(profile_io_data),
77 partition_descriptor_(partition_descriptor), 101 partition_descriptor_(partition_descriptor),
78 main_request_context_getter_(main_context), 102 main_request_context_getter_(main_context),
79 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) {} 103 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()),
104 blob_protocol_handler_(blob_protocol_handler.Pass()),
105 file_system_protocol_handler_(file_system_protocol_handler.Pass()),
106 developer_protocol_handler_(developer_protocol_handler.Pass()) {}
80 107
81 virtual ChromeURLRequestContext* Create() OVERRIDE { 108 virtual ChromeURLRequestContext* Create() OVERRIDE {
82 // We will copy most of the state from the main request context. 109 // We will copy most of the state from the main request context.
83 // 110 //
84 // Note that this factory is one-shot. After Create() is called once, the 111 // Note that this factory is one-shot. After Create() is called once, the
85 // factory is actually destroyed. Thus it is safe to destructively pass 112 // factory is actually destroyed. Thus it is safe to destructively pass
86 // state onwards. 113 // state onwards.
87 return profile_io_data_->GetIsolatedAppRequestContext( 114 return profile_io_data_->GetIsolatedAppRequestContext(
88 main_request_context_getter_->GetIOContext(), partition_descriptor_, 115 main_request_context_getter_->GetIOContext(), partition_descriptor_,
89 protocol_handler_interceptor_.Pass()); 116 protocol_handler_interceptor_.Pass(), blob_protocol_handler_.Pass(),
117 file_system_protocol_handler_.Pass(),
118 developer_protocol_handler_.Pass());
90 } 119 }
91 120
92 private: 121 private:
93 const ProfileIOData* const profile_io_data_; 122 const ProfileIOData* const profile_io_data_;
94 const StoragePartitionDescriptor partition_descriptor_; 123 const StoragePartitionDescriptor partition_descriptor_;
95 scoped_refptr<ChromeURLRequestContextGetter> 124 scoped_refptr<ChromeURLRequestContextGetter>
96 main_request_context_getter_; 125 main_request_context_getter_;
97 scoped_ptr<net::URLRequestJobFactory::Interceptor> 126 scoped_ptr<net::URLRequestJobFactory::Interceptor>
98 protocol_handler_interceptor_; 127 protocol_handler_interceptor_;
128 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
129 blob_protocol_handler_;
130 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
131 file_system_protocol_handler_;
132 scoped_ptr<net::URLRequestJobFactory::Interceptor>
133 developer_protocol_handler_;
99 }; 134 };
100 135
101 // Factory that creates the media ChromeURLRequestContext for a given isolated 136 // Factory that creates the media ChromeURLRequestContext for a given isolated
102 // app. The media context is based on the corresponding isolated app's context. 137 // app. The media context is based on the corresponding isolated app's context.
103 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { 138 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory {
104 public: 139 public:
105 FactoryForIsolatedMedia( 140 FactoryForIsolatedMedia(
106 const ProfileIOData* profile_io_data, 141 const ProfileIOData* profile_io_data,
107 const StoragePartitionDescriptor& partition_descriptor, 142 const StoragePartitionDescriptor& partition_descriptor,
108 ChromeURLRequestContextGetter* app_context) 143 ChromeURLRequestContextGetter* app_context)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 209 }
175 210
176 scoped_refptr<base::SingleThreadTaskRunner> 211 scoped_refptr<base::SingleThreadTaskRunner>
177 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { 212 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const {
178 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 213 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
179 } 214 }
180 215
181 // static 216 // static
182 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal( 217 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal(
183 Profile* profile, 218 Profile* profile,
184 const ProfileIOData* profile_io_data) { 219 const ProfileIOData* profile_io_data,
220 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
221 blob_protocol_handler,
222 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
223 file_system_protocol_handler,
224 scoped_ptr<net::URLRequestJobFactory::Interceptor>
225 developer_protocol_handler) {
185 DCHECK(!profile->IsOffTheRecord()); 226 DCHECK(!profile->IsOffTheRecord());
186 return new ChromeURLRequestContextGetter( 227 return new ChromeURLRequestContextGetter(
187 new FactoryForMain(profile_io_data)); 228 new FactoryForMain(profile_io_data,
229 blob_protocol_handler.Pass(),
230 file_system_protocol_handler.Pass(),
231 developer_protocol_handler.Pass()));
188 } 232 }
189 233
190 // static 234 // static
191 ChromeURLRequestContextGetter* 235 ChromeURLRequestContextGetter*
192 ChromeURLRequestContextGetter::CreateOriginalForMedia( 236 ChromeURLRequestContextGetter::CreateOriginalForMedia(
193 Profile* profile, const ProfileIOData* profile_io_data) { 237 Profile* profile, const ProfileIOData* profile_io_data) {
194 DCHECK(!profile->IsOffTheRecord()); 238 DCHECK(!profile->IsOffTheRecord());
195 return new ChromeURLRequestContextGetter( 239 return new ChromeURLRequestContextGetter(
196 new FactoryForMedia(profile_io_data)); 240 new FactoryForMedia(profile_io_data));
197 } 241 }
198 242
199 // static 243 // static
200 ChromeURLRequestContextGetter* 244 ChromeURLRequestContextGetter*
201 ChromeURLRequestContextGetter::CreateOriginalForExtensions( 245 ChromeURLRequestContextGetter::CreateOriginalForExtensions(
202 Profile* profile, const ProfileIOData* profile_io_data) { 246 Profile* profile, const ProfileIOData* profile_io_data) {
203 DCHECK(!profile->IsOffTheRecord()); 247 DCHECK(!profile->IsOffTheRecord());
204 return new ChromeURLRequestContextGetter( 248 return new ChromeURLRequestContextGetter(
205 new FactoryForExtensions(profile_io_data)); 249 new FactoryForExtensions(profile_io_data));
206 } 250 }
207 251
208 // static 252 // static
209 ChromeURLRequestContextGetter* 253 ChromeURLRequestContextGetter*
210 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( 254 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
211 Profile* profile, 255 Profile* profile,
212 const ProfileIOData* profile_io_data, 256 const ProfileIOData* profile_io_data,
213 const StoragePartitionDescriptor& partition_descriptor, 257 const StoragePartitionDescriptor& partition_descriptor,
214 scoped_ptr<net::URLRequestJobFactory::Interceptor> 258 scoped_ptr<net::URLRequestJobFactory::Interceptor>
215 protocol_handler_interceptor) { 259 protocol_handler_interceptor,
260 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
261 blob_protocol_handler,
262 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
263 file_system_protocol_handler,
264 scoped_ptr<net::URLRequestJobFactory::Interceptor>
265 developer_protocol_handler) {
216 DCHECK(!profile->IsOffTheRecord()); 266 DCHECK(!profile->IsOffTheRecord());
217 ChromeURLRequestContextGetter* main_context = 267 ChromeURLRequestContextGetter* main_context =
218 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 268 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
219 return new ChromeURLRequestContextGetter( 269 return new ChromeURLRequestContextGetter(
220 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, 270 new FactoryForIsolatedApp(profile_io_data, partition_descriptor,
221 main_context, protocol_handler_interceptor.Pass())); 271 main_context, protocol_handler_interceptor.Pass(),
272 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(),
273 developer_protocol_handler.Pass()));
222 } 274 }
223 275
224 // static 276 // static
225 ChromeURLRequestContextGetter* 277 ChromeURLRequestContextGetter*
226 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( 278 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia(
227 Profile* profile, 279 Profile* profile,
228 ChromeURLRequestContextGetter* app_context, 280 ChromeURLRequestContextGetter* app_context,
229 const ProfileIOData* profile_io_data, 281 const ProfileIOData* profile_io_data,
230 const StoragePartitionDescriptor& partition_descriptor) { 282 const StoragePartitionDescriptor& partition_descriptor) {
231 DCHECK(!profile->IsOffTheRecord()); 283 DCHECK(!profile->IsOffTheRecord());
232 return new ChromeURLRequestContextGetter( 284 return new ChromeURLRequestContextGetter(
233 new FactoryForIsolatedMedia( 285 new FactoryForIsolatedMedia(
234 profile_io_data, partition_descriptor, app_context)); 286 profile_io_data, partition_descriptor, app_context));
235 } 287 }
236 288
237 // static 289 // static
238 ChromeURLRequestContextGetter* 290 ChromeURLRequestContextGetter*
239 ChromeURLRequestContextGetter::CreateOffTheRecord( 291 ChromeURLRequestContextGetter::CreateOffTheRecord(
240 Profile* profile, const ProfileIOData* profile_io_data) { 292 Profile* profile,
293 const ProfileIOData* profile_io_data,
294 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
295 blob_protocol_handler,
296 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
297 file_system_protocol_handler,
298 scoped_ptr<net::URLRequestJobFactory::Interceptor>
299 developer_protocol_handler) {
241 DCHECK(profile->IsOffTheRecord()); 300 DCHECK(profile->IsOffTheRecord());
242 return new ChromeURLRequestContextGetter( 301 return new ChromeURLRequestContextGetter(
243 new FactoryForMain(profile_io_data)); 302 new FactoryForMain(profile_io_data,
303 blob_protocol_handler.Pass(),
304 file_system_protocol_handler.Pass(),
305 developer_protocol_handler.Pass()));
244 } 306 }
245 307
246 // static 308 // static
247 ChromeURLRequestContextGetter* 309 ChromeURLRequestContextGetter*
248 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( 310 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
249 Profile* profile, const ProfileIOData* profile_io_data) { 311 Profile* profile, const ProfileIOData* profile_io_data) {
250 DCHECK(profile->IsOffTheRecord()); 312 DCHECK(profile->IsOffTheRecord());
251 return new ChromeURLRequestContextGetter( 313 return new ChromeURLRequestContextGetter(
252 new FactoryForExtensions(profile_io_data)); 314 new FactoryForExtensions(profile_io_data));
253 } 315 }
254 316
255 // static 317 // static
256 ChromeURLRequestContextGetter* 318 ChromeURLRequestContextGetter*
257 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 319 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
258 Profile* profile, 320 Profile* profile,
259 const ProfileIOData* profile_io_data, 321 const ProfileIOData* profile_io_data,
260 const StoragePartitionDescriptor& partition_descriptor, 322 const StoragePartitionDescriptor& partition_descriptor,
261 scoped_ptr<net::URLRequestJobFactory::Interceptor> 323 scoped_ptr<net::URLRequestJobFactory::Interceptor>
262 protocol_handler_interceptor) { 324 protocol_handler_interceptor,
325 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
326 blob_protocol_handler,
327 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
328 file_system_protocol_handler,
329 scoped_ptr<net::URLRequestJobFactory::Interceptor>
330 developer_protocol_handler) {
263 DCHECK(profile->IsOffTheRecord()); 331 DCHECK(profile->IsOffTheRecord());
264 ChromeURLRequestContextGetter* main_context = 332 ChromeURLRequestContextGetter* main_context =
265 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); 333 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
266 return new ChromeURLRequestContextGetter( 334 return new ChromeURLRequestContextGetter(
267 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, 335 new FactoryForIsolatedApp(profile_io_data, partition_descriptor,
268 main_context, protocol_handler_interceptor.Pass())); 336 main_context, protocol_handler_interceptor.Pass(),
337 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(),
338 developer_protocol_handler.Pass()));
269 } 339 }
270 340
271 // ---------------------------------------------------------------------------- 341 // ----------------------------------------------------------------------------
272 // ChromeURLRequestContext 342 // ChromeURLRequestContext
273 // ---------------------------------------------------------------------------- 343 // ----------------------------------------------------------------------------
274 344
275 ChromeURLRequestContext::ChromeURLRequestContext( 345 ChromeURLRequestContext::ChromeURLRequestContext(
276 ContextType type, 346 ContextType type,
277 chrome_browser_net::LoadTimeStats* load_time_stats) 347 chrome_browser_net::LoadTimeStats* load_time_stats)
278 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 348 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
(...skipping 22 matching lines...) Expand all
301 ChromeURLDataManagerBackend* 371 ChromeURLDataManagerBackend*
302 ChromeURLRequestContext::chrome_url_data_manager_backend() const { 372 ChromeURLRequestContext::chrome_url_data_manager_backend() const {
303 return chrome_url_data_manager_backend_; 373 return chrome_url_data_manager_backend_;
304 } 374 }
305 375
306 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( 376 void ChromeURLRequestContext::set_chrome_url_data_manager_backend(
307 ChromeURLDataManagerBackend* backend) { 377 ChromeURLDataManagerBackend* backend) {
308 DCHECK(backend); 378 DCHECK(backend);
309 chrome_url_data_manager_backend_ = backend; 379 chrome_url_data_manager_backend_ = backend;
310 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698