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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
25 #include "components/omnibox/autocomplete_input.h" | 25 #include "components/omnibox/autocomplete_input.h" |
26 #include "components/omnibox/autocomplete_match.h" | 26 #include "components/omnibox/autocomplete_match.h" |
27 #include "components/omnibox/autocomplete_match_type.h" | 27 #include "components/omnibox/autocomplete_match_type.h" |
28 #include "components/omnibox/autocomplete_result.h" | 28 #include "components/omnibox/autocomplete_result.h" |
29 #include "components/omnibox/base_search_provider.h" | 29 #include "components/omnibox/base_search_provider.h" |
30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 |
| 34 #if defined(ENABLE_EXTENSIONS) |
33 #include "extensions/browser/notification_types.h" | 35 #include "extensions/browser/notification_types.h" |
34 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| 37 #endif |
35 | 38 |
36 using content::BrowserThread; | 39 using content::BrowserThread; |
37 | 40 |
38 namespace { | 41 namespace { |
39 | 42 |
40 // Takes Match classification vector and removes all matched positions, | 43 // Takes Match classification vector and removes all matched positions, |
41 // compacting repetitions if necessary. | 44 // compacting repetitions if necessary. |
42 std::string StripMatchMarkers(const ACMatchClassifications& matches) { | 45 std::string StripMatchMarkers(const ACMatchClassifications& matches) { |
43 ACMatchClassifications unmatched; | 46 ACMatchClassifications unmatched; |
44 for (ACMatchClassifications::const_iterator i(matches.begin()); | 47 for (ACMatchClassifications::const_iterator i(matches.begin()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) | 79 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) |
77 : profile_(profile), | 80 : profile_(profile), |
78 current_state_(NOT_INITIALIZED), | 81 current_state_(NOT_INITIALIZED), |
79 no_db_access_(suppress_db) { | 82 no_db_access_(suppress_db) { |
80 if (!suppress_db) { | 83 if (!suppress_db) { |
81 db_ = new history::ShortcutsDatabase( | 84 db_ = new history::ShortcutsDatabase( |
82 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); | 85 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); |
83 } | 86 } |
84 // |profile| can be NULL in tests. | 87 // |profile| can be NULL in tests. |
85 if (profile) { | 88 if (profile) { |
| 89 #if defined(ENABLE_EXTENSIONS) |
86 notification_registrar_.Add( | 90 notification_registrar_.Add( |
87 this, | 91 this, |
88 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 92 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
89 content::Source<Profile>(profile)); | 93 content::Source<Profile>(profile)); |
| 94 #endif |
90 notification_registrar_.Add( | 95 notification_registrar_.Add( |
91 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 96 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
92 content::Source<Profile>(profile)); | 97 content::Source<Profile>(profile)); |
93 } | 98 } |
94 } | 99 } |
95 | 100 |
96 bool ShortcutsBackend::Init() { | 101 bool ShortcutsBackend::Init() { |
97 if (current_state_ != NOT_INITIALIZED) | 102 if (current_state_ != NOT_INITIALIZED) |
98 return false; | 103 return false; |
99 | 104 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
171 notification_registrar_.RemoveAll(); | 176 notification_registrar_.RemoveAll(); |
172 } | 177 } |
173 | 178 |
174 void ShortcutsBackend::Observe(int type, | 179 void ShortcutsBackend::Observe(int type, |
175 const content::NotificationSource& source, | 180 const content::NotificationSource& source, |
176 const content::NotificationDetails& details) { | 181 const content::NotificationDetails& details) { |
177 if (!initialized()) | 182 if (!initialized()) |
178 return; | 183 return; |
179 | 184 |
| 185 #if defined(ENABLE_EXTENSIONS) |
180 if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | 186 if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
181 // When an extension is unloaded, we want to remove any Shortcuts associated | 187 // When an extension is unloaded, we want to remove any Shortcuts associated |
182 // with it. | 188 // with it. |
183 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( | 189 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( |
184 details)->extension->url(), false); | 190 details)->extension->url(), false); |
185 return; | 191 return; |
186 } | 192 } |
| 193 #endif |
187 | 194 |
188 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); | 195 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); |
189 const history::URLsDeletedDetails* deleted_details = | 196 const history::URLsDeletedDetails* deleted_details = |
190 content::Details<const history::URLsDeletedDetails>(details).ptr(); | 197 content::Details<const history::URLsDeletedDetails>(details).ptr(); |
191 if (deleted_details->all_history) { | 198 if (deleted_details->all_history) { |
192 DeleteAllShortcuts(); | 199 DeleteAllShortcuts(); |
193 return; | 200 return; |
194 } | 201 } |
195 | 202 |
196 const history::URLRows& rows(deleted_details->rows); | 203 const history::URLRows& rows(deleted_details->rows); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 guid_map_.clear(); | 328 guid_map_.clear(); |
322 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 329 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
323 OnShortcutsChanged()); | 330 OnShortcutsChanged()); |
324 return no_db_access_ || | 331 return no_db_access_ || |
325 BrowserThread::PostTask( | 332 BrowserThread::PostTask( |
326 BrowserThread::DB, FROM_HERE, | 333 BrowserThread::DB, FROM_HERE, |
327 base::Bind(base::IgnoreResult( | 334 base::Bind(base::IgnoreResult( |
328 &history::ShortcutsDatabase::DeleteAllShortcuts), | 335 &history::ShortcutsDatabase::DeleteAllShortcuts), |
329 db_.get())); | 336 db_.get())); |
330 } | 337 } |
OLD | NEW |