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/profiles/profile_keyed_service.h" | 11 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
12 #include "chrome/common/extensions/command.h" | 12 #include "chrome/common/extensions/command.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 | 18 |
19 class PrefServiceSyncable; | 19 class PrefServiceSyncable; |
20 class Profile; | 20 class Profile; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class DictionaryValue; | 23 class DictionaryValue; |
24 } | 24 } |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 class Accelerator; | 27 class Accelerator; |
28 } | 28 } |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 // This service keeps track of preferences related to extension commands | 32 // This service keeps track of preferences related to extension commands |
33 // (assigning initial keybindings on install and removing them on deletion | 33 // (assigning initial keybindings on install and removing them on deletion |
34 // and answers questions related to which commands are active. | 34 // and answers questions related to which commands are active. |
35 class CommandService : public ProfileKeyedService, | 35 class CommandService : public ProfileKeyedAPI, |
36 public content::NotificationObserver { | 36 public content::NotificationObserver { |
37 public: | 37 public: |
38 // An enum specifying whether to fetch all extension commands or only active | 38 // An enum specifying whether to fetch all extension commands or only active |
39 // ones. | 39 // ones. |
40 enum QueryType { | 40 enum QueryType { |
41 ALL, | 41 ALL, |
42 ACTIVE_ONLY, | 42 ACTIVE_ONLY, |
43 }; | 43 }; |
44 | 44 |
45 // Register prefs for keybinding. | 45 // Register prefs for keybinding. |
46 static void RegisterUserPrefs(PrefServiceSyncable* user_prefs); | 46 static void RegisterUserPrefs(PrefServiceSyncable* user_prefs); |
47 | 47 |
48 // Constructs a CommandService object for the given profile. | 48 // Constructs a CommandService object for the given profile. |
49 explicit CommandService(Profile* profile); | 49 explicit CommandService(Profile* profile); |
50 virtual ~CommandService(); | 50 virtual ~CommandService(); |
51 | 51 |
| 52 // ProfileKeyedAPI implementation. |
| 53 static ProfileKeyedAPIFactory<CommandService>* GetFactoryInstance(); |
| 54 |
| 55 // Convenience method to get the CommandService for a profile. |
| 56 static CommandService* Get(Profile* profile); |
| 57 |
52 // Gets the command (if any) for the browser action of an extension given | 58 // Gets the command (if any) for the browser action of an extension given |
53 // its |extension_id|. The function consults the master list to see if | 59 // its |extension_id|. The function consults the master list to see if |
54 // the command is active. Returns false if the extension has no browser | 60 // the command is active. Returns false if the extension has no browser |
55 // action. Returns false if the command is not active and |type| requested | 61 // action. Returns false if the command is not active and |type| requested |
56 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not | 62 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not |
57 // NULL) contains whether |command| is active. | 63 // NULL) contains whether |command| is active. |
58 bool GetBrowserActionCommand(const std::string& extension_id, | 64 bool GetBrowserActionCommand(const std::string& extension_id, |
59 QueryType type, | 65 QueryType type, |
60 extensions::Command* command, | 66 extensions::Command* command, |
61 bool* active); | 67 bool* active); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // command is not found. | 122 // command is not found. |
117 ui::Accelerator FindShortcutForCommand(const std::string& extension_id, | 123 ui::Accelerator FindShortcutForCommand(const std::string& extension_id, |
118 const std::string& command); | 124 const std::string& command); |
119 | 125 |
120 // Overridden from content::NotificationObserver. | 126 // Overridden from content::NotificationObserver. |
121 virtual void Observe(int type, | 127 virtual void Observe(int type, |
122 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
123 const content::NotificationDetails& details) OVERRIDE; | 129 const content::NotificationDetails& details) OVERRIDE; |
124 | 130 |
125 private: | 131 private: |
| 132 friend class ProfileKeyedAPIFactory<CommandService>; |
| 133 |
| 134 // ProfileKeyedAPI implementation. |
| 135 static const char* service_name() { |
| 136 return "CommandService"; |
| 137 } |
| 138 static const bool kServiceRedirectedInIncognito = true; |
| 139 |
126 // An enum specifying the types of icons that can have a command. | 140 // An enum specifying the types of icons that can have a command. |
127 enum ExtensionActionType { | 141 enum ExtensionActionType { |
128 BROWSER_ACTION, | 142 BROWSER_ACTION, |
129 PAGE_ACTION, | 143 PAGE_ACTION, |
130 SCRIPT_BADGE, | 144 SCRIPT_BADGE, |
131 }; | 145 }; |
132 | 146 |
133 // Assigns initial keybinding for a given |extension|'s page action, browser | 147 // Assigns initial keybinding for a given |extension|'s page action, browser |
134 // action and named commands. In each case, if the suggested keybinding is | 148 // action and named commands. In each case, if the suggested keybinding is |
135 // free, it will be taken by this extension. If not, that keybinding request | 149 // free, it will be taken by this extension. If not, that keybinding request |
(...skipping 18 matching lines...) Expand all Loading... |
154 | 168 |
155 // A weak pointer to the profile we are associated with. Not owned by us. | 169 // A weak pointer to the profile we are associated with. Not owned by us. |
156 Profile* profile_; | 170 Profile* profile_; |
157 | 171 |
158 DISALLOW_COPY_AND_ASSIGN(CommandService); | 172 DISALLOW_COPY_AND_ASSIGN(CommandService); |
159 }; | 173 }; |
160 | 174 |
161 } // namespace extensions | 175 } // namespace extensions |
162 | 176 |
163 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ | 177 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ |
OLD | NEW |