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

Unified Diff: chrome/browser/custom_handlers/protocol_handler_registry.h

Issue 11669012: Convert ProtocolHandlerRegistry::Interceptor to a net::URLRequestJobFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jhawkins' comments Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/protocol_handler_registry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/custom_handlers/protocol_handler_registry.h
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h
index e8ae9137b9a29e9ca8f90b36f4626aebff609cf7..e1331c16332e2f888935e0d27834eb12bb7c1826 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.h
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -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_;
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/protocol_handler_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698