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

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

Issue 11308362: Add StoragePartition's ProtocolHandlers at URLRequestContext construction time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove incorrect comment Created 8 years 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/profile_io_data.h" 5 #include "chrome/browser/profiles/profile_io_data.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 params->notification_service = 166 params->notification_service =
167 DesktopNotificationServiceFactory::GetForProfile(profile); 167 DesktopNotificationServiceFactory::GetForProfile(profile);
168 #endif 168 #endif
169 169
170 ProtocolHandlerRegistry* protocol_handler_registry = 170 ProtocolHandlerRegistry* protocol_handler_registry =
171 ProtocolHandlerRegistryFactory::GetForProfile(profile); 171 ProtocolHandlerRegistryFactory::GetForProfile(profile);
172 DCHECK(protocol_handler_registry); 172 DCHECK(protocol_handler_registry);
173 173
174 // The profile instance is only available here in the InitializeOnUIThread 174 // The profile instance is only available here in the InitializeOnUIThread
175 // method, so we create the url interceptor here, then save it for 175 // method, so we create the url interceptor here, then save it for
176 // later delivery to the job factory in LazyInitialize. 176 // later delivery to the job factory in LazyInitialize.
awong 2012/12/13 01:06:15 Is LazyInitialize() still the right name here?
pauljensen 2012/12/13 17:58:44 I changed it to Init().
177 params->protocol_handler_interceptor.reset( 177 params->protocol_handler_interceptor.reset(
178 protocol_handler_registry->CreateURLInterceptor()); 178 protocol_handler_registry->CreateURLInterceptor());
179 179
180 ChromeProxyConfigService* proxy_config_service = 180 ChromeProxyConfigService* proxy_config_service =
181 ProxyServiceFactory::CreateProxyConfigService(true); 181 ProxyServiceFactory::CreateProxyConfigService(true);
182 params->proxy_config_service.reset(proxy_config_service); 182 params->proxy_config_service.reset(proxy_config_service);
183 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( 183 profile->GetProxyConfigTracker()->SetChromeProxyConfigService(
184 proxy_config_service); 184 proxy_config_service);
185 params->profile = profile; 185 params->profile = profile;
186 profile_params_.reset(params.release()); 186 profile_params_.reset(params.release());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 return IsHandledProtocol(url.scheme()); 359 return IsHandledProtocol(url.scheme());
360 } 360 }
361 361
362 content::ResourceContext* ProfileIOData::GetResourceContext() const { 362 content::ResourceContext* ProfileIOData::GetResourceContext() const {
363 return resource_context_.get(); 363 return resource_context_.get();
364 } 364 }
365 365
366 ChromeURLDataManagerBackend* 366 ChromeURLDataManagerBackend*
367 ProfileIOData::GetChromeURLDataManagerBackend() const { 367 ProfileIOData::GetChromeURLDataManagerBackend() const {
368 LazyInitialize(); 368 CHECK(initialized_);
awong 2012/12/13 01:06:15 These should all either DCHECK(initialized_) or CH
pauljensen 2012/12/13 17:58:44 Done.
369 return chrome_url_data_manager_backend_.get(); 369 return chrome_url_data_manager_backend_.get();
370 } 370 }
371 371
372 ChromeURLRequestContext* 372 ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const {
373 ProfileIOData::GetMainRequestContext() const { 373 CHECK(initialized_);
374 LazyInitialize();
375 return main_request_context_.get(); 374 return main_request_context_.get();
376 } 375 }
377 376
378 ChromeURLRequestContext* 377 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const {
379 ProfileIOData::GetMediaRequestContext() const { 378 DCHECK(initialized_);
380 LazyInitialize(); 379 ChromeURLRequestContext* context = AcquireMediaRequestContext();
381 ChromeURLRequestContext* context =
382 AcquireMediaRequestContext();
383 DCHECK(context); 380 DCHECK(context);
384 return context; 381 return context;
385 } 382 }
386 383
387 ChromeURLRequestContext* 384 ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const {
388 ProfileIOData::GetExtensionsRequestContext() const { 385 CHECK(initialized_);
389 LazyInitialize();
390 return extensions_request_context_.get(); 386 return extensions_request_context_.get();
391 } 387 }
392 388
393 ChromeURLRequestContext* 389 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext(
394 ProfileIOData::GetIsolatedAppRequestContext(
395 ChromeURLRequestContext* main_context, 390 ChromeURLRequestContext* main_context,
396 const StoragePartitionDescriptor& partition_descriptor, 391 const StoragePartitionDescriptor& partition_descriptor,
397 scoped_ptr<net::URLRequestJobFactory::Interceptor> 392 scoped_ptr<net::URLRequestJobFactory::Interceptor>
398 protocol_handler_interceptor) const { 393 protocol_handler_interceptor,
399 LazyInitialize(); 394 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
395 blob_protocol_handler,
396 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
397 file_system_protocol_handler,
398 scoped_ptr<net::URLRequestJobFactory::Interceptor>
399 developer_protocol_handler) const {
400 DCHECK(initialized_);
400 ChromeURLRequestContext* context = NULL; 401 ChromeURLRequestContext* context = NULL;
401 if (ContainsKey(app_request_context_map_, partition_descriptor)) { 402 if (ContainsKey(app_request_context_map_, partition_descriptor)) {
402 context = app_request_context_map_[partition_descriptor]; 403 context = app_request_context_map_[partition_descriptor];
403 } else { 404 } else {
404 context = AcquireIsolatedAppRequestContext( 405 context = AcquireIsolatedAppRequestContext(
405 main_context, partition_descriptor, 406 main_context, partition_descriptor, protocol_handler_interceptor.Pass(),
406 protocol_handler_interceptor.Pass()); 407 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(),
408 developer_protocol_handler.Pass());
407 app_request_context_map_[partition_descriptor] = context; 409 app_request_context_map_[partition_descriptor] = context;
408 } 410 }
409 DCHECK(context); 411 DCHECK(context);
410 return context; 412 return context;
411 } 413 }
412 414
413 ChromeURLRequestContext* 415 ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext(
414 ProfileIOData::GetIsolatedMediaRequestContext(
415 ChromeURLRequestContext* app_context, 416 ChromeURLRequestContext* app_context,
416 const StoragePartitionDescriptor& partition_descriptor) const { 417 const StoragePartitionDescriptor& partition_descriptor) const {
417 LazyInitialize(); 418 DCHECK(initialized_);
418 ChromeURLRequestContext* context = NULL; 419 ChromeURLRequestContext* context = NULL;
419 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { 420 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) {
420 context = isolated_media_request_context_map_[partition_descriptor]; 421 context = isolated_media_request_context_map_[partition_descriptor];
421 } else { 422 } else {
422 context = AcquireIsolatedMediaRequestContext(app_context, 423 context = AcquireIsolatedMediaRequestContext(app_context,
423 partition_descriptor); 424 partition_descriptor);
424 isolated_media_request_context_map_[partition_descriptor] = context; 425 isolated_media_request_context_map_[partition_descriptor] = context;
425 } 426 }
426 DCHECK(context); 427 DCHECK(context);
427 return context; 428 return context;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 482
482 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) 483 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data)
483 : io_data_(io_data), 484 : io_data_(io_data),
484 host_resolver_(NULL), 485 host_resolver_(NULL),
485 request_context_(NULL) { 486 request_context_(NULL) {
486 DCHECK(io_data); 487 DCHECK(io_data);
487 } 488 }
488 489
489 ProfileIOData::ResourceContext::~ResourceContext() {} 490 ProfileIOData::ResourceContext::~ResourceContext() {}
490 491
491 void ProfileIOData::ResourceContext::EnsureInitialized() {
492 io_data_->LazyInitialize();
493 }
494
495 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { 492 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() {
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
497 EnsureInitialized(); 494 CHECK(io_data_->initialized_);
498 return host_resolver_; 495 return host_resolver_;
499 } 496 }
500 497
501 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { 498 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() {
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
503 EnsureInitialized(); 500 CHECK(io_data_->initialized_);
504 return request_context_; 501 return request_context_;
505 } 502 }
506 503
507 // static 504 // static
508 std::string ProfileIOData::GetSSLSessionCacheShard() { 505 std::string ProfileIOData::GetSSLSessionCacheShard() {
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
510 // The SSL session cache is partitioned by setting a string. This returns a 507 // The SSL session cache is partitioned by setting a string. This returns a
511 // unique string to partition the SSL session cache. Each time we create a 508 // unique string to partition the SSL session cache. Each time we create a
512 // new profile, we'll get a fresh SSL session cache which is separate from 509 // new profile, we'll get a fresh SSL session cache which is separate from
513 // the other profiles. 510 // the other profiles.
514 static unsigned ssl_session_cache_instance = 0; 511 static unsigned ssl_session_cache_instance = 0;
515 return StringPrintf("profile/%u", ssl_session_cache_instance++); 512 return StringPrintf("profile/%u", ssl_session_cache_instance++);
516 } 513 }
517 514
518 void ProfileIOData::LazyInitialize() const { 515 void ProfileIOData::Init(
516 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
517 blob_protocol_handler,
518 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
519 file_system_protocol_handler,
520 scoped_ptr<net::URLRequestJobFactory::Interceptor>
521 developer_protocol_handler) const {
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
520 if (initialized_) 523 DCHECK(!initialized_);
521 return;
522 524
523 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. 525 // TODO(jhawkins): Remove once crbug.com/102004 is fixed.
524 CHECK(initialized_on_UI_thread_); 526 CHECK(initialized_on_UI_thread_);
525 527
526 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. 528 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed.
527 CHECK(profile_params_.get()); 529 CHECK(profile_params_.get());
528 530
529 IOThread* const io_thread = profile_params_->io_thread; 531 IOThread* const io_thread = profile_params_->io_thread;
530 IOThread::Globals* const io_thread_globals = io_thread->globals(); 532 IOThread::Globals* const io_thread_globals = io_thread->globals();
531 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 533 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 extension_info_map_ = profile_params_->extension_info_map; 585 extension_info_map_ = profile_params_->extension_info_map;
584 586
585 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); 587 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get();
586 resource_context_->request_context_ = main_request_context_.get(); 588 resource_context_->request_context_ = main_request_context_.get();
587 589
588 if (profile_params_->resource_prefetch_predictor_observer_.get()) { 590 if (profile_params_->resource_prefetch_predictor_observer_.get()) {
589 resource_prefetch_predictor_observer_.reset( 591 resource_prefetch_predictor_observer_.reset(
590 profile_params_->resource_prefetch_predictor_observer_.release()); 592 profile_params_->resource_prefetch_predictor_observer_.release());
591 } 593 }
592 594
593 LazyInitializeInternal(profile_params_.get()); 595 InitializeInternal(profile_params_.get(),
596 blob_protocol_handler.Pass(),
597 file_system_protocol_handler.Pass(),
598 developer_protocol_handler.Pass());
594 599
595 profile_params_.reset(); 600 profile_params_.reset();
596 initialized_ = true; 601 initialized_ = true;
597 } 602 }
598 603
599 void ProfileIOData::ApplyProfileParamsToContext( 604 void ProfileIOData::ApplyProfileParamsToContext(
600 ChromeURLRequestContext* context) const { 605 ChromeURLRequestContext* context) const {
601 context->set_is_incognito(is_incognito()); 606 context->set_is_incognito(is_incognito());
602 context->set_http_user_agent_settings( 607 context->set_http_user_agent_settings(
603 chrome_http_user_agent_settings_.get()); 608 chrome_http_user_agent_settings_.get());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 void ProfileIOData::SetCookieSettingsForTesting( 733 void ProfileIOData::SetCookieSettingsForTesting(
729 CookieSettings* cookie_settings) { 734 CookieSettings* cookie_settings) {
730 DCHECK(!cookie_settings_.get()); 735 DCHECK(!cookie_settings_.get());
731 cookie_settings_ = cookie_settings; 736 cookie_settings_ = cookie_settings;
732 } 737 }
733 738
734 void ProfileIOData::set_signin_names_for_testing( 739 void ProfileIOData::set_signin_names_for_testing(
735 SigninNamesOnIOThread* signin_names) { 740 SigninNamesOnIOThread* signin_names) {
736 signin_names_.reset(signin_names); 741 signin_names_.reset(signin_names);
737 } 742 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698