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