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

Unified Diff: chrome/browser/history/shortcuts_backend.cc

Issue 27057004: Make the OmniboxNavigationObserver update the ShortcutsProvider. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 months 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/history/shortcuts_backend.cc
===================================================================
--- chrome/browser/history/shortcuts_backend.cc (revision 228523)
+++ chrome/browser/history/shortcuts_backend.cc (working copy)
@@ -160,8 +160,6 @@
content::Source<Profile>(profile));
notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
content::Source<Profile>(profile));
- notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
- content::Source<Profile>(profile));
}
}
@@ -191,6 +189,24 @@
observer_list_.RemoveObserver(obs);
}
+void ShortcutsBackend::OnOmniboxNavigation(const string16& text,
+ const AutocompleteMatch& match) {
+ const string16 text_lowercase(base::i18n::ToLower(text));
+ const base::Time now(base::Time::Now());
+ for (ShortcutMap::const_iterator it(
+ shortcuts_map_.lower_bound(text_lowercase));
+ it != shortcuts_map_.end() &&
+ StartsWith(it->first, text_lowercase, true); ++it) {
+ if (match.destination_url == it->second.match_core.destination_url) {
+ UpdateShortcut(Shortcut(it->second.id, text, Shortcut::MatchCore(match),
+ now, it->second.number_of_hits + 1));
+ return;
+ }
+ }
+ AddShortcut(Shortcut(base::GenerateGUID(), text, Shortcut::MatchCore(match),
+ now, 1));
+}
+
ShortcutsBackend::~ShortcutsBackend() {
}
@@ -214,45 +230,22 @@
return;
}
- if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
- if (content::Details<const history::URLsDeletedDetails>(details)->
- all_history) {
- DeleteAllShortcuts();
- }
- const URLRows& rows(
- content::Details<const history::URLsDeletedDetails>(details)->rows);
- std::vector<std::string> shortcut_ids;
+ 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();
+ const URLRows& rows(deleted_details->rows);
+ std::vector<std::string> shortcut_ids;
- for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
- ++it) {
- if (std::find_if(
- rows.begin(), rows.end(), URLRow::URLRowHasURL(
- it->second->second.match_core.destination_url)) != rows.end())
- shortcut_ids.push_back(it->first);
- }
- DeleteShortcutsWithIds(shortcut_ids);
- return;
+ for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
+ ++it) {
+ if (std::find_if(
+ rows.begin(), rows.end(), URLRow::URLRowHasURL(
+ it->second->second.match_core.destination_url)) != rows.end())
+ shortcut_ids.push_back(it->first);
}
-
- DCHECK(type == chrome::NOTIFICATION_OMNIBOX_OPENED_URL);
-
- OmniboxLog* log = content::Details<OmniboxLog>(details).ptr();
- string16 text_lowercase(base::i18n::ToLower(log->text));
-
- const AutocompleteMatch& match(log->result.match_at(log->selected_index));
- for (ShortcutMap::const_iterator it(
- shortcuts_map_.lower_bound(text_lowercase));
- it != shortcuts_map_.end() &&
- StartsWith(it->first, text_lowercase, true); ++it) {
- if (match.destination_url == it->second.match_core.destination_url) {
- UpdateShortcut(Shortcut(it->second.id, log->text,
- Shortcut::MatchCore(match), base::Time::Now(),
- it->second.number_of_hits + 1));
- return;
- }
- }
- AddShortcut(Shortcut(base::GenerateGUID(), log->text,
- Shortcut::MatchCore(match), base::Time::Now(), 1));
+ DeleteShortcutsWithIds(shortcut_ids);
}
void ShortcutsBackend::InitInternal() {

Powered by Google App Engine
This is Rietveld 408576698