summaryrefslogtreecommitdiffstats
path: root/chrome/browser/custom_handlers/protocol_handler_registry.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 15:11:35 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 15:11:35 +0000
commitbcb999db980e678755e59b8c85cb973df95614ab (patch)
treef8ef010fc98fb1ff710999f4017ede1bffcfdf35 /chrome/browser/custom_handlers/protocol_handler_registry.h
parent3fe73f16c7d40ba0331d23180401d5dd8cff9cc0 (diff)
downloadchromium_src-bcb999db980e678755e59b8c85cb973df95614ab.zip
chromium_src-bcb999db980e678755e59b8c85cb973df95614ab.tar.gz
chromium_src-bcb999db980e678755e59b8c85cb973df95614ab.tar.bz2
Fix memory leak in unit tests for ProtocolHandlerRegistry introduced by observers.
Unit tests need to call Finalize at teardown. This has an additional change to http://codereview.chromium.org/7080023/. BUG=83556 Review URL: http://codereview.chromium.org/7050035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87305 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.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h
index 7532bba..fa588c5 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.h
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -16,6 +16,7 @@
#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/common/notification_service.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
@@ -41,9 +42,35 @@ class ProtocolHandlerRegistry
virtual void RegisterWithOSAsDefaultClient(const std::string& protocol);
};
+ class DefaultClientObserver
+ : public ShellIntegration::DefaultWebClientObserver {
+ public:
+ explicit DefaultClientObserver(ProtocolHandlerRegistry* registry);
+ virtual ~DefaultClientObserver();
+
+ // Get response from the worker regarding whether Chrome is the default
+ // handler for the protocol.
+ virtual void SetDefaultWebClientUIState(
+ ShellIntegration::DefaultWebClientUIState state);
+
+ // Give the observer a handle to the worker, so we can find out the protocol
+ // when we're called and also tell the worker if we get deleted.
+ void SetWorker(ShellIntegration::DefaultProtocolClientWorker* worker);
+
+ private:
+ // This is a raw pointer, not reference counted, intentionally. In general
+ // subclasses of DefaultWebClientObserver are not able to be refcounted
+ // e.g. the browser options page
+ ProtocolHandlerRegistry* registry_;
+ scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultClientObserver);
+ };
+
typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap;
typedef std::vector<ProtocolHandler> ProtocolHandlerList;
typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap;
+ typedef std::vector<DefaultClientObserver*> DefaultClientObserverList;
ProtocolHandlerRegistry(Profile* profile, Delegate* delegate);
~ProtocolHandlerRegistry();
@@ -97,6 +124,9 @@ class ProtocolHandlerRegistry
// Removes the given protocol handler from the registry.
void RemoveHandler(const ProtocolHandler& handler);
+ // Remove the default handler for the given protocol.
+ void RemoveDefaultHandler(const std::string& scheme);
+
// Returns the default handler for this protocol, or an empty handler if none
// exists.
const ProtocolHandler& GetHandlerFor(const std::string& scheme) const;
@@ -113,6 +143,10 @@ class ProtocolHandlerRegistry
// will not handle requests.
void Disable();
+ // 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();
+
// Registers the preferences that we store registered protocol handlers in.
static void RegisterPrefs(PrefService* prefService);
@@ -138,6 +172,9 @@ class ProtocolHandlerRegistry
// exists.
const ProtocolHandler& GetHandlerForInternal(const std::string& scheme) const;
+ // Removes the given protocol handler from the registry.
+ void RemoveHandlerInternal(const ProtocolHandler& handler);
+
// Saves a user's registered protocol handlers.
void Save();
@@ -204,6 +241,8 @@ class ProtocolHandlerRegistry
// TODO(koz): Remove the necessity of this lock by using message passing.
mutable base::Lock lock_;
+ DefaultClientObserverList default_client_observers_;
+
friend class ProtocolHandlerRegistryTest;
DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);