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_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/scoped_observer.h" | |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
21 #include "chrome/browser/history/shortcuts_database.h" | 22 #include "chrome/browser/history/shortcuts_database.h" |
22 #include "components/keyed_service/content/refcounted_browser_context_keyed_serv ice.h" | 23 #include "components/keyed_service/content/refcounted_browser_context_keyed_serv ice.h" |
23 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
26 #include "extensions/browser/extension_registry_observer.h" | |
25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
26 | 28 |
27 class Profile; | 29 class Profile; |
28 | 30 |
31 namespace extensions { | |
32 class ExtensionRegistry; | |
33 } | |
34 | |
29 namespace history { | 35 namespace history { |
30 class ShortcutsDatabase; | 36 class ShortcutsDatabase; |
31 }; // namespace history | 37 }; // namespace history |
32 | 38 |
33 // This class manages the shortcut provider backend - access to database on the | 39 // This class manages the shortcut provider backend - access to database on the |
34 // db thread, etc. | 40 // db thread, etc. |
35 class ShortcutsBackend : public RefcountedBrowserContextKeyedService, | 41 class ShortcutsBackend : public RefcountedBrowserContextKeyedService, |
36 public content::NotificationObserver { | 42 public content::NotificationObserver, |
43 public extensions::ExtensionRegistryObserver { | |
37 public: | 44 public: |
38 typedef std::multimap<base::string16, | 45 typedef std::multimap<base::string16, |
39 const history::ShortcutsDatabase::Shortcut> ShortcutMap; | 46 const history::ShortcutsDatabase::Shortcut> ShortcutMap; |
40 | 47 |
41 // |profile| is necessary for profile notifications only and can be NULL in | 48 // |profile| is necessary for profile notifications only and can be NULL in |
42 // unit-tests. For unit testing, set |suppress_db| to true to prevent creation | 49 // unit-tests. For unit testing, set |suppress_db| to true to prevent creation |
43 // of the database, in which case all operations are performed in memory only. | 50 // of the database, in which case all operations are performed in memory only. |
44 ShortcutsBackend(Profile* profile, bool suppress_db); | 51 ShortcutsBackend(Profile* profile, bool suppress_db); |
45 | 52 |
46 // The interface is guaranteed to be called on the thread AddObserver() | 53 // The interface is guaranteed to be called on the thread AddObserver() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 const AutocompleteMatch& match, Profile* profile); | 104 const AutocompleteMatch& match, Profile* profile); |
98 | 105 |
99 // RefcountedBrowserContextKeyedService: | 106 // RefcountedBrowserContextKeyedService: |
100 virtual void ShutdownOnUIThread() OVERRIDE; | 107 virtual void ShutdownOnUIThread() OVERRIDE; |
101 | 108 |
102 // content::NotificationObserver: | 109 // content::NotificationObserver: |
103 virtual void Observe(int type, | 110 virtual void Observe(int type, |
104 const content::NotificationSource& source, | 111 const content::NotificationSource& source, |
105 const content::NotificationDetails& details) OVERRIDE; | 112 const content::NotificationDetails& details) OVERRIDE; |
106 | 113 |
114 // Overridden from extensions::ExtensionRegistryObserver. | |
Peter Kasting
2014/05/12 19:46:55
Nit: File style seems to be "extensions::Extension
limasdf
2014/05/13 14:38:44
Done.
| |
115 virtual void OnExtensionUnloaded( | |
116 content::BrowserContext* browser_context, | |
117 const extensions::Extension* extension, | |
118 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; | |
119 | |
107 // Internal initialization of the back-end. Posted by Init() to the DB thread. | 120 // Internal initialization of the back-end. Posted by Init() to the DB thread. |
108 // On completion posts InitCompleted() back to UI thread. | 121 // On completion posts InitCompleted() back to UI thread. |
109 void InitInternal(); | 122 void InitInternal(); |
110 | 123 |
111 // Finishes initialization on UI thread, notifies all observers. | 124 // Finishes initialization on UI thread, notifies all observers. |
112 void InitCompleted(); | 125 void InitCompleted(); |
113 | 126 |
114 // Adds the Shortcut to the database. | 127 // Adds the Shortcut to the database. |
115 bool AddShortcut(const history::ShortcutsDatabase::Shortcut& shortcut); | 128 bool AddShortcut(const history::ShortcutsDatabase::Shortcut& shortcut); |
116 | 129 |
(...skipping 21 matching lines...) Expand all Loading... | |
138 // copy. | 151 // copy. |
139 scoped_ptr<ShortcutMap> temp_shortcuts_map_; | 152 scoped_ptr<ShortcutMap> temp_shortcuts_map_; |
140 scoped_ptr<GuidMap> temp_guid_map_; | 153 scoped_ptr<GuidMap> temp_guid_map_; |
141 | 154 |
142 ShortcutMap shortcuts_map_; | 155 ShortcutMap shortcuts_map_; |
143 // This is a helper map for quick access to a shortcut by guid. | 156 // This is a helper map for quick access to a shortcut by guid. |
144 GuidMap guid_map_; | 157 GuidMap guid_map_; |
145 | 158 |
146 content::NotificationRegistrar notification_registrar_; | 159 content::NotificationRegistrar notification_registrar_; |
147 | 160 |
161 // Listen to extension load, unload notifications. | |
Peter Kasting
2014/05/12 19:46:55
Remove this comment; it's both inaccurate (you're
limasdf
2014/05/13 14:38:44
Done.
| |
162 ScopedObserver<extensions::ExtensionRegistry, | |
163 extensions::ExtensionRegistryObserver> | |
164 extension_registry_observer_; | |
165 | |
148 // For some unit-test only. | 166 // For some unit-test only. |
149 bool no_db_access_; | 167 bool no_db_access_; |
150 | 168 |
151 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); | 169 DISALLOW_COPY_AND_ASSIGN(ShortcutsBackend); |
152 }; | 170 }; |
153 | 171 |
154 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ | 172 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_BACKEND_H_ |
OLD | NEW |