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

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: Fix android build 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..3f831deeb9324b0b804b2b5b1b011dcfe1487a2e 100644
--- a/chrome/browser/autocomplete/shortcuts_backend.cc
+++ b/chrome/browser/autocomplete/shortcuts_backend.cc
@@ -13,9 +13,8 @@
#include "base/guid.h"
#include "base/i18n/case_conversion.h"
#include "base/strings/string_util.h"
-#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 +78,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 +92,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,42 +175,23 @@ void ShortcutsBackend::ShutdownOnUIThread() {
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
notification_registrar_.RemoveAll();
+ history_service_observer_.RemoveAll();
}
void ShortcutsBackend::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
+#if defined(ENABLE_EXTENSIONS)
+ DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
if (!initialized())
return;
-#if defined(ENABLE_EXTENSIONS)
- if (type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
- // When an extension is unloaded, we want to remove any Shortcuts associated
- // with it.
- DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
- details)->extension->url(), false);
- return;
- }
+ // When an extension is unloaded, we want to remove any Shortcuts associated
+ // with it.
+ DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
+ details)->extension->url(),
+ false);
#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 +317,27 @@ bool ShortcutsBackend::DeleteAllShortcuts() {
&history::ShortcutsDatabase::DeleteAllShortcuts),
db_.get()));
}
+
+void ShortcutsBackend::OnURLsDeleted(HistoryService* history_service,
+ bool all_history,
+ bool expired,
+ const history::URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ if (!initialized())
+ return;
+ if (all_history) {
+ DeleteAllShortcuts();
+ return;
+ }
+
+ history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
+ for (const auto& guid_pair : guid_map_) {
+ if (std::find_if(
+ deleted_rows.begin(), deleted_rows.end(),
+ history::URLRow::URLRowHasURL(
+ guid_pair.second->second.match_core.destination_url)) !=
+ deleted_rows.end())
sdefresne 2014/12/10 16:41:47 style: In general, curly braces are not required f
nshaik 2014/12/11 03:11:09 Done.
+ shortcut_ids.push_back(guid_pair.first);
+ }
+ DeleteShortcutsWithIDs(shortcut_ids);
+}
« 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