OLD | NEW |
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_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | |
12 #include "chrome/common/extensions/command.h" | 11 #include "chrome/common/extensions/command.h" |
13 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "extensions/browser/browser_context_keyed_api_factory.h" |
17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
18 | 18 |
19 class Profile; | 19 class Profile; |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class DictionaryValue; | 22 class DictionaryValue; |
23 } | 23 } |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 class BrowserContext; | 26 class BrowserContext; |
27 } | 27 } |
28 | 28 |
29 namespace ui { | 29 namespace ui { |
30 class Accelerator; | 30 class Accelerator; |
31 } | 31 } |
32 | 32 |
33 namespace user_prefs { | 33 namespace user_prefs { |
34 class PrefRegistrySyncable; | 34 class PrefRegistrySyncable; |
35 } | 35 } |
36 | 36 |
37 namespace extensions { | 37 namespace extensions { |
38 | 38 |
39 // This service keeps track of preferences related to extension commands | 39 // This service keeps track of preferences related to extension commands |
40 // (assigning initial keybindings on install and removing them on deletion | 40 // (assigning initial keybindings on install and removing them on deletion |
41 // and answers questions related to which commands are active. | 41 // and answers questions related to which commands are active. |
42 class CommandService : public ProfileKeyedAPI, | 42 class CommandService : public BrowserContextKeyedAPI, |
43 public content::NotificationObserver { | 43 public content::NotificationObserver { |
44 public: | 44 public: |
45 // An enum specifying whether to fetch all extension commands or only active | 45 // An enum specifying whether to fetch all extension commands or only active |
46 // ones. | 46 // ones. |
47 enum QueryType { | 47 enum QueryType { |
48 ALL, | 48 ALL, |
49 ACTIVE_ONLY, | 49 ACTIVE_ONLY, |
50 }; | 50 }; |
51 | 51 |
52 // An enum specifying whether the command is global in scope or not. Global | 52 // An enum specifying whether the command is global in scope or not. Global |
(...skipping 12 matching lines...) Expand all Loading... |
65 PAGE_ACTION | 65 PAGE_ACTION |
66 }; | 66 }; |
67 | 67 |
68 // Register prefs for keybinding. | 68 // Register prefs for keybinding. |
69 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 69 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
70 | 70 |
71 // Constructs a CommandService object for the given profile. | 71 // Constructs a CommandService object for the given profile. |
72 explicit CommandService(content::BrowserContext* context); | 72 explicit CommandService(content::BrowserContext* context); |
73 virtual ~CommandService(); | 73 virtual ~CommandService(); |
74 | 74 |
75 // ProfileKeyedAPI implementation. | 75 // BrowserContextKeyedAPI implementation. |
76 static ProfileKeyedAPIFactory<CommandService>* GetFactoryInstance(); | 76 static BrowserContextKeyedAPIFactory<CommandService>* GetFactoryInstance(); |
77 | 77 |
78 // Convenience method to get the CommandService for a profile. | 78 // Convenience method to get the CommandService for a profile. |
79 static CommandService* Get(content::BrowserContext* context); | 79 static CommandService* Get(content::BrowserContext* context); |
80 | 80 |
81 // Returns true if |extension| is permitted to and does remove the bookmark | 81 // Returns true if |extension| is permitted to and does remove the bookmark |
82 // shortcut key. | 82 // shortcut key. |
83 static bool RemovesBookmarkShortcut(const extensions::Extension* extension); | 83 static bool RemovesBookmarkShortcut(const extensions::Extension* extension); |
84 | 84 |
85 // Gets the command (if any) for the browser action of an extension given | 85 // Gets the command (if any) for the browser action of an extension given |
86 // its |extension_id|. The function consults the master list to see if | 86 // its |extension_id|. The function consults the master list to see if |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Returns true if |extension| is permitted to and does override the bookmark | 165 // Returns true if |extension| is permitted to and does override the bookmark |
166 // shortcut key. | 166 // shortcut key. |
167 bool OverridesBookmarkShortcut(const extensions::Extension* extension) const; | 167 bool OverridesBookmarkShortcut(const extensions::Extension* extension) const; |
168 | 168 |
169 // Overridden from content::NotificationObserver. | 169 // Overridden from content::NotificationObserver. |
170 virtual void Observe(int type, | 170 virtual void Observe(int type, |
171 const content::NotificationSource& source, | 171 const content::NotificationSource& source, |
172 const content::NotificationDetails& details) OVERRIDE; | 172 const content::NotificationDetails& details) OVERRIDE; |
173 | 173 |
174 private: | 174 private: |
175 friend class ProfileKeyedAPIFactory<CommandService>; | 175 friend class BrowserContextKeyedAPIFactory<CommandService>; |
176 | 176 |
177 // ProfileKeyedAPI implementation. | 177 // BrowserContextKeyedAPI implementation. |
178 static const char* service_name() { | 178 static const char* service_name() { |
179 return "CommandService"; | 179 return "CommandService"; |
180 } | 180 } |
181 static const bool kServiceRedirectedInIncognito = true; | 181 static const bool kServiceRedirectedInIncognito = true; |
182 | 182 |
183 // Assigns initial keybinding for a given |extension|'s page action, browser | 183 // Assigns initial keybinding for a given |extension|'s page action, browser |
184 // action and named commands. In each case, if the suggested keybinding is | 184 // action and named commands. In each case, if the suggested keybinding is |
185 // free, it will be taken by this extension. If not, that keybinding request | 185 // free, it will be taken by this extension. If not, that keybinding request |
186 // is ignored. |user_pref| is the PrefService used to record the new | 186 // is ignored. |user_pref| is the PrefService used to record the new |
187 // keybinding assignment. | 187 // keybinding assignment. |
188 void AssignInitialKeybindings(const extensions::Extension* extension); | 188 void AssignInitialKeybindings(const extensions::Extension* extension); |
189 | 189 |
190 bool GetExtensionActionCommand(const std::string& extension_id, | 190 bool GetExtensionActionCommand(const std::string& extension_id, |
191 QueryType query_type, | 191 QueryType query_type, |
192 extensions::Command* command, | 192 extensions::Command* command, |
193 bool* active, | 193 bool* active, |
194 ExtensionCommandType action_type) const; | 194 ExtensionCommandType action_type) const; |
195 | 195 |
196 // The content notification registrar for listening to extension events. | 196 // The content notification registrar for listening to extension events. |
197 content::NotificationRegistrar registrar_; | 197 content::NotificationRegistrar registrar_; |
198 | 198 |
199 // A weak pointer to the profile we are associated with. Not owned by us. | 199 // A weak pointer to the profile we are associated with. Not owned by us. |
200 Profile* profile_; | 200 Profile* profile_; |
201 | 201 |
202 DISALLOW_COPY_AND_ASSIGN(CommandService); | 202 DISALLOW_COPY_AND_ASSIGN(CommandService); |
203 }; | 203 }; |
204 | 204 |
205 template <> | 205 template <> |
206 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies(); | 206 void |
| 207 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies(); |
207 | 208 |
208 } // namespace extensions | 209 } // namespace extensions |
209 | 210 |
210 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ | 211 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ |
OLD | NEW |