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

Side by Side Diff: chrome/browser/profiles/off_the_record_profile_io_data.cc

Issue 10969017: Create a new URLRequestJobFactory for isolated request contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ordering 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 "chrome/browser/profiles/off_the_record_profile_io_data.h" 5 #include "chrome/browser/profiles/off_the_record_profile_io_data.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/threading/worker_pool.h" 11 #include "base/threading/worker_pool.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
14 #include "chrome/browser/io_thread.h" 16 #include "chrome/browser/io_thread.h"
15 #include "chrome/browser/net/about_protocol_handler.h" 17 #include "chrome/browser/net/about_protocol_handler.h"
16 #include "chrome/browser/net/chrome_net_log.h" 18 #include "chrome/browser/net/chrome_net_log.h"
17 #include "chrome/browser/net/chrome_url_request_context.h" 19 #include "chrome/browser/net/chrome_url_request_context.h"
18 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 22 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
21 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/resource_context.h" 28 #include "content/public/browser/resource_context.h"
27 #include "net/base/default_server_bound_cert_store.h" 29 #include "net/base/default_server_bound_cert_store.h"
28 #include "net/base/server_bound_cert_service.h" 30 #include "net/base/server_bound_cert_service.h"
29 #include "net/ftp/ftp_network_layer.h" 31 #include "net/ftp/ftp_network_layer.h"
30 #include "net/http/http_cache.h" 32 #include "net/http/http_cache.h"
31 #include "net/http/http_network_session.h" 33 #include "net/http/http_network_session.h"
32 #include "net/http/http_server_properties_impl.h" 34 #include "net/http/http_server_properties_impl.h"
33 #include "net/url_request/file_protocol_handler.h"
34 #include "net/url_request/ftp_protocol_handler.h"
35 #include "net/url_request/url_request_job_factory_impl.h" 35 #include "net/url_request/url_request_job_factory_impl.h"
36 #include "webkit/database/database_tracker.h" 36 #include "webkit/database/database_tracker.h"
37 37
38 using content::BrowserThread; 38 using content::BrowserThread;
39 39
40 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) 40 OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
41 : io_data_(new OffTheRecordProfileIOData), 41 : io_data_(new OffTheRecordProfileIOData),
42 profile_(profile), 42 profile_(profile),
43 initialized_(false) { 43 initialized_(false) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
122 DCHECK(!app_id.empty()); 122 DCHECK(!app_id.empty());
123 LazyInitialize(); 123 LazyInitialize();
124 124
125 // Keep a map of request context getters, one per requested app ID. 125 // Keep a map of request context getters, one per requested app ID.
126 ChromeURLRequestContextGetterMap::iterator iter = 126 ChromeURLRequestContextGetterMap::iterator iter =
127 app_request_context_getter_map_.find(app_id); 127 app_request_context_getter_map_.find(app_id);
128 if (iter != app_request_context_getter_map_.end()) 128 if (iter != app_request_context_getter_map_.end())
129 return iter->second; 129 return iter->second;
130 130
131 scoped_ptr<net::URLRequestJobFactory::Interceptor>
132 protocol_handler_interceptor(
133 ProtocolHandlerRegistryFactory::GetForProfile(profile_)->
134 CreateURLInterceptor());
131 ChromeURLRequestContextGetter* context = 135 ChromeURLRequestContextGetter* context =
132 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( 136 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
133 profile_, io_data_, app_id); 137 profile_, io_data_, app_id, protocol_handler_interceptor.Pass());
134 app_request_context_getter_map_[app_id] = context; 138 app_request_context_getter_map_[app_id] = context;
135 139
136 return context; 140 return context;
137 } 141 }
138 142
139 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { 143 void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
140 if (initialized_) 144 if (initialized_)
141 return; 145 return;
142 146
143 // Set initialized_ to true at the beginning in case any of the objects 147 // Set initialized_ to true at the beginning in case any of the objects
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 PopulateNetworkSessionParams(profile_params, &network_session_params); 226 PopulateNetworkSessionParams(profile_params, &network_session_params);
223 net::HttpCache* cache = new net::HttpCache( 227 net::HttpCache* cache = new net::HttpCache(
224 network_session_params, main_backend); 228 network_session_params, main_backend);
225 229
226 main_http_factory_.reset(cache); 230 main_http_factory_.reset(cache);
227 main_context->set_http_transaction_factory(cache); 231 main_context->set_http_transaction_factory(cache);
228 #if !defined(DISABLE_FTP_SUPPORT) 232 #if !defined(DISABLE_FTP_SUPPORT)
229 ftp_factory_.reset( 233 ftp_factory_.reset(
230 new net::FtpNetworkLayer(main_context->host_resolver())); 234 new net::FtpNetworkLayer(main_context->host_resolver()));
231 main_context->set_ftp_transaction_factory(ftp_factory_.get()); 235 main_context->set_ftp_transaction_factory(ftp_factory_.get());
236 extensions_context->set_ftp_transaction_factory(ftp_factory_.get());
232 #endif // !defined(DISABLE_FTP_SUPPORT) 237 #endif // !defined(DISABLE_FTP_SUPPORT)
233 238
234 main_context->set_chrome_url_data_manager_backend( 239 main_context->set_chrome_url_data_manager_backend(
235 chrome_url_data_manager_backend()); 240 chrome_url_data_manager_backend());
236 241
237 main_job_factory_.reset(new net::URLRequestJobFactoryImpl); 242 main_job_factory_.reset(new net::URLRequestJobFactoryImpl());
238 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); 243 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl());
239 244
240 int set_protocol = main_job_factory_->SetProtocolHandler( 245 SetUpJobFactoryDefaults(
241 chrome::kFileScheme, new net::FileProtocolHandler()); 246 main_job_factory_.get(),
242 DCHECK(set_protocol); 247 profile_params->protocol_handler_interceptor.Pass(),
243 // TODO(shalev): The extension_job_factory_ has a NULL NetworkDelegate. 248 network_delegate(),
249 main_context->ftp_transaction_factory(),
250 main_context->ftp_auth_cache());
251 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate.
244 // Without a network_delegate, this protocol handler will never 252 // Without a network_delegate, this protocol handler will never
245 // handle file: requests, but as a side effect it makes 253 // handle file: requests, but as a side effect it makes
246 // job_factory::IsHandledProtocol return true, which prevents attempts to 254 // job_factory::IsHandledProtocol return true, which prevents attempts to
247 // handle the protocol externally. 255 // handle the protocol externally. We pass NULL in to
248 set_protocol = extensions_job_factory_->SetProtocolHandler( 256 // SetUpJobFactoryDefaults() to get this effect.
249 chrome::kFileScheme, new net::FileProtocolHandler()); 257 SetUpJobFactoryDefaults(
250 DCHECK(set_protocol); 258 extensions_job_factory_.get(),
251 259 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL),
252 set_protocol = main_job_factory_->SetProtocolHandler( 260 NULL,
253 chrome::kChromeDevToolsScheme, 261 extensions_context->ftp_transaction_factory(),
254 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), 262 extensions_context->ftp_auth_cache());
255 network_delegate()));
256 DCHECK(set_protocol);
257 set_protocol = extensions_job_factory_->SetProtocolHandler(
258 chrome::kChromeDevToolsScheme,
259 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), NULL));
260 DCHECK(set_protocol);
261
262 net::URLRequestJobFactory* job_factories[2];
263 job_factories[0] = main_job_factory_.get();
264 job_factories[1] = extensions_job_factory_.get();
265
266 net::FtpAuthCache* ftp_auth_caches[2];
267 ftp_auth_caches[0] = main_context->ftp_auth_cache();
268 ftp_auth_caches[1] = extensions_context->ftp_auth_cache();
269
270 for (int i = 0; i < 2; i++) {
271 SetUpJobFactoryDefaults(job_factories[i]);
272 job_factories[i]->SetProtocolHandler(chrome::kAboutScheme,
273 new net::AboutProtocolHandler());
274 CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]);
275 }
276 263
277 main_context->set_job_factory(main_job_factory_.get()); 264 main_context->set_job_factory(main_job_factory_.get());
278 extensions_context->set_job_factory(extensions_job_factory_.get()); 265 extensions_context->set_job_factory(extensions_job_factory_.get());
279 } 266 }
280 267
281 ChromeURLRequestContext* 268 ChromeURLRequestContext*
282 OffTheRecordProfileIOData::InitializeAppRequestContext( 269 OffTheRecordProfileIOData::InitializeAppRequestContext(
283 ChromeURLRequestContext* main_context, 270 ChromeURLRequestContext* main_context,
284 const std::string& app_id) const { 271 const std::string& app_id,
272 scoped_ptr<net::URLRequestJobFactory::Interceptor>
273 protocol_handler_interceptor) const {
285 AppRequestContext* context = new AppRequestContext(load_time_stats()); 274 AppRequestContext* context = new AppRequestContext(load_time_stats());
286 275
287 // Copy most state from the main context. 276 // Copy most state from the main context.
288 context->CopyFrom(main_context); 277 context->CopyFrom(main_context);
289 278
290 // Use a separate in-memory cookie store for the app. 279 // Use a separate in-memory cookie store for the app.
291 // TODO(creis): We should have a cookie delegate for notifying the cookie 280 // TODO(creis): We should have a cookie delegate for notifying the cookie
292 // extensions API, but we need to update it to understand isolated apps first. 281 // extensions API, but we need to update it to understand isolated apps first.
293 context->SetCookieStore(new net::CookieMonster(NULL, NULL)); 282 context->SetCookieStore(new net::CookieMonster(NULL, NULL));
294 283
295 // Use a separate in-memory cache for the app. 284 // Use a separate in-memory cache for the app.
296 net::HttpCache::BackendFactory* app_backend = 285 net::HttpCache::BackendFactory* app_backend =
297 net::HttpCache::DefaultBackend::InMemory(0); 286 net::HttpCache::DefaultBackend::InMemory(0);
298 net::HttpNetworkSession* main_network_session = 287 net::HttpNetworkSession* main_network_session =
299 main_http_factory_->GetSession(); 288 main_http_factory_->GetSession();
300 net::HttpCache* app_http_cache = 289 scoped_ptr<net::HttpTransactionFactory> app_http_cache(
301 new net::HttpCache(main_network_session, app_backend); 290 new net::HttpCache(main_network_session, app_backend));
302 291
303 context->SetHttpTransactionFactory(app_http_cache); 292 context->SetHttpTransactionFactory(app_http_cache.Pass());
293
294 scoped_ptr<net::URLRequestJobFactory> job_factory(
295 new net::URLRequestJobFactoryImpl());
296 SetUpJobFactoryDefaults(job_factory.get(),
297 protocol_handler_interceptor.Pass(),
298 network_delegate(),
299 context->ftp_transaction_factory(),
300 context->ftp_auth_cache());
301 context->SetJobFactory(job_factory.Pass());
304 return context; 302 return context;
305 } 303 }
306 304
307 ChromeURLRequestContext* 305 ChromeURLRequestContext*
308 OffTheRecordProfileIOData::InitializeMediaRequestContext( 306 OffTheRecordProfileIOData::InitializeMediaRequestContext(
309 ChromeURLRequestContext* original_context, 307 ChromeURLRequestContext* original_context,
310 const std::string& app_id) const { 308 const std::string& app_id) const {
311 NOTREACHED(); 309 NOTREACHED();
312 return NULL; 310 return NULL;
313 } 311 }
314 312
315 ChromeURLRequestContext* 313 ChromeURLRequestContext*
316 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { 314 OffTheRecordProfileIOData::AcquireMediaRequestContext() const {
317 NOTREACHED(); 315 NOTREACHED();
318 return NULL; 316 return NULL;
319 } 317 }
320 318
321 ChromeURLRequestContext* 319 ChromeURLRequestContext*
322 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( 320 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
323 ChromeURLRequestContext* main_context, 321 ChromeURLRequestContext* main_context,
324 const std::string& app_id) const { 322 const std::string& app_id,
323 scoped_ptr<net::URLRequestJobFactory::Interceptor>
324 protocol_handler_interceptor) const {
325 // We create per-app contexts on demand, unlike the others above. 325 // We create per-app contexts on demand, unlike the others above.
326 ChromeURLRequestContext* app_request_context = 326 ChromeURLRequestContext* app_request_context =
327 InitializeAppRequestContext(main_context, app_id); 327 InitializeAppRequestContext(main_context, app_id,
328 protocol_handler_interceptor.Pass());
328 DCHECK(app_request_context); 329 DCHECK(app_request_context);
329 return app_request_context; 330 return app_request_context;
330 } 331 }
331 332
332 ChromeURLRequestContext* 333 ChromeURLRequestContext*
333 OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext( 334 OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext(
334 ChromeURLRequestContext* app_context, 335 ChromeURLRequestContext* app_context,
335 const std::string& app_id) const { 336 const std::string& app_id) const {
336 NOTREACHED(); 337 NOTREACHED();
337 return NULL; 338 return NULL;
338 } 339 }
339 340
340 void OffTheRecordProfileIOData::CreateFtpProtocolHandler(
341 net::URLRequestJobFactory* job_factory,
342 net::FtpAuthCache* ftp_auth_cache) const {
343 #if !defined(DISABLE_FTP_SUPPORT)
344 job_factory->SetProtocolHandler(
345 chrome::kFtpScheme,
346 new net::FtpProtocolHandler(ftp_factory_.get(), ftp_auth_cache));
347 #endif // !defined(DISABLE_FTP_SUPPORT)
348 }
349
350 chrome_browser_net::LoadTimeStats* OffTheRecordProfileIOData::GetLoadTimeStats( 341 chrome_browser_net::LoadTimeStats* OffTheRecordProfileIOData::GetLoadTimeStats(
351 IOThread::Globals* io_thread_globals) const { 342 IOThread::Globals* io_thread_globals) const {
352 return NULL; 343 return NULL;
353 } 344 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_io_data.h ('k') | chrome/browser/profiles/profile_impl_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698