This source file includes following definitions.
- protocol_interceptors_
- Create
- Create
- protocol_interceptors_
- Create
- app_context_getter_
- Create
- Create
- GetURLRequestContext
- GetNetworkTaskRunner
- Create
- CreateForMedia
- CreateForExtensions
- CreateForIsolatedApp
- CreateForIsolatedMedia
- CopyFrom
#include "chrome/browser/net/chrome_url_request_context.h"
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
#include "content/public/browser/browser_thread.h"
#include "net/cookies/cookie_store.h"
using content::BrowserThread;
class ChromeURLRequestContextFactory {
public:
ChromeURLRequestContextFactory() {}
virtual ~ChromeURLRequestContextFactory() {}
virtual ChromeURLRequestContext* Create() = 0;
protected:
DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory);
};
namespace {
class FactoryForMain : public ChromeURLRequestContextFactory {
public:
FactoryForMain(const ProfileIOData* profile_io_data,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors)
: profile_io_data_(profile_io_data),
protocol_interceptors_(protocol_interceptors.Pass()) {
std::swap(protocol_handlers_, *protocol_handlers);
}
virtual ChromeURLRequestContext* Create() OVERRIDE {
profile_io_data_->Init(&protocol_handlers_, protocol_interceptors_.Pass());
return profile_io_data_->GetMainRequestContext();
}
private:
const ProfileIOData* const profile_io_data_;
content::ProtocolHandlerMap protocol_handlers_;
content::ProtocolHandlerScopedVector protocol_interceptors_;
};
class FactoryForExtensions : public ChromeURLRequestContextFactory {
public:
explicit FactoryForExtensions(const ProfileIOData* profile_io_data)
: profile_io_data_(profile_io_data) {}
virtual ChromeURLRequestContext* Create() OVERRIDE {
return profile_io_data_->GetExtensionsRequestContext();
}
private:
const ProfileIOData* const profile_io_data_;
};
class FactoryForIsolatedApp : public ChromeURLRequestContextFactory {
public:
FactoryForIsolatedApp(
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
ChromeURLRequestContextGetter* main_context,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors)
: profile_io_data_(profile_io_data),
partition_descriptor_(partition_descriptor),
main_request_context_getter_(main_context),
protocol_handler_interceptor_(protocol_handler_interceptor.Pass()),
protocol_interceptors_(protocol_interceptors.Pass()) {
std::swap(protocol_handlers_, *protocol_handlers);
}
virtual ChromeURLRequestContext* Create() OVERRIDE {
return profile_io_data_->GetIsolatedAppRequestContext(
main_request_context_getter_->GetURLRequestContext(),
partition_descriptor_,
protocol_handler_interceptor_.Pass(),
&protocol_handlers_,
protocol_interceptors_.Pass());
}
private:
const ProfileIOData* const profile_io_data_;
const StoragePartitionDescriptor partition_descriptor_;
scoped_refptr<ChromeURLRequestContextGetter>
main_request_context_getter_;
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor_;
content::ProtocolHandlerMap protocol_handlers_;
content::ProtocolHandlerScopedVector protocol_interceptors_;
};
class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory {
public:
FactoryForIsolatedMedia(
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
ChromeURLRequestContextGetter* app_context)
: profile_io_data_(profile_io_data),
partition_descriptor_(partition_descriptor),
app_context_getter_(app_context) {}
virtual ChromeURLRequestContext* Create() OVERRIDE {
return profile_io_data_->GetIsolatedMediaRequestContext(
app_context_getter_->GetURLRequestContext(), partition_descriptor_);
}
private:
const ProfileIOData* const profile_io_data_;
const StoragePartitionDescriptor partition_descriptor_;
scoped_refptr<ChromeURLRequestContextGetter> app_context_getter_;
};
class FactoryForMedia : public ChromeURLRequestContextFactory {
public:
explicit FactoryForMedia(const ProfileIOData* profile_io_data)
: profile_io_data_(profile_io_data) {
}
virtual ChromeURLRequestContext* Create() OVERRIDE {
return profile_io_data_->GetMediaRequestContext();
}
private:
const ProfileIOData* const profile_io_data_;
};
}
ChromeURLRequestContextGetter::ChromeURLRequestContextGetter(
ChromeURLRequestContextFactory* factory)
: factory_(factory) {
DCHECK(factory);
}
ChromeURLRequestContextGetter::~ChromeURLRequestContextGetter() {}
ChromeURLRequestContext*
ChromeURLRequestContextGetter::GetURLRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!url_request_context_.get()) {
DCHECK(factory_.get());
url_request_context_ = factory_->Create()->GetWeakPtr();
factory_.reset();
}
CHECK(url_request_context_.get());
return url_request_context_.get();
}
scoped_refptr<base::SingleThreadTaskRunner>
ChromeURLRequestContextGetter::GetNetworkTaskRunner() const {
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
}
ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create(
Profile* profile,
const ProfileIOData* profile_io_data,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) {
return new ChromeURLRequestContextGetter(new FactoryForMain(
profile_io_data, protocol_handlers, protocol_interceptors.Pass()));
}
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateForMedia(
Profile* profile, const ProfileIOData* profile_io_data) {
return new ChromeURLRequestContextGetter(
new FactoryForMedia(profile_io_data));
}
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateForExtensions(
Profile* profile, const ProfileIOData* profile_io_data) {
return new ChromeURLRequestContextGetter(
new FactoryForExtensions(profile_io_data));
}
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateForIsolatedApp(
Profile* profile,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) {
ChromeURLRequestContextGetter* main_context =
static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext());
return new ChromeURLRequestContextGetter(
new FactoryForIsolatedApp(profile_io_data,
partition_descriptor,
main_context,
protocol_handler_interceptor.Pass(),
protocol_handlers,
protocol_interceptors.Pass()));
}
ChromeURLRequestContextGetter*
ChromeURLRequestContextGetter::CreateForIsolatedMedia(
Profile* profile,
ChromeURLRequestContextGetter* app_context,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor) {
return new ChromeURLRequestContextGetter(
new FactoryForIsolatedMedia(
profile_io_data, partition_descriptor, app_context));
}
ChromeURLRequestContext::ChromeURLRequestContext()
: weak_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
ChromeURLRequestContext::~ChromeURLRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) {
URLRequestContext::CopyFrom(other);
}