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

Unified 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: Remove NotificationObserver from InMemoryURLIndex 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/shortcuts_backend.cc
diff --git a/chrome/browser/autocomplete/shortcuts_backend.cc b/chrome/browser/autocomplete/shortcuts_backend.cc
index 62ebaf53b15312c841f7830ff14f102245a261dd..83ed1dd8e029a7d69caa5b9d82440ec8035474cc 100644
--- a/chrome/browser/autocomplete/shortcuts_backend.cc
+++ b/chrome/browser/autocomplete/shortcuts_backend.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/shortcuts_database.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/profiles/profile.h"
@@ -79,7 +80,8 @@ AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) {
ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
: profile_(profile),
current_state_(NOT_INITIALIZED),
- no_db_access_(suppress_db) {
+ no_db_access_(suppress_db),
+ history_service_observer_(this) {
if (!suppress_db) {
db_ = new history::ShortcutsDatabase(
profile->GetPath().Append(chrome::kShortcutsDatabaseName));
@@ -92,9 +94,10 @@ ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile));
#endif
- notification_registrar_.Add(
- this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- content::Source<Profile>(profile));
+ HistoryService* hs =
+ HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
+ if (hs)
+ history_service_observer_.Add(hs);
}
}
@@ -174,6 +177,7 @@ void ShortcutsBackend::ShutdownOnUIThread() {
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
notification_registrar_.RemoveAll();
+ history_service_observer_.RemoveAll();
}
void ShortcutsBackend::Observe(int type,
@@ -191,25 +195,6 @@ void ShortcutsBackend::Observe(int type,
return;
}
#endif
-
- DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type);
- const history::URLsDeletedDetails* deleted_details =
- content::Details<const history::URLsDeletedDetails>(details).ptr();
- if (deleted_details->all_history) {
- DeleteAllShortcuts();
- return;
- }
-
- const history::URLRows& rows(deleted_details->rows);
- history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
- for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
- ++it) {
- if (std::find_if(
- rows.begin(), rows.end(), history::URLRow::URLRowHasURL(
- it->second->second.match_core.destination_url)) != rows.end())
- shortcut_ids.push_back(it->first);
- }
- DeleteShortcutsWithIDs(shortcut_ids);
}
void ShortcutsBackend::InitInternal() {
@@ -335,3 +320,26 @@ bool ShortcutsBackend::DeleteAllShortcuts() {
&history::ShortcutsDatabase::DeleteAllShortcuts),
db_.get()));
}
+
+void ShortcutsBackend::OnURLsDeleted(
+ HistoryService* history_service,
+ const history::URLsDeletedDetails& deleted_details) {
+ if (!initialized())
+ return;
+ if (deleted_details.all_history) {
+ DeleteAllShortcuts();
+ return;
+ }
+
+ const history::URLRows& rows(deleted_details.rows);
+ history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
+ for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
sdefresne 2014/12/04 17:21:12 nit: c++11 for-loop and auto are now allowed, so t
nshaik 2014/12/07 09:34:49 Done.
+ ++it) {
+ if (std::find_if(rows.begin(), rows.end(),
+ history::URLRow::URLRowHasURL(
+ it->second->second.match_core.destination_url)) !=
+ rows.end())
+ shortcut_ids.push_back(it->first);
+ }
+ DeleteShortcutsWithIDs(shortcut_ids);
+}

Powered by Google App Engine
This is Rietveld 408576698