This source file includes following definitions.
- initialized_
- GetResourceContext
- GetResourceContextNoInit
- CreateMainRequestContextGetter
- GetExtensionsRequestContextGetter
- GetIsolatedAppRequestContextGetter
- CreateIsolatedAppRequestContextGetter
- LazyInitialize
- InitializeInternal
- InitializeExtensionsRequestContext
- InitializeAppRequestContext
- InitializeMediaRequestContext
- AcquireMediaRequestContext
- AcquireIsolatedAppRequestContext
- AcquireIsolatedMediaRequestContext
#include "chrome/browser/profiles/off_the_record_profile_io_data.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/threading/worker_pool.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/about_protocol_handler.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/resource_context.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties_impl.h"
#include "net/ssl/default_server_bound_cert_store.h"
#include "net/ssl/server_bound_cert_service.h"
#include "net/url_request/protocol_intercept_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "webkit/browser/database/database_tracker.h"
using content::BrowserThread;
OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
: io_data_(new OffTheRecordProfileIOData(profile->GetProfileType())),
profile_(profile),
initialized_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(profile);
}
OffTheRecordProfileIOData::Handle::~Handle() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
io_data_->ShutdownOnUIThread();
}
content::ResourceContext*
OffTheRecordProfileIOData::Handle::GetResourceContext() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
LazyInitialize();
return GetResourceContextNoInit();
}
content::ResourceContext*
OffTheRecordProfileIOData::Handle::GetResourceContextNoInit() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return io_data_->GetResourceContext();
}
scoped_refptr<ChromeURLRequestContextGetter>
OffTheRecordProfileIOData::Handle::CreateMainRequestContextGetter(
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) const {
#if !defined(OS_CHROMEOS)
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
#endif
LazyInitialize();
DCHECK(!main_request_context_getter_.get());
main_request_context_getter_ = ChromeURLRequestContextGetter::Create(
profile_, io_data_, protocol_handlers, protocol_interceptors.Pass());
return main_request_context_getter_;
}
scoped_refptr<ChromeURLRequestContextGetter>
OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
LazyInitialize();
if (!extensions_request_context_getter_.get()) {
extensions_request_context_getter_ =
ChromeURLRequestContextGetter::CreateForExtensions(profile_, io_data_);
}
return extensions_request_context_getter_;
}
scoped_refptr<ChromeURLRequestContextGetter>
OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter(
const base::FilePath& partition_path,
bool in_memory) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!partition_path.empty());
LazyInitialize();
StoragePartitionDescriptor descriptor(partition_path, in_memory);
ChromeURLRequestContextGetterMap::iterator iter =
app_request_context_getter_map_.find(descriptor);
CHECK(iter != app_request_context_getter_map_.end());
return iter->second;
}
scoped_refptr<ChromeURLRequestContextGetter>
OffTheRecordProfileIOData::Handle::CreateIsolatedAppRequestContextGetter(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!partition_path.empty());
LazyInitialize();
StoragePartitionDescriptor descriptor(partition_path, in_memory);
DCHECK_EQ(app_request_context_getter_map_.count(descriptor), 0u);
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor(
ProtocolHandlerRegistryFactory::GetForProfile(profile_)->
CreateJobInterceptorFactory());
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateForIsolatedApp(
profile_,
io_data_,
descriptor,
protocol_handler_interceptor.Pass(),
protocol_handlers,
protocol_interceptors.Pass());
app_request_context_getter_map_[descriptor] = context;
return context;
}
void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
if (initialized_)
return;
initialized_ = true;
#if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
profile_->GetPrefs());
io_data_->safe_browsing_enabled()->MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
#endif
io_data_->InitializeOnUIThread(profile_);
}
OffTheRecordProfileIOData::OffTheRecordProfileIOData(
Profile::ProfileType profile_type)
: ProfileIOData(profile_type) {}
OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {
DestroyResourceContext();
}
void OffTheRecordProfileIOData::InitializeInternal(
ProfileParams* profile_params,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) const {
ChromeURLRequestContext* main_context = main_request_context();
IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
ApplyProfileParamsToContext(main_context);
main_context->set_transport_security_state(transport_security_state());
main_context->set_net_log(io_thread->net_log());
main_context->set_network_delegate(network_delegate());
main_context->set_host_resolver(
io_thread_globals->host_resolver.get());
main_context->set_http_auth_handler_factory(
io_thread_globals->http_auth_handler_factory.get());
main_context->set_fraudulent_certificate_reporter(
fraudulent_certificate_reporter());
main_context->set_proxy_service(proxy_service());
main_context->set_throttler_manager(
io_thread_globals->throttler_manager.get());
set_http_server_properties(
scoped_ptr<net::HttpServerProperties>(
new net::HttpServerPropertiesImpl()));
main_context->set_http_server_properties(http_server_properties());
net::ServerBoundCertService* server_bound_cert_service =
new net::ServerBoundCertService(
new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true));
set_server_bound_cert_service(server_bound_cert_service);
main_context->set_server_bound_cert_service(server_bound_cert_service);
using content::CookieStoreConfig;
main_context->set_cookie_store(
CreateCookieStore(CookieStoreConfig(
base::FilePath(),
CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
NULL,
profile_params->cookie_monster_delegate.get())));
net::HttpCache::BackendFactory* main_backend =
net::HttpCache::DefaultBackend::InMemory(0);
net::HttpNetworkSession::Params network_session_params;
PopulateNetworkSessionParams(profile_params, &network_session_params);
net::HttpCache* cache = new net::HttpCache(
network_session_params, main_backend);
main_http_factory_.reset(cache);
main_context->set_http_transaction_factory(cache);
#if !defined(DISABLE_FTP_SUPPORT)
ftp_factory_.reset(
new net::FtpNetworkLayer(main_context->host_resolver()));
#endif
scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
main_job_factory_ = SetUpJobFactoryDefaults(
main_job_factory.Pass(),
protocol_interceptors.Pass(),
profile_params->protocol_handler_interceptor.Pass(),
network_delegate(),
ftp_factory_.get());
main_context->set_job_factory(main_job_factory_.get());
#if defined(ENABLE_EXTENSIONS)
InitializeExtensionsRequestContext(profile_params);
#endif
}
void OffTheRecordProfileIOData::
InitializeExtensionsRequestContext(ProfileParams* profile_params) const {
ChromeURLRequestContext* extensions_context = extensions_request_context();
IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
ApplyProfileParamsToContext(extensions_context);
extensions_context->set_transport_security_state(transport_security_state());
extensions_context->set_net_log(io_thread->net_log());
extensions_context->set_throttler_manager(
io_thread_globals->throttler_manager.get());
net::CookieMonster* extensions_cookie_store =
content::CreateCookieStore(content::CookieStoreConfig())->
GetCookieMonster();
const char* schemes[] = {content::kChromeDevToolsScheme,
extensions::kExtensionScheme};
extensions_cookie_store->SetCookieableSchemes(schemes, 2);
extensions_context->set_cookie_store(extensions_cookie_store);
scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory(
new net::URLRequestJobFactoryImpl());
extensions_job_factory_ = SetUpJobFactoryDefaults(
extensions_job_factory.Pass(),
content::ProtocolHandlerScopedVector(),
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(),
NULL,
ftp_factory_.get());
extensions_context->set_job_factory(extensions_job_factory_.get());
}
ChromeURLRequestContext* OffTheRecordProfileIOData::InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) const {
AppRequestContext* context = new AppRequestContext();
context->CopyFrom(main_context);
context->SetCookieStore(
content::CreateCookieStore(content::CookieStoreConfig()));
net::HttpCache::BackendFactory* app_backend =
net::HttpCache::DefaultBackend::InMemory(0);
net::HttpNetworkSession* main_network_session =
main_http_factory_->GetSession();
scoped_ptr<net::HttpTransactionFactory> app_http_cache(
new net::HttpCache(main_network_session, app_backend));
context->SetHttpTransactionFactory(app_http_cache.Pass());
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(job_factory.get(), protocol_handlers);
scoped_ptr<net::URLRequestJobFactory> top_job_factory;
top_job_factory = SetUpJobFactoryDefaults(job_factory.Pass(),
protocol_interceptors.Pass(),
protocol_handler_interceptor.Pass(),
network_delegate(),
ftp_factory_.get());
context->SetJobFactory(top_job_factory.Pass());
return context;
}
ChromeURLRequestContext*
OffTheRecordProfileIOData::InitializeMediaRequestContext(
ChromeURLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor) const {
NOTREACHED();
return NULL;
}
ChromeURLRequestContext*
OffTheRecordProfileIOData::AcquireMediaRequestContext() const {
NOTREACHED();
return NULL;
}
ChromeURLRequestContext*
OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) const {
ChromeURLRequestContext* app_request_context =
InitializeAppRequestContext(main_context,
partition_descriptor,
protocol_handler_interceptor.Pass(),
protocol_handlers,
protocol_interceptors.Pass());
DCHECK(app_request_context);
return app_request_context;
}
ChromeURLRequestContext*
OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext(
ChromeURLRequestContext* app_context,
const StoragePartitionDescriptor& partition_descriptor) const {
NOTREACHED();
return NULL;
}