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 #include "chrome/browser/autocomplete/shortcuts_backend.h" | 5 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/history/history_notifications.h" | 21 #include "chrome/browser/history/history_notifications.h" |
22 #include "chrome/browser/history/history_service.h" | 22 #include "chrome/browser/history/history_service.h" |
23 #include "chrome/browser/history/shortcuts_database.h" | 23 #include "chrome/browser/history/shortcuts_database.h" |
24 #include "chrome/browser/omnibox/omnibox_log.h" | 24 #include "chrome/browser/omnibox/omnibox_log.h" |
25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/common/autocomplete_match_type.h" | 26 #include "chrome/common/autocomplete_match_type.h" |
27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
31 #include "extensions/browser/extension_registry.h" | |
31 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
32 | 33 |
33 using content::BrowserThread; | 34 using content::BrowserThread; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // Takes Match classification vector and removes all matched positions, | 38 // Takes Match classification vector and removes all matched positions, |
38 // compacting repetitions if necessary. | 39 // compacting repetitions if necessary. |
39 std::string StripMatchMarkers(const ACMatchClassifications& matches) { | 40 std::string StripMatchMarkers(const ACMatchClassifications& matches) { |
40 ACMatchClassifications unmatched; | 41 ACMatchClassifications unmatched; |
(...skipping 25 matching lines...) Expand all Loading... | |
66 } | 67 } |
67 | 68 |
68 } // namespace | 69 } // namespace |
69 | 70 |
70 | 71 |
71 // ShortcutsBackend ----------------------------------------------------------- | 72 // ShortcutsBackend ----------------------------------------------------------- |
72 | 73 |
73 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) | 74 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) |
74 : profile_(profile), | 75 : profile_(profile), |
75 current_state_(NOT_INITIALIZED), | 76 current_state_(NOT_INITIALIZED), |
77 extension_registry_observer_(this), | |
76 no_db_access_(suppress_db) { | 78 no_db_access_(suppress_db) { |
77 if (!suppress_db) { | 79 if (!suppress_db) { |
78 db_ = new history::ShortcutsDatabase( | 80 db_ = new history::ShortcutsDatabase( |
79 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); | 81 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); |
80 } | 82 } |
81 // |profile| can be NULL in tests. | 83 // |profile| can be NULL in tests. |
82 if (profile) { | 84 if (profile) { |
83 notification_registrar_.Add( | 85 extension_registry_observer_.Add( |
84 this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 86 extensions::ExtensionRegistry::Get(profile)); |
Peter Kasting
2014/05/12 19:46:55
Nit: Move this after the line below, to keep initi
limasdf
2014/05/13 14:38:44
Done.
| |
85 content::Source<Profile>(profile)); | |
86 notification_registrar_.Add( | 87 notification_registrar_.Add( |
87 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 88 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
88 content::Source<Profile>(profile)); | 89 content::Source<Profile>(profile)); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 bool ShortcutsBackend::Init() { | 93 bool ShortcutsBackend::Init() { |
93 if (current_state_ != NOT_INITIALIZED) | 94 if (current_state_ != NOT_INITIALIZED) |
94 return false; | 95 return false; |
95 | 96 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 StripMatchMarkers(normalized_match.description_class), | 158 StripMatchMarkers(normalized_match.description_class), |
158 normalized_match.transition, match_type, normalized_match.keyword); | 159 normalized_match.transition, match_type, normalized_match.keyword); |
159 } | 160 } |
160 | 161 |
161 void ShortcutsBackend::ShutdownOnUIThread() { | 162 void ShortcutsBackend::ShutdownOnUIThread() { |
162 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 163 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
163 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 notification_registrar_.RemoveAll(); | 165 notification_registrar_.RemoveAll(); |
165 } | 166 } |
166 | 167 |
168 void ShortcutsBackend::OnExtensionUnloaded( | |
Peter Kasting
2014/05/12 19:46:55
Nit: Function definition order should match declar
limasdf
2014/05/13 14:38:44
Done.
| |
169 content::BrowserContext* browser_context, | |
170 const extensions::Extension* extension, | |
171 extensions::UnloadedExtensionInfo::Reason reason) { | |
172 if (!initialized()) | |
173 return; | |
174 | |
175 // When an extension is unloaded, we want to remove any Shortcuts associated | |
176 // with it. | |
177 DeleteShortcutsWithURL(extension->url(), false); | |
178 } | |
179 | |
167 void ShortcutsBackend::Observe(int type, | 180 void ShortcutsBackend::Observe(int type, |
168 const content::NotificationSource& source, | 181 const content::NotificationSource& source, |
169 const content::NotificationDetails& details) { | 182 const content::NotificationDetails& details) { |
170 if (!initialized()) | |
171 return; | |
172 | |
173 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | |
174 // When an extension is unloaded, we want to remove any Shortcuts associated | |
175 // with it. | |
176 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( | |
177 details)->extension->url(), false); | |
178 return; | |
179 } | |
180 | |
181 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); | 183 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); |
182 const history::URLsDeletedDetails* deleted_details = | 184 const history::URLsDeletedDetails* deleted_details = |
183 content::Details<const history::URLsDeletedDetails>(details).ptr(); | 185 content::Details<const history::URLsDeletedDetails>(details).ptr(); |
184 if (deleted_details->all_history) { | 186 if (deleted_details->all_history) { |
185 DeleteAllShortcuts(); | 187 DeleteAllShortcuts(); |
186 return; | 188 return; |
187 } | 189 } |
188 | 190 |
189 const history::URLRows& rows(deleted_details->rows); | 191 const history::URLRows& rows(deleted_details->rows); |
190 history::ShortcutsDatabase::ShortcutIDs shortcut_ids; | 192 history::ShortcutsDatabase::ShortcutIDs shortcut_ids; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 guid_map_.clear(); | 316 guid_map_.clear(); |
315 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 317 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
316 OnShortcutsChanged()); | 318 OnShortcutsChanged()); |
317 return no_db_access_ || | 319 return no_db_access_ || |
318 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
319 BrowserThread::DB, FROM_HERE, | 321 BrowserThread::DB, FROM_HERE, |
320 base::Bind(base::IgnoreResult( | 322 base::Bind(base::IgnoreResult( |
321 &history::ShortcutsDatabase::DeleteAllShortcuts), | 323 &history::ShortcutsDatabase::DeleteAllShortcuts), |
322 db_.get())); | 324 db_.get())); |
323 } | 325 } |
OLD | NEW |