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

Side by Side Diff: chrome/browser/history/in_memory_history_backend.cc

Issue 808123003: Eliminate sending NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update unittest Created 5 years, 11 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 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/history/in_memory_history_backend.h" 5 #include "chrome/browser/history/in_memory_history_backend.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // runs without a browser process. generate_profile should really create 54 // runs without a browser process. generate_profile should really create
55 // a browser process, at which point this check can then be nuked. 55 // a browser process, at which point this check can then be nuked.
56 if (!g_browser_process) 56 if (!g_browser_process)
57 return; 57 return;
58 58
59 // Register for the notifications we care about. 59 // Register for the notifications we care about.
60 // We only want notifications for the associated profile. 60 // We only want notifications for the associated profile.
61 content::Source<Profile> source(profile_); 61 content::Source<Profile> source(profile_);
62 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); 62 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source);
63 registrar_.Add( 63 registrar_.Add(
64 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, source);
65 registrar_.Add(
66 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source); 64 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source);
67 } 65 }
68 66
69 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( 67 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword(
70 KeywordID keyword_id) { 68 KeywordID keyword_id) {
71 // For simplicity, this will not remove the corresponding URLRows, but 69 // For simplicity, this will not remove the corresponding URLRows, but
72 // this is okay, as the main database does not do so either. 70 // this is okay, as the main database does not do so either.
73 db_->DeleteAllSearchTermsForKeyword(keyword_id); 71 db_->DeleteAllSearchTermsForKeyword(keyword_id);
74 } 72 }
75 73
76 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, 74 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service,
77 ui::PageTransition transition, 75 ui::PageTransition transition,
78 const URLRow& row, 76 const URLRow& row,
79 const RedirectList& redirects, 77 const RedirectList& redirects,
80 base::Time visit_time) { 78 base::Time visit_time) {
81 OnURLVisitedOrModified(row); 79 OnURLVisitedOrModified(row);
82 } 80 }
83 81
84 void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service, 82 void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service,
85 const URLRows& changed_urls) { 83 const URLRows& changed_urls) {
86 for (const auto& row : changed_urls) { 84 for (const auto& row : changed_urls) {
87 OnURLVisitedOrModified(row); 85 OnURLVisitedOrModified(row);
88 } 86 }
89 } 87 }
90 88
89 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
90 HistoryService* history_service,
91 const URLRow& row,
92 KeywordID keyword_id,
93 const base::string16& term) {
94 DCHECK(row.id());
95 db_->InsertOrUpdateURLRowByID(row);
96 db_->SetKeywordSearchTermsForURL(row.id(), keyword_id, term);
97 }
98
91 void InMemoryHistoryBackend::Observe( 99 void InMemoryHistoryBackend::Observe(
92 int type, 100 int type,
93 const content::NotificationSource& source, 101 const content::NotificationSource& source,
94 const content::NotificationDetails& details) { 102 const content::NotificationDetails& details) {
95 switch (type) { 103 switch (type) {
96 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED:
97 OnKeywordSearchTermUpdated(
98 *content::Details<KeywordSearchUpdatedDetails>(details).ptr());
99 break;
100 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED: 104 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED:
101 OnKeywordSearchTermDeleted( 105 OnKeywordSearchTermDeleted(
102 *content::Details<KeywordSearchDeletedDetails>(details).ptr()); 106 *content::Details<KeywordSearchDeletedDetails>(details).ptr());
103 break; 107 break;
104 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: 108 case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
105 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr()); 109 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr());
106 break; 110 break;
107 default: 111 default:
108 // For simplicity, the unit tests send us all notifications, even when 112 // For simplicity, the unit tests send us all notifications, even when
109 // we haven't registered for them, so don't assert here. 113 // we haven't registered for them, so don't assert here.
(...skipping 24 matching lines...) Expand all
134 138
135 // Delete all matching URLs in our database. 139 // Delete all matching URLs in our database.
136 for (URLRows::const_iterator row = details.rows.begin(); 140 for (URLRows::const_iterator row = details.rows.begin();
137 row != details.rows.end(); ++row) { 141 row != details.rows.end(); ++row) {
138 // This will also delete the corresponding keyword search term. 142 // This will also delete the corresponding keyword search term.
139 // Ignore errors, as we typically only cache a subset of URLRows. 143 // Ignore errors, as we typically only cache a subset of URLRows.
140 db_->DeleteURLRow(row->id()); 144 db_->DeleteURLRow(row->id());
141 } 145 }
142 } 146 }
143 147
144 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
145 const KeywordSearchUpdatedDetails& details) {
146 DCHECK(details.url_row.id());
147 db_->InsertOrUpdateURLRowByID(details.url_row);
148 db_->SetKeywordSearchTermsForURL(
149 details.url_row.id(), details.keyword_id, details.term);
150 }
151
152 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( 148 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted(
153 const KeywordSearchDeletedDetails& details) { 149 const KeywordSearchDeletedDetails& details) {
154 // For simplicity, this will not remove the corresponding URLRow, but this is 150 // For simplicity, this will not remove the corresponding URLRow, but this is
155 // okay, as the main database does not do so either. 151 // okay, as the main database does not do so either.
156 db_->DeleteKeywordSearchTermForURL(details.url_row_id); 152 db_->DeleteKeywordSearchTermForURL(details.url_row_id);
157 } 153 }
158 154
159 } // namespace history 155 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_history_backend.h ('k') | components/history/core/browser/history_service_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698