diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 06:07:28 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-05 06:07:28 +0000 |
commit | 559f973910377af001a91cc014ddcad6155d255a (patch) | |
tree | a9942ba7555ef67d20449edfd98639fa3ca40628 /chrome/browser/custom_handlers/protocol_handler_registry.h | |
parent | d99592b1bea5672f33c705a5efb7eeb347bc24e5 (diff) | |
download | chromium_src-559f973910377af001a91cc014ddcad6155d255a.zip chromium_src-559f973910377af001a91cc014ddcad6155d255a.tar.gz chromium_src-559f973910377af001a91cc014ddcad6155d255a.tar.bz2 |
Change ProtocolHandlerRegistry from locks to message passing.
TEST=unit tests provided
Review URL: http://codereview.chromium.org/7291021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91490 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/custom_handlers/protocol_handler_registry.h')
-rw-r--r-- | chrome/browser/custom_handlers/protocol_handler_registry.h | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h index fa588c5..391bd19 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.h +++ b/chrome/browser/custom_handlers/protocol_handler_registry.h @@ -12,11 +12,11 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" -#include "base/synchronization/lock.h" #include "base/values.h" #include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/shell_integration.h" +#include "content/browser/browser_thread.h" #include "content/common/notification_service.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" @@ -28,7 +28,8 @@ // instances of this class. class ProtocolHandlerRegistry - : public base::RefCountedThreadSafe<ProtocolHandlerRegistry> { + : public base::RefCountedThreadSafe<ProtocolHandlerRegistry, + BrowserThread::DeleteOnIOThread> { public: // 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 @@ -121,6 +122,10 @@ class ProtocolHandlerRegistry // Returns true if the protocol has a registered protocol handler. bool IsHandledProtocol(const std::string& scheme) const; + // Returns true if the protocol has a registered 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); @@ -155,25 +160,21 @@ class ProtocolHandlerRegistry private: friend class base::RefCountedThreadSafe<ProtocolHandlerRegistry>; - // Returns true if the protocol has a registered protocol handler. - bool IsHandledProtocolInternal(const std::string& scheme) const; - - // Returns true if this handler is the default handler for its protocol. - bool IsDefaultInternal(const ProtocolHandler& handler) const; - - // Returns true if we allow websites to register handlers for the given - // scheme. - bool CanSchemeBeOverriddenInternal(const std::string& scheme) const; + // Clears the default for the provided protocol. + // Should be called only from the IO thread. + void ClearDefaultIO(const std::string& scheme); - // Returns true if an identical protocol handler has already been registered. - bool IsRegisteredInternal(const ProtocolHandler& handler) const; + // Makes this ProtocolHandler the default handler for its protocol. + // Should be called only from the IO thread. + void SetDefaultIO(const ProtocolHandler& handler); - // Returns the default handler for this protocol, or an empty handler if none - // exists. - const ProtocolHandler& GetHandlerForInternal(const std::string& scheme) const; + // Indicate that the registry has been enabled in the IO thread's copy of the + // data. + void EnableIO() { enabled_io_ = true; } - // Removes the given protocol handler from the registry. - void RemoveHandlerInternal(const ProtocolHandler& handler); + // 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(); @@ -232,17 +233,17 @@ 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_; - // This lock ensures that only a single thread is accessing this object at a - // time, that is, it covers the entire class. This is to prevent race - // conditions from concurrent access from the IO and UI threads. - // TODO(koz): Remove the necessity of this lock by using message passing. - mutable base::Lock lock_; - DefaultClientObserverList default_client_observers_; + // Copy of default_handlers_ that is only accessed on the IO thread. + ProtocolHandlerMap default_handlers_io_; + friend class ProtocolHandlerRegistryTest; DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |