Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/autocomplete/shortcuts_backend.cc

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/i18n/case_conversion.h" 14 #include "base/i18n/case_conversion.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/history/history_notifications.h"
18 #include "chrome/browser/history/history_service.h" 16 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/history/history_service_factory.h"
19 #include "chrome/browser/history/shortcuts_database.h" 18 #include "chrome/browser/history/shortcuts_database.h"
20 #include "chrome/browser/omnibox/omnibox_log.h" 19 #include "chrome/browser/omnibox/omnibox_log.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/search_engines/template_url_service_factory.h" 21 #include "chrome/browser/search_engines/template_url_service_factory.h"
23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
24 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
25 #include "components/omnibox/autocomplete_input.h" 24 #include "components/omnibox/autocomplete_input.h"
26 #include "components/omnibox/autocomplete_match.h" 25 #include "components/omnibox/autocomplete_match.h"
27 #include "components/omnibox/autocomplete_match_type.h" 26 #include "components/omnibox/autocomplete_match_type.h"
28 #include "components/omnibox/autocomplete_result.h" 27 #include "components/omnibox/autocomplete_result.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 71 }
73 72
74 } // namespace 73 } // namespace
75 74
76 75
77 // ShortcutsBackend ----------------------------------------------------------- 76 // ShortcutsBackend -----------------------------------------------------------
78 77
79 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) 78 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
80 : profile_(profile), 79 : profile_(profile),
81 current_state_(NOT_INITIALIZED), 80 current_state_(NOT_INITIALIZED),
81 history_service_observer_(this),
82 no_db_access_(suppress_db) { 82 no_db_access_(suppress_db) {
83 if (!suppress_db) { 83 if (!suppress_db) {
84 db_ = new history::ShortcutsDatabase( 84 db_ = new history::ShortcutsDatabase(
85 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); 85 profile->GetPath().Append(chrome::kShortcutsDatabaseName));
86 } 86 }
87 // |profile| can be NULL in tests. 87 // |profile| can be NULL in tests.
88 if (profile) { 88 if (profile) {
89 #if defined(ENABLE_EXTENSIONS) 89 #if defined(ENABLE_EXTENSIONS)
90 notification_registrar_.Add( 90 notification_registrar_.Add(
91 this, 91 this,
92 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 92 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
93 content::Source<Profile>(profile)); 93 content::Source<Profile>(profile));
94 #endif 94 #endif
95 notification_registrar_.Add( 95 HistoryService* hs =
96 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 96 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
97 content::Source<Profile>(profile)); 97 if (hs)
98 history_service_observer_.Add(hs);
98 } 99 }
99 } 100 }
100 101
101 bool ShortcutsBackend::Init() { 102 bool ShortcutsBackend::Init() {
102 if (current_state_ != NOT_INITIALIZED) 103 if (current_state_ != NOT_INITIALIZED)
103 return false; 104 return false;
104 105
105 if (no_db_access_) { 106 if (no_db_access_) {
106 current_state_ = INITIALIZED; 107 current_state_ = INITIALIZED;
107 return true; 108 return true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 StripMatchMarkers(normalized_match.contents_class), 168 StripMatchMarkers(normalized_match.contents_class),
168 normalized_match.description, 169 normalized_match.description,
169 StripMatchMarkers(normalized_match.description_class), 170 StripMatchMarkers(normalized_match.description_class),
170 normalized_match.transition, match_type, normalized_match.keyword); 171 normalized_match.transition, match_type, normalized_match.keyword);
171 } 172 }
172 173
173 void ShortcutsBackend::ShutdownOnUIThread() { 174 void ShortcutsBackend::ShutdownOnUIThread() {
174 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || 175 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
175 BrowserThread::CurrentlyOn(BrowserThread::UI)); 176 BrowserThread::CurrentlyOn(BrowserThread::UI));
176 notification_registrar_.RemoveAll(); 177 notification_registrar_.RemoveAll();
178 history_service_observer_.RemoveAll();
177 } 179 }
178 180
179 void ShortcutsBackend::Observe(int type, 181 void ShortcutsBackend::Observe(int type,
180 const content::NotificationSource& source, 182 const content::NotificationSource& source,
181 const content::NotificationDetails& details) { 183 const content::NotificationDetails& details) {
184 #if defined(ENABLE_EXTENSIONS)
185 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, type);
182 if (!initialized()) 186 if (!initialized())
183 return; 187 return;
184 188
185 #if defined(ENABLE_EXTENSIONS) 189 // When an extension is unloaded, we want to remove any Shortcuts associated
186 if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { 190 // with it.
187 // When an extension is unloaded, we want to remove any Shortcuts associated 191 DeleteShortcutsWithURL(
188 // with it. 192 content::Details<extensions::UnloadedExtensionInfo>(
189 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( 193 details)->extension->url(),
190 details)->extension->url(), false); 194 false);
195 return;
196 #endif
197 DCHECK(0);
nshaik 2014/12/12 05:50:44 @pkasting, please see if this CHECK is necessary.
Peter Kasting 2014/12/12 19:06:52 Don't do this. Either just omit it, or else make
198 }
199
200 void ShortcutsBackend::OnURLsDeleted(HistoryService* history_service,
201 bool all_history,
202 bool expired,
203 const history::URLRows& deleted_rows,
204 const std::set<GURL>& favicon_urls) {
205 if (!initialized())
191 return; 206 return;
192 }
193 #endif
194 207
195 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); 208 if (all_history) {
196 const history::URLsDeletedDetails* deleted_details =
197 content::Details<const history::URLsDeletedDetails>(details).ptr();
198 if (deleted_details->all_history) {
199 DeleteAllShortcuts(); 209 DeleteAllShortcuts();
200 return; 210 return;
201 } 211 }
202 212
203 const history::URLRows& rows(deleted_details->rows);
204 history::ShortcutsDatabase::ShortcutIDs shortcut_ids; 213 history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
205 for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end(); 214 for (const auto& guid_pair : guid_map_) {
206 ++it) {
207 if (std::find_if( 215 if (std::find_if(
208 rows.begin(), rows.end(), history::URLRow::URLRowHasURL( 216 deleted_rows.begin(), deleted_rows.end(),
209 it->second->second.match_core.destination_url)) != rows.end()) 217 history::URLRow::URLRowHasURL(
210 shortcut_ids.push_back(it->first); 218 guid_pair.second->second.match_core.destination_url)) !=
219 deleted_rows.end()) {
220 shortcut_ids.push_back(guid_pair.first);
221 }
211 } 222 }
212 DeleteShortcutsWithIDs(shortcut_ids); 223 DeleteShortcutsWithIDs(shortcut_ids);
213 } 224 }
214 225
215 void ShortcutsBackend::InitInternal() { 226 void ShortcutsBackend::InitInternal() {
216 DCHECK(current_state_ == INITIALIZING); 227 DCHECK(current_state_ == INITIALIZING);
217 db_->Init(); 228 db_->Init();
218 history::ShortcutsDatabase::GuidToShortcutMap shortcuts; 229 history::ShortcutsDatabase::GuidToShortcutMap shortcuts;
219 db_->LoadShortcuts(&shortcuts); 230 db_->LoadShortcuts(&shortcuts);
220 temp_shortcuts_map_.reset(new ShortcutMap); 231 temp_shortcuts_map_.reset(new ShortcutMap);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 guid_map_.clear(); 339 guid_map_.clear();
329 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 340 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
330 OnShortcutsChanged()); 341 OnShortcutsChanged());
331 return no_db_access_ || 342 return no_db_access_ ||
332 BrowserThread::PostTask( 343 BrowserThread::PostTask(
333 BrowserThread::DB, FROM_HERE, 344 BrowserThread::DB, FROM_HERE,
334 base::Bind(base::IgnoreResult( 345 base::Bind(base::IgnoreResult(
335 &history::ShortcutsDatabase::DeleteAllShortcuts), 346 &history::ShortcutsDatabase::DeleteAllShortcuts),
336 db_.get())); 347 db_.get()));
337 } 348 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_backend.h ('k') | chrome/browser/autocomplete/shortcuts_backend_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698