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

Side by Side Diff: chrome/browser/history/in_memory_history_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 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // TODO(evanm): this is currently necessitated by generate_profile, which 53 // TODO(evanm): this is currently necessitated by generate_profile, which
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);
63 registrar_.Add( 62 registrar_.Add(
64 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, source); 63 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, source);
65 registrar_.Add( 64 registrar_.Add(
66 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source); 65 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source);
67 } 66 }
68 67
69 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( 68 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword(
70 KeywordID keyword_id) { 69 KeywordID keyword_id) {
71 // For simplicity, this will not remove the corresponding URLRows, but 70 // For simplicity, this will not remove the corresponding URLRows, but
72 // this is okay, as the main database does not do so either. 71 // this is okay, as the main database does not do so either.
73 db_->DeleteAllSearchTermsForKeyword(keyword_id); 72 db_->DeleteAllSearchTermsForKeyword(keyword_id);
74 } 73 }
75 74
76 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, 75 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service,
77 ui::PageTransition transition, 76 ui::PageTransition transition,
78 const URLRow& row, 77 const URLRow& row,
79 const RedirectList& redirects, 78 const RedirectList& redirects,
80 base::Time visit_time) { 79 base::Time visit_time) {
81 OnURLVisitedOrModified(row); 80 OnURLVisitedOrModified(row);
82 } 81 }
83 82
84 void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service, 83 void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service,
85 const URLRows& changed_urls) { 84 const URLRows& changed_urls) {
86 for (const auto& row : changed_urls) { 85 for (const auto& row : changed_urls) {
87 OnURLVisitedOrModified(row); 86 OnURLVisitedOrModified(row);
88 } 87 }
89 } 88 }
90 89
90 void InMemoryHistoryBackend::OnURLsDeleted(HistoryService* history_service,
91 const URLsDeletedDetails& details) {
92 DCHECK(db_);
93
94 if (details.all_history) {
95 // When all history is deleted, the individual URLs won't be listed. Just
96 // create a new database to quickly clear everything out.
97 db_.reset(new InMemoryDatabase);
98 if (!db_->InitFromScratch())
99 db_.reset();
100 return;
101 }
102
103 // Delete all matching URLs in our database.
104 for (URLRows::const_iterator row = details.rows.begin();
sdefresne 2014/12/04 17:21:13 nit: you can use the new c++11 for loops here too.
nshaik 2014/12/07 09:34:50 Done.
105 row != details.rows.end(); ++row) {
106 // This will also delete the corresponding keyword search term.
107 // Ignore errors, as we typically only cache a subset of URLRows.
108 db_->DeleteURLRow(row->id());
109 }
110 }
111
91 void InMemoryHistoryBackend::Observe( 112 void InMemoryHistoryBackend::Observe(
92 int type, 113 int type,
93 const content::NotificationSource& source, 114 const content::NotificationSource& source,
94 const content::NotificationDetails& details) { 115 const content::NotificationDetails& details) {
95 switch (type) { 116 switch (type) {
96 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: 117 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED:
97 OnKeywordSearchTermUpdated( 118 OnKeywordSearchTermUpdated(
98 *content::Details<KeywordSearchUpdatedDetails>(details).ptr()); 119 *content::Details<KeywordSearchUpdatedDetails>(details).ptr());
99 break; 120 break;
100 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED: 121 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED:
101 OnKeywordSearchTermDeleted( 122 OnKeywordSearchTermDeleted(
102 *content::Details<KeywordSearchDeletedDetails>(details).ptr()); 123 *content::Details<KeywordSearchDeletedDetails>(details).ptr());
103 break; 124 break;
104 case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
105 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr());
106 break;
107 default: 125 default:
108 // For simplicity, the unit tests send us all notifications, even when 126 // For simplicity, the unit tests send us all notifications, even when
109 // we haven't registered for them, so don't assert here. 127 // we haven't registered for them, so don't assert here.
110 break; 128 break;
111 } 129 }
112 } 130 }
113 131
114 void InMemoryHistoryBackend::OnURLVisitedOrModified(const URLRow& url_row) { 132 void InMemoryHistoryBackend::OnURLVisitedOrModified(const URLRow& url_row) {
115 DCHECK(db_); 133 DCHECK(db_);
116 DCHECK(url_row.id()); 134 DCHECK(url_row.id());
117 if (url_row.typed_count() || db_->GetKeywordSearchTermRow(url_row.id(), NULL)) 135 if (url_row.typed_count() || db_->GetKeywordSearchTermRow(url_row.id(), NULL))
118 db_->InsertOrUpdateURLRowByID(url_row); 136 db_->InsertOrUpdateURLRowByID(url_row);
119 else 137 else
120 db_->DeleteURLRow(url_row.id()); 138 db_->DeleteURLRow(url_row.id());
121 } 139 }
122 140
123 void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) {
124 DCHECK(db_);
125
126 if (details.all_history) {
127 // When all history is deleted, the individual URLs won't be listed. Just
128 // create a new database to quickly clear everything out.
129 db_.reset(new InMemoryDatabase);
130 if (!db_->InitFromScratch())
131 db_.reset();
132 return;
133 }
134
135 // Delete all matching URLs in our database.
136 for (URLRows::const_iterator row = details.rows.begin();
137 row != details.rows.end(); ++row) {
138 // This will also delete the corresponding keyword search term.
139 // Ignore errors, as we typically only cache a subset of URLRows.
140 db_->DeleteURLRow(row->id());
141 }
142 }
143
144 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated( 141 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
145 const KeywordSearchUpdatedDetails& details) { 142 const KeywordSearchUpdatedDetails& details) {
146 DCHECK(details.url_row.id()); 143 DCHECK(details.url_row.id());
147 db_->InsertOrUpdateURLRowByID(details.url_row); 144 db_->InsertOrUpdateURLRowByID(details.url_row);
148 db_->SetKeywordSearchTermsForURL( 145 db_->SetKeywordSearchTermsForURL(
149 details.url_row.id(), details.keyword_id, details.term); 146 details.url_row.id(), details.keyword_id, details.term);
150 } 147 }
151 148
152 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( 149 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted(
153 const KeywordSearchDeletedDetails& details) { 150 const KeywordSearchDeletedDetails& details) {
154 // For simplicity, this will not remove the corresponding URLRow, but this is 151 // For simplicity, this will not remove the corresponding URLRow, but this is
155 // okay, as the main database does not do so either. 152 // okay, as the main database does not do so either.
156 db_->DeleteKeywordSearchTermForURL(details.url_row_id); 153 db_->DeleteKeywordSearchTermForURL(details.url_row_id);
157 } 154 }
158 155
159 } // namespace history 156 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698