Convert ProtocolHandlerRegistry::Interceptor to a net::URLRequestJobFactory.

BUG=161536


Review URL: https://chromiumcodereview.appspot.com/11669012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175524 0039d316-1c4b-4281-b951-d872f2087c98
parent 96e51036
......@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/sequenced_task_runner_helpers.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
......@@ -84,6 +85,57 @@ class ProtocolHandlerRegistry : public ProfileKeyedService {
ProtocolHandlerRegistry* registry);
};
// Forward declaration of the internal implementation class.
class IOThreadDelegate;
// JobInterceptorFactory intercepts URLRequestJob creation for URLRequests the
// ProtocolHandlerRegistry is registered to handle. When no handler is
// registered, the URLRequest is passed along to the chained
// URLRequestJobFactory (set with |JobInterceptorFactory::Chain|).
// JobInterceptorFactory's are created via
// |ProtocolHandlerRegistry::CreateJobInterceptorFactory|.
class JobInterceptorFactory : public net::URLRequestJobFactory {
public:
// |io_thread_delegate| is used to perform actual job creation work.
explicit JobInterceptorFactory(IOThreadDelegate* io_thread_delegate);
virtual ~JobInterceptorFactory();
// |job_factory| is set as the URLRequestJobFactory where requests are
// forwarded if JobInterceptorFactory decides to pass on them.
void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory);
// URLRequestJobFactory implementation.
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE;
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithInterceptor(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
private:
// When JobInterceptorFactory decides to pass on particular requests,
// they're forwarded to the chained URLRequestJobFactory, |job_factory_|.
scoped_ptr<URLRequestJobFactory> job_factory_;
// |io_thread_delegate_| performs the actual job creation decisions by
// mirroring the ProtocolHandlerRegistry on the IO thread.
scoped_refptr<IOThreadDelegate> io_thread_delegate_;
DISALLOW_COPY_AND_ASSIGN(JobInterceptorFactory);
};
typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap;
typedef std::vector<ProtocolHandler> ProtocolHandlerList;
typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap;
......@@ -93,10 +145,9 @@ class ProtocolHandlerRegistry : public ProfileKeyedService {
ProtocolHandlerRegistry(Profile* profile, Delegate* delegate);
virtual ~ProtocolHandlerRegistry();
// Returns a net::URLRequestJobFactory::Interceptor suitable
// for use on the IO thread, but is initialized on the UI thread.
// Callers assume responsibility for deleting this object.
net::URLRequestJobFactory::Interceptor* CreateURLInterceptor();
// Returns a net::URLRequestJobFactory suitable for use on the IO thread, but
// is initialized on the UI thread.
scoped_ptr<JobInterceptorFactory> CreateJobInterceptorFactory();
// Called when a site tries to register as a protocol handler. If the request
// can be handled silently by the registry - either to ignore the request
......@@ -212,10 +263,6 @@ class ProtocolHandlerRegistry : public ProfileKeyedService {
friend class ProtocolHandlerRegistryTest;
friend class RegisterProtocolHandlerBrowserTest;
// Forward declaration of the internal implementation classes.
class Core;
class URLInterceptor;
// Puts the given handler at the top of the list of handlers for its
// protocol.
void PromoteHandler(const ProtocolHandler& handler);
......@@ -287,7 +334,7 @@ class ProtocolHandlerRegistry : public ProfileKeyedService {
// Copy of registry data for use on the IO thread. Changes to the registry
// are posted to the IO thread where updates are applied to this object.
scoped_refptr<Core> core_;
scoped_refptr<IOThreadDelegate> io_thread_delegate_;
DefaultClientObserverList default_client_observers_;
......
......@@ -30,18 +30,19 @@ namespace {
void AssertInterceptedIO(
const GURL& url,
net::URLRequestJobFactory::Interceptor* interceptor) {
net::URLRequestJobFactory* interceptor) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
net::URLRequestContext context;
net::URLRequest request(url, NULL, &context);
scoped_refptr<net::URLRequestJob> job = interceptor->MaybeIntercept(
&request, context.network_delegate());
scoped_refptr<net::URLRequestJob> job =
interceptor->MaybeCreateJobWithProtocolHandler(
url.scheme(), &request, context.network_delegate());
ASSERT_TRUE(job.get() != NULL);
}
void AssertIntercepted(
const GURL& url,
net::URLRequestJobFactory::Interceptor* interceptor) {
net::URLRequestJobFactory* interceptor) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
......@@ -51,18 +52,64 @@ void AssertIntercepted(
MessageLoop::current()->RunUntilIdle();
}
// FakeURLRequestJobFactory returns NULL for all job creation requests and false
// for all IsHandled*() requests. FakeURLRequestJobFactory can be chained to
// ProtocolHandlerRegistry::JobInterceptorFactory so the result of
// MaybeCreateJobWithProtocolHandler() indicates whether the
// ProtocolHandlerRegistry properly handled a job creation request.
class FakeURLRequestJobFactory : public net::URLRequestJobFactory {
// net::URLRequestJobFactory implementation:
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE {
return false;
}
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE {
}
virtual net::URLRequestJob* MaybeCreateJobWithInterceptor(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE {
return false;
}
virtual bool IsHandledURL(const GURL& url) const OVERRIDE {
return false;
}
};
void AssertWillHandleIO(
const std::string& scheme,
bool expected,
net::URLRequestJobFactory::Interceptor* interceptor) {
ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ASSERT_EQ(expected, interceptor->WillHandleProtocol(scheme));
interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>(
new FakeURLRequestJobFactory()));
ASSERT_EQ(expected, interceptor->IsHandledProtocol(scheme));
interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>(NULL));
}
void AssertWillHandle(
const std::string& scheme,
bool expected,
net::URLRequestJobFactory::Interceptor* interceptor) {
ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
......@@ -754,8 +801,8 @@ TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) {
registry()->OnAcceptRegisterProtocolHandler(ph1);
GURL url("mailto:someone@something.com");
scoped_ptr<net::URLRequestJobFactory::Interceptor> interceptor(
registry()->CreateURLInterceptor());
scoped_ptr<net::URLRequestJobFactory> interceptor(
registry()->CreateJobInterceptorFactory());
AssertIntercepted(url, interceptor.get());
}
......@@ -765,8 +812,8 @@ TEST_F(ProtocolHandlerRegistryTest,
ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1");
registry()->OnAcceptRegisterProtocolHandler(ph1);
scoped_ptr<net::URLRequestJobFactory::Interceptor> interceptor(
registry()->CreateURLInterceptor());
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> interceptor(
registry()->CreateJobInterceptorFactory());
AssertWillHandle(scheme, true, interceptor.get());
}
......@@ -812,8 +859,8 @@ TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestClearDefaultGetsPropagatedToIO) {
registry()->OnAcceptRegisterProtocolHandler(ph1);
registry()->ClearDefault(scheme);
scoped_ptr<net::URLRequestJobFactory::Interceptor> interceptor(
registry()->CreateURLInterceptor());
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> interceptor(
registry()->CreateJobInterceptorFactory());
AssertWillHandle(scheme, false, interceptor.get());
}
......@@ -822,8 +869,8 @@ TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) {
ProtocolHandler ph1 = CreateProtocolHandler(mailto, "MailtoHandler");
registry()->OnAcceptRegisterProtocolHandler(ph1);
scoped_ptr<net::URLRequestJobFactory::Interceptor> interceptor(
registry()->CreateURLInterceptor());
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> interceptor(
registry()->CreateJobInterceptorFactory());
AssertWillHandle(mailto, true, interceptor.get());
registry()->Disable();
AssertWillHandle(mailto, false, interceptor.get());
......
......@@ -68,11 +68,12 @@ class FactoryForExtensions : public ChromeURLRequestContextFactory {
// Factory that creates the ChromeURLRequestContext for a given isolated app.
class FactoryForIsolatedApp : public ChromeURLRequestContextFactory {
public:
FactoryForIsolatedApp(const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
ChromeURLRequestContextGetter* main_context,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
protocol_handler_interceptor)
FactoryForIsolatedApp(
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
ChromeURLRequestContextGetter* main_context,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor)
: profile_io_data_(profile_io_data),
partition_descriptor_(partition_descriptor),
main_request_context_getter_(main_context),
......@@ -94,7 +95,7 @@ class FactoryForIsolatedApp : public ChromeURLRequestContextFactory {
const StoragePartitionDescriptor partition_descriptor_;
scoped_refptr<ChromeURLRequestContextGetter>
main_request_context_getter_;
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor_;
};
......@@ -211,7 +212,7 @@ ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
Profile* profile,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) {
DCHECK(!profile->IsOffTheRecord());
ChromeURLRequestContextGetter* main_context =
......@@ -258,7 +259,7 @@ ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
Profile* profile,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) {
DCHECK(profile->IsOffTheRecord());
ChromeURLRequestContextGetter* main_context =
......
......@@ -8,6 +8,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h"
......@@ -132,7 +133,7 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter {
Profile* profile,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor);
// Create an instance for an original profile for media with isolated
......@@ -159,7 +160,7 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter {
Profile* profile,
const ProfileIOData* profile_io_data,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor);
private:
......
......@@ -119,10 +119,10 @@ OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter(
if (iter != app_request_context_getter_map_.end())
return iter->second;
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor(
ProtocolHandlerRegistryFactory::GetForProfile(profile_)->
CreateURLInterceptor());
CreateJobInterceptorFactory());
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp(
profile_, io_data_, descriptor,
......@@ -218,13 +218,12 @@ void OffTheRecordProfileIOData::LazyInitializeInternal(
scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
SetUpJobFactoryDefaults(
main_job_factory.get(),
main_job_factory_ = SetUpJobFactoryDefaults(
main_job_factory.Pass(),
profile_params->protocol_handler_interceptor.Pass(),
network_delegate(),
main_context->ftp_transaction_factory(),
main_context->ftp_auth_cache());
main_job_factory_ = main_job_factory.Pass();
main_context->set_job_factory(main_job_factory_.get());
#if defined(ENABLE_EXTENSIONS)
......@@ -271,13 +270,12 @@ void OffTheRecordProfileIOData::
// job_factory::IsHandledProtocol return true, which prevents attempts to
// handle the protocol externally. We pass NULL in to
// SetUpJobFactoryDefaults() to get this effect.
SetUpJobFactoryDefaults(
extensions_job_factory.get(),
scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL),
extensions_job_factory_ = SetUpJobFactoryDefaults(
extensions_job_factory.Pass(),
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(NULL),
NULL,
extensions_context->ftp_transaction_factory(),
extensions_context->ftp_auth_cache());
extensions_job_factory_ = extensions_job_factory.Pass();
extensions_context->set_job_factory(extensions_job_factory_.get());
}
......@@ -285,7 +283,7 @@ ChromeURLRequestContext*
OffTheRecordProfileIOData::InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const {
AppRequestContext* context = new AppRequestContext(load_time_stats());
......@@ -309,12 +307,13 @@ OffTheRecordProfileIOData::InitializeAppRequestContext(
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
SetUpJobFactoryDefaults(job_factory.get(),
protocol_handler_interceptor.Pass(),
network_delegate(),
context->ftp_transaction_factory(),
context->ftp_auth_cache());
context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>());
scoped_ptr<net::URLRequestJobFactory> top_job_factory;
top_job_factory = SetUpJobFactoryDefaults(job_factory.Pass(),
protocol_handler_interceptor.Pass(),
network_delegate(),
context->ftp_transaction_factory(),
context->ftp_auth_cache());
context->SetJobFactory(top_job_factory.Pass());
return context;
}
......@@ -336,7 +335,7 @@ ChromeURLRequestContext*
OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const {
// We create per-app contexts on demand, unlike the others above.
ChromeURLRequestContext* app_request_context =
......
......@@ -11,6 +11,7 @@
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
......@@ -102,7 +103,7 @@ class OffTheRecordProfileIOData : public ProfileIOData {
virtual ChromeURLRequestContext* InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE;
virtual ChromeURLRequestContext* InitializeMediaRequestContext(
ChromeURLRequestContext* original_context,
......@@ -113,7 +114,7 @@ class OffTheRecordProfileIOData : public ProfileIOData {
AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE;
virtual ChromeURLRequestContext*
AcquireIsolatedMediaRequestContext(
......
......@@ -202,10 +202,10 @@ ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter(
if (iter != app_request_context_getter_map_.end())
return iter->second;
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor(
ProtocolHandlerRegistryFactory::GetForProfile(profile_)->
CreateURLInterceptor());
CreateJobInterceptorFactory());
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
profile_, io_data_, descriptor,
......@@ -423,12 +423,12 @@ void ProfileImplIOData::LazyInitializeInternal(
scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
SetUpJobFactoryDefaults(main_job_factory.get(),
profile_params->protocol_handler_interceptor.Pass(),
network_delegate(),
main_context->ftp_transaction_factory(),
main_context->ftp_auth_cache());
main_job_factory_ = main_job_factory.Pass();
main_job_factory_ = SetUpJobFactoryDefaults(
main_job_factory.Pass(),
profile_params->protocol_handler_interceptor.Pass(),
network_delegate(),
main_context->ftp_transaction_factory(),
main_context->ftp_auth_cache());
main_context->set_job_factory(main_job_factory_.get());
#if defined(ENABLE_EXTENSIONS)
......@@ -482,13 +482,12 @@ void ProfileImplIOData::
// job_factory::IsHandledProtocol return true, which prevents attempts to
// handle the protocol externally. We pass NULL in to
// SetUpJobFactory() to get this effect.
SetUpJobFactoryDefaults(
extensions_job_factory.get(),
scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL),
extensions_job_factory_ = SetUpJobFactoryDefaults(
extensions_job_factory.Pass(),
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(NULL),
NULL,
extensions_context->ftp_transaction_factory(),
extensions_context->ftp_auth_cache());
extensions_job_factory_ = extensions_job_factory.Pass();
extensions_context->set_job_factory(extensions_job_factory_.get());
}
......@@ -496,7 +495,7 @@ ChromeURLRequestContext*
ProfileImplIOData::InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const {
// Copy most state from the main context.
AppRequestContext* context = new AppRequestContext(load_time_stats());
......@@ -560,20 +559,23 @@ ProfileImplIOData::InitializeAppRequestContext(
context->SetHttpTransactionFactory(
scoped_ptr<net::HttpTransactionFactory>(app_http_cache));
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
scoped_ptr<net::URLRequestJobFactory> top_job_factory;
// Overwrite the job factory that we inherit from the main context so
// that we can later provide our own handlers for storage related protocols.
// Install all the usual protocol handlers unless we are in a browser plugin
// guest process, in which case only web-safe schemes are allowed.
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
if (!partition_descriptor.in_memory) {
SetUpJobFactoryDefaults(
job_factory.get(), protocol_handler_interceptor.Pass(),
top_job_factory = SetUpJobFactoryDefaults(
job_factory.Pass(), protocol_handler_interceptor.Pass(),
network_delegate(),
context->ftp_transaction_factory(),
context->ftp_auth_cache());
} else {
top_job_factory = job_factory.PassAs<net::URLRequestJobFactory>();
}
context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>());
context->SetJobFactory(top_job_factory.Pass());
return context;
}
......@@ -636,7 +638,7 @@ ChromeURLRequestContext*
ProfileImplIOData::AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const {
// We create per-app contexts on demand, unlike the others above.
ChromeURLRequestContext* app_request_context =
......
......@@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/profiles/profile_io_data.h"
namespace chrome_browser_net {
......@@ -151,7 +152,7 @@ class ProfileImplIOData : public ProfileIOData {
virtual ChromeURLRequestContext* InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE;
virtual ChromeURLRequestContext* InitializeMediaRequestContext(
ChromeURLRequestContext* original_context,
......@@ -162,7 +163,7 @@ class ProfileImplIOData : public ProfileIOData {
AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE;
virtual ChromeURLRequestContext*
AcquireIsolatedMediaRequestContext(
......
......@@ -172,10 +172,10 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
DCHECK(protocol_handler_registry);
// The profile instance is only available here in the InitializeOnUIThread
// method, so we create the url interceptor here, then save it for
// method, so we create the url job factory here, then save it for
// later delivery to the job factory in LazyInitialize.
params->protocol_handler_interceptor.reset(
protocol_handler_registry->CreateURLInterceptor());
params->protocol_handler_interceptor =
protocol_handler_registry->CreateJobInterceptorFactory();
ChromeProxyConfigService* proxy_config_service =
ProxyServiceFactory::CreateProxyConfigService(true);
......@@ -394,7 +394,7 @@ ChromeURLRequestContext*
ProfileIOData::GetIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const {
LazyInitialize();
ChromeURLRequestContext* context = NULL;
......@@ -604,9 +604,9 @@ void ProfileIOData::ApplyProfileParamsToContext(
context->set_ssl_config_service(profile_params_->ssl_config_service);
}
void ProfileIOData::SetUpJobFactoryDefaults(
net::URLRequestJobFactoryImpl* job_factory,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
net::NetworkDelegate* network_delegate,
net::FtpTransactionFactory* ftp_transaction_factory,
......@@ -622,11 +622,6 @@ void ProfileIOData::SetUpJobFactoryDefaults(
CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(),
network_delegate));
DCHECK(set_protocol);
if (protocol_handler_interceptor.get()) {
job_factory->AddInterceptor(protocol_handler_interceptor.release());
}
set_protocol = job_factory->SetProtocolHandler(
extensions::kExtensionScheme,
CreateExtensionProtocolHandler(is_incognito(), GetExtensionInfoMap()));
......@@ -661,6 +656,14 @@ void ProfileIOData::SetUpJobFactoryDefaults(
new net::FtpProtocolHandler(ftp_transaction_factory,
ftp_auth_cache));
#endif // !defined(DISABLE_FTP_SUPPORT)
if (protocol_handler_interceptor) {
protocol_handler_interceptor->Chain(
job_factory.PassAs<net::URLRequestJobFactory>());
return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>();
} else {
return job_factory.PassAs<net::URLRequestJobFactory>();
}
}
void ProfileIOData::ShutdownOnUIThread() {
......
......@@ -15,6 +15,7 @@
#include "base/memory/weak_ptr.h"
#include "base/prefs/public/pref_member.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
......@@ -88,7 +89,7 @@ class ProfileIOData {
ChromeURLRequestContext* GetIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const;
ChromeURLRequestContext* GetIsolatedMediaRequestContext(
ChromeURLRequestContext* app_context,
......@@ -218,11 +219,11 @@ class ProfileIOData {
DesktopNotificationService* notification_service;
#endif
// This pointer exists only as a means of conveying a url interceptor
// This pointer exists only as a means of conveying a url job factory
// pointer from the protocol handler registry on the UI thread to the
// the URLRequestJobFactory on the IO thread. The consumer MUST take
// the URLRequestContext on the IO thread. The consumer MUST take
// ownership of the object by calling release() on this pointer.
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor;
// We need to initialize the ProxyConfigService from the UI thread
......@@ -242,9 +243,9 @@ class ProfileIOData {
void InitializeOnUIThread(Profile* profile);
void ApplyProfileParamsToContext(ChromeURLRequestContext* context) const;
void SetUpJobFactoryDefaults(
net::URLRequestJobFactoryImpl* job_factory,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<net::URLRequestJobFactory> SetUpJobFactoryDefaults(
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory,
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor,
net::NetworkDelegate* network_delegate,
net::FtpTransactionFactory* ftp_transaction_factory,
......@@ -352,7 +353,7 @@ class ProfileIOData {
virtual ChromeURLRequestContext* InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& details,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const = 0;
// Does an on-demand initialization of a media RequestContext for the given
......@@ -369,7 +370,7 @@ class ProfileIOData {
AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const = 0;
virtual ChromeURLRequestContext*
AcquireIsolatedMediaRequestContext(
......
......@@ -5,6 +5,7 @@
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
......@@ -93,7 +94,7 @@ class TestProfileIOData : public ProfileIOData {
virtual ChromeURLRequestContext* InitializeAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& details,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE {
NOTREACHED();
return NULL;
......@@ -113,7 +114,7 @@ class TestProfileIOData : public ProfileIOData {
AcquireIsolatedAppRequestContext(
ChromeURLRequestContext* main_context,
const StoragePartitionDescriptor& partition_descriptor,
scoped_ptr<net::URLRequestJobFactory::Interceptor>
scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
protocol_handler_interceptor) const OVERRIDE {
NOTREACHED();
return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment