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

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 228521)
+++ 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,25 @@
observer_list_.RemoveObserver(obs);
}
+void ShortcutsBackend::OnOmniboxNavigation(const string16& text,
+ const AutocompleteMatch& match) {
+ string16 text_lowercase(base::i18n::ToLower(text));
Bart N. 2013/10/14 21:31:54 const
Peter Kasting 2013/10/16 01:28:55 I agree, and I made the change here, but note that
+
+ for (ShortcutMap::const_iterator it(
Bart N. 2013/10/14 21:31:54 Hmmm... why don't you use GUID -> shortcut iterato
Peter Kasting 2013/10/16 01:28:55 I'm confused. How is using the GUID map useful?
Bart N. 2013/10/16 17:42:47 Sorry, my mistake. I thought that this was a URL h
+ 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),
+ base::Time::Now(),
Bart N. 2013/10/14 21:31:54 For consistency and performance, you should take t
Peter Kasting 2013/10/16 01:28:55 Done.
+ it->second.number_of_hits + 1));
+ return;
+ }
+ }
+ AddShortcut(Shortcut(base::GenerateGUID(), text, Shortcut::MatchCore(match),
+ base::Time::Now(), 1));
Bart N. 2013/10/14 21:31:54 Replace it with "now" introduced in previous step.
Peter Kasting 2013/10/16 01:28:55 Done.
+}
+
ShortcutsBackend::~ShortcutsBackend() {
}
@@ -214,45 +231,23 @@
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;
-
- 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;
+ DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type);
+ if (content::Details<const history::URLsDeletedDetails>(details)->
Bart N. 2013/10/14 21:31:54 Style: -> should be on the second line.
Peter Kasting 2013/10/16 01:28:55 Operators go on ends of lines, not starts. But I
Bart N. 2013/10/16 17:42:47 Interesting, unlike the internal Google style.
+ all_history) {
+ DeleteAllShortcuts();
}
+ const URLRows& rows(
+ content::Details<const history::URLsDeletedDetails>(details)->rows);
+ std::vector<std::string> shortcut_ids;
- 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;
- }
+ 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);
}
- 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