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

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

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge in MessageLoop conflict from upstream. Created 8 years, 6 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
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 18f01111eedac6b82a6b48dee98f77de9c5fbccb..d69c2aedbe98d69556c951ac7b93524df0b95b25 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.h
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -21,17 +21,18 @@
#include "content/public/browser/notification_service.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
+#include "net/url_request/url_request_job_factory.h"
// This is where handlers for protocols registered with
// navigator.registerProtocolHandler() are registered. Each Profile owns an
// instance of this class, which is initialized on browser start through
// Profile::InitRegisteredProtocolHandlers(), and they should be the only
// instances of this class.
+class ProtocolHandlerRegistry : public ProfileKeyedService {
-class ProtocolHandlerRegistry
- : public base::RefCountedThreadSafe<
- ProtocolHandlerRegistry, content::BrowserThread::DeleteOnIOThread> {
public:
+ // Provides notification of when the OS level user agent settings
+ // are changed.
class DefaultClientObserver
: public ShellIntegration::DefaultWebClientObserver {
public:
@@ -60,6 +61,10 @@ class ProtocolHandlerRegistry
DISALLOW_COPY_AND_ASSIGN(DefaultClientObserver);
};
+ // The tersely named |Delegate| class provides an interface for interacting
+ // asynchronously with the underlying OS for the purposes of registering
+ // Chrome as the default handler for specific protocols.
+ //
// TODO(koz): Refactor this to eliminate the unnecessary virtuals. All that
// should be needed is a way to ensure that the list of websafe protocols is
// updated.
@@ -85,6 +90,12 @@ class ProtocolHandlerRegistry
typedef std::vector<DefaultClientObserver*> DefaultClientObserverList;
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();
// 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
@@ -117,8 +128,10 @@ class ProtocolHandlerRegistry
// Returns true if this handler is the default handler for its protocol.
bool IsDefault(const ProtocolHandler& handler) const;
- // Loads a user's registered protocol handlers.
- void Load();
+ // Initializes default protocol settings and loads them from prefs.
+ // This method must be called to complete initialization of the
+ // registry after creation, and prior to use.
+ void InitProtocolSettings();
// Returns the offset in the list of handlers for a protocol of the default
// handler for that protocol.
@@ -156,10 +169,6 @@ class ProtocolHandlerRegistry
// Returns true if the protocol has a default protocol handler.
bool IsHandledProtocol(const std::string& scheme) const;
- // Returns true if the protocol has a default protocol handler.
- // Should be called only from the IO thread.
- bool IsHandledProtocolIO(const std::string& scheme) const;
-
// Removes the given protocol handler from the registry.
void RemoveHandler(const ProtocolHandler& handler);
@@ -170,10 +179,6 @@ class ProtocolHandlerRegistry
// exists.
const ProtocolHandler& GetHandlerFor(const std::string& scheme) const;
- // Creates a URL request job for the given request if there is a matching
- // protocol handler, returns NULL otherwise.
- net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const;
-
// Puts this registry in the enabled state - registered protocol handlers
// will handle requests.
void Enable();
@@ -184,7 +189,7 @@ class ProtocolHandlerRegistry
// This is called by the UI thread when the system is shutting down. This
// does finalization which must be done on the UI thread.
- void Finalize();
+ virtual void Shutdown() OVERRIDE;
// Registers the preferences that we store registered protocol handlers in.
static void RegisterPrefs(PrefService* prefService);
@@ -202,28 +207,14 @@ class ProtocolHandlerRegistry
friend class ProtocolHandlerRegistryTest;
friend class RegisterProtocolHandlerBrowserTest;
- ~ProtocolHandlerRegistry();
+ // Forward declaration of our 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);
- // Clears the default for the provided protocol.
- // Should be called only from the IO thread.
- void ClearDefaultIO(const std::string& scheme);
-
- // Makes this ProtocolHandler the default handler for its protocol.
- // Should be called only from the IO thread.
- void SetDefaultIO(const ProtocolHandler& handler);
-
- // Indicate that the registry has been enabled in the IO thread's copy of the
- // data.
- void EnableIO() { enabled_io_ = true; }
-
- // Indicate that the registry has been disabled in the IO thread's copy of
- // the data.
- void DisableIO() { enabled_io_ = false; }
-
// Saves a user's registered protocol handlers.
void Save();
@@ -278,9 +269,6 @@ class ProtocolHandlerRegistry
// requests.
bool enabled_;
- // Copy of enabled_ that is only accessed on the IO thread.
- bool enabled_io_;
-
// Whether or not we are loading.
bool is_loading_;
@@ -288,10 +276,9 @@ class ProtocolHandlerRegistry
// AddPredefinedHandler will be rejected.
bool is_loaded_;
- DefaultClientObserverList default_client_observers_;
+ scoped_refptr<Core> core_;
- // Copy of default_handlers_ that is only accessed on the IO thread.
- ProtocolHandlerMap default_handlers_io_;
+ DefaultClientObserverList default_client_observers_;
DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);
};

Powered by Google App Engine
This is Rietveld 408576698