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

Side by Side 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: Respond to review comments. Fit and finish. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ 5 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ 6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/sequenced_task_runner_helpers.h" 14 #include "base/sequenced_task_runner_helpers.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/shell_integration.h" 17 #include "chrome/browser/shell_integration.h"
19 #include "chrome/common/custom_handlers/protocol_handler.h" 18 #include "chrome/common/custom_handlers/protocol_handler.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
22 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
23 #include "net/url_request/url_request_job.h" 22 #include "net/url_request/url_request_job.h"
24 23
25 // This is where handlers for protocols registered with 24 // This is where handlers for protocols registered with
26 // navigator.registerProtocolHandler() are registered. Each Profile owns an 25 // navigator.registerProtocolHandler() are registered. Each Profile owns an
27 // instance of this class, which is initialized on browser start through 26 // instance of this class, which is initialized on browser start through
28 // Profile::InitRegisteredProtocolHandlers(), and they should be the only 27 // Profile::InitRegisteredProtocolHandlers(), and they should be the only
29 // instances of this class. 28 // instances of this class.
30 29
31 class ProtocolHandlerRegistry 30 class ProtocolHandlerRegistry : public ProfileKeyedService {
32 : public base::RefCountedThreadSafe< 31
33 ProtocolHandlerRegistry, content::BrowserThread::DeleteOnIOThread> {
34 public: 32 public:
35 class DefaultClientObserver 33 class DefaultClientObserver
36 : public ShellIntegration::DefaultWebClientObserver { 34 : public ShellIntegration::DefaultWebClientObserver {
37 public: 35 public:
38 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry); 36 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry);
39 virtual ~DefaultClientObserver(); 37 virtual ~DefaultClientObserver();
40 38
41 // Get response from the worker regarding whether Chrome is the default 39 // Get response from the worker regarding whether Chrome is the default
42 // handler for the protocol. 40 // handler for the protocol.
43 virtual void SetDefaultWebClientUIState( 41 virtual void SetDefaultWebClientUIState(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Returns a list of protocol handlers that can be replaced by the given 108 // Returns a list of protocol handlers that can be replaced by the given
111 // handler. 109 // handler.
112 ProtocolHandlerList GetReplacedHandlers(const ProtocolHandler& handler) const; 110 ProtocolHandlerList GetReplacedHandlers(const ProtocolHandler& handler) const;
113 111
114 // Clears the default for the provided protocol. 112 // Clears the default for the provided protocol.
115 void ClearDefault(const std::string& scheme); 113 void ClearDefault(const std::string& scheme);
116 114
117 // Returns true if this handler is the default handler for its protocol. 115 // Returns true if this handler is the default handler for its protocol.
118 bool IsDefault(const ProtocolHandler& handler) const; 116 bool IsDefault(const ProtocolHandler& handler) const;
119 117
120 // Loads a user's registered protocol handlers. 118 // Initializes default protocol setttings and loads them from prefs.
121 void Load(); 119 void InitProtocolSettings();
122 120
123 // Returns the offset in the list of handlers for a protocol of the default 121 // Returns the offset in the list of handlers for a protocol of the default
124 // handler for that protocol. 122 // handler for that protocol.
125 int GetHandlerIndex(const std::string& scheme) const; 123 int GetHandlerIndex(const std::string& scheme) const;
126 124
127 // Get the list of protocol handlers for the given scheme. 125 // Get the list of protocol handlers for the given scheme.
128 ProtocolHandlerList GetHandlersFor(const std::string& scheme) const; 126 ProtocolHandlerList GetHandlersFor(const std::string& scheme) const;
129 127
130 // Get the list of ignored protocol handlers. 128 // Get the list of ignored protocol handlers.
131 ProtocolHandlerList GetIgnoredHandlers(); 129 ProtocolHandlerList GetIgnoredHandlers();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Puts this registry in the enabled state - registered protocol handlers 175 // Puts this registry in the enabled state - registered protocol handlers
178 // will handle requests. 176 // will handle requests.
179 void Enable(); 177 void Enable();
180 178
181 // Puts this registry in the disabled state - registered protocol handlers 179 // Puts this registry in the disabled state - registered protocol handlers
182 // will not handle requests. 180 // will not handle requests.
183 void Disable(); 181 void Disable();
184 182
185 // This is called by the UI thread when the system is shutting down. This 183 // This is called by the UI thread when the system is shutting down. This
186 // does finalization which must be done on the UI thread. 184 // does finalization which must be done on the UI thread.
187 void Finalize(); 185 virtual void Shutdown() OVERRIDE;
188 186
189 // Registers the preferences that we store registered protocol handlers in. 187 // Registers the preferences that we store registered protocol handlers in.
190 static void RegisterPrefs(PrefService* prefService); 188 static void RegisterPrefs(PrefService* prefService);
191 189
192 bool enabled() const { return enabled_; } 190 bool enabled() const { return enabled_; }
193 191
194 // Add a predefined protocol handler. This has to be called before the first 192 // Add a predefined protocol handler. This has to be called before the first
195 // load command was issued, otherwise the command will be ignored. 193 // load command was issued, otherwise the command will be ignored.
196 void AddPredefinedHandler(const ProtocolHandler& handler); 194 void AddPredefinedHandler(const ProtocolHandler& handler);
197 195
198 private: 196 private:
199 friend class base::DeleteHelper<ProtocolHandlerRegistry>; 197 friend class base::DeleteHelper<ProtocolHandlerRegistry>;
200 friend struct content::BrowserThread::DeleteOnThread< 198 friend struct content::BrowserThread::DeleteOnThread<
201 content::BrowserThread::IO>; 199 content::BrowserThread::IO>;
202 friend class ProtocolHandlerRegistryTest; 200 friend class ProtocolHandlerRegistryTest;
203 friend class RegisterProtocolHandlerBrowserTest; 201 friend class RegisterProtocolHandlerBrowserTest;
204 202
205 ~ProtocolHandlerRegistry(); 203 virtual ~ProtocolHandlerRegistry();
206 204
207 // Puts the given handler at the top of the list of handlers for its 205 // Puts the given handler at the top of the list of handlers for its
208 // protocol. 206 // protocol.
209 void PromoteHandler(const ProtocolHandler& handler); 207 void PromoteHandler(const ProtocolHandler& handler);
210 208
211 // Clears the default for the provided protocol. 209 // Clears the default for the provided protocol.
212 // Should be called only from the IO thread. 210 // Should be called only from the IO thread.
213 void ClearDefaultIO(const std::string& scheme); 211 void ClearDefaultIO(const std::string& scheme);
214 212
215 // Makes this ProtocolHandler the default handler for its protocol. 213 // Makes this ProtocolHandler the default handler for its protocol.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 bool is_loaded_; 287 bool is_loaded_;
290 288
291 DefaultClientObserverList default_client_observers_; 289 DefaultClientObserverList default_client_observers_;
292 290
293 // Copy of default_handlers_ that is only accessed on the IO thread. 291 // Copy of default_handlers_ that is only accessed on the IO thread.
294 ProtocolHandlerMap default_handlers_io_; 292 ProtocolHandlerMap default_handlers_io_;
295 293
296 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); 294 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);
297 }; 295 };
298 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ 296 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/protocol_handler_registry.cc » ('j') | chrome/browser/profiles/profile.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698