OLD | NEW |
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_url_index.h" | 5 #include "chrome/browser/history/in_memory_url_index.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 private_data_(new URLIndexPrivateData), | 101 private_data_(new URLIndexPrivateData), |
102 restore_cache_observer_(NULL), | 102 restore_cache_observer_(NULL), |
103 save_cache_observer_(NULL), | 103 save_cache_observer_(NULL), |
104 shutdown_(false), | 104 shutdown_(false), |
105 restored_(false), | 105 restored_(false), |
106 needs_to_be_cached_(false) { | 106 needs_to_be_cached_(false) { |
107 InitializeSchemeWhitelist(&scheme_whitelist_); | 107 InitializeSchemeWhitelist(&scheme_whitelist_); |
108 if (profile) { | 108 if (profile) { |
109 // TODO(mrossetti): Register for language change notifications. | 109 // TODO(mrossetti): Register for language change notifications. |
110 content::Source<Profile> source(profile); | 110 content::Source<Profile> source(profile); |
111 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | |
112 source); | |
113 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); | 111 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
114 } | 112 } |
115 if (history_service_) | 113 if (history_service_) |
116 history_service_->AddObserver(this); | 114 history_service_->AddObserver(this); |
117 } | 115 } |
118 | 116 |
119 // Called only by unit tests. | 117 // Called only by unit tests. |
120 InMemoryURLIndex::InMemoryURLIndex() | 118 InMemoryURLIndex::InMemoryURLIndex() |
121 : profile_(NULL), | 119 : profile_(NULL), |
122 history_service_(nullptr), | 120 history_service_(nullptr), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // Updating -------------------------------------------------------------------- | 180 // Updating -------------------------------------------------------------------- |
183 | 181 |
184 void InMemoryURLIndex::DeleteURL(const GURL& url) { | 182 void InMemoryURLIndex::DeleteURL(const GURL& url) { |
185 private_data_->DeleteURL(url); | 183 private_data_->DeleteURL(url); |
186 } | 184 } |
187 | 185 |
188 void InMemoryURLIndex::Observe(int notification_type, | 186 void InMemoryURLIndex::Observe(int notification_type, |
189 const content::NotificationSource& source, | 187 const content::NotificationSource& source, |
190 const content::NotificationDetails& details) { | 188 const content::NotificationDetails& details) { |
191 switch (notification_type) { | 189 switch (notification_type) { |
192 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: | |
193 OnURLsModified( | |
194 content::Details<history::URLsModifiedDetails>(details).ptr()); | |
195 break; | |
196 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | 190 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
197 OnURLsDeleted( | 191 OnURLsDeleted( |
198 content::Details<history::URLsDeletedDetails>(details).ptr()); | 192 content::Details<history::URLsDeletedDetails>(details).ptr()); |
199 break; | 193 break; |
200 case chrome::NOTIFICATION_HISTORY_LOADED: | 194 case chrome::NOTIFICATION_HISTORY_LOADED: |
201 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED, | 195 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED, |
202 content::Source<Profile>(profile_)); | 196 content::Source<Profile>(profile_)); |
203 ScheduleRebuildFromHistory(); | 197 ScheduleRebuildFromHistory(); |
204 break; | 198 break; |
205 default: | 199 default: |
206 // For simplicity, the unit tests send us all notifications, even when | 200 // For simplicity, the unit tests send us all notifications, even when |
207 // we haven't registered for them, so don't assert here. | 201 // we haven't registered for them, so don't assert here. |
208 break; | 202 break; |
209 } | 203 } |
210 } | 204 } |
211 | 205 |
212 void InMemoryURLIndex::OnURLVisited(HistoryService* history_service, | 206 void InMemoryURLIndex::OnURLVisited(HistoryService* history_service, |
213 ui::PageTransition transition, | 207 ui::PageTransition transition, |
214 const URLRow& row, | 208 const URLRow& row, |
215 const RedirectList& redirects, | 209 const RedirectList& redirects, |
216 base::Time visit_time) { | 210 base::Time visit_time) { |
217 DCHECK_EQ(history_service_, history_service); | 211 DCHECK_EQ(history_service_, history_service); |
218 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, | 212 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, |
219 row, | 213 row, |
220 languages_, | 214 languages_, |
221 scheme_whitelist_, | 215 scheme_whitelist_, |
222 &private_data_tracker_); | 216 &private_data_tracker_); |
223 } | 217 } |
224 | 218 |
225 void InMemoryURLIndex::OnURLsModified(const URLsModifiedDetails* details) { | 219 void InMemoryURLIndex::OnURLsModified(HistoryService* history_service, |
226 HistoryService* service = | 220 const URLRows& changed_urls) { |
227 HistoryServiceFactory::GetForProfile(profile_, | 221 DCHECK_EQ(history_service_, history_service); |
228 Profile::EXPLICIT_ACCESS); | 222 for (const auto& row : changed_urls) { |
229 for (URLRows::const_iterator row = details->changed_urls.begin(); | 223 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, |
230 row != details->changed_urls.end(); | 224 row, |
231 ++row) { | 225 languages_, |
232 needs_to_be_cached_ |= private_data_->UpdateURL( | 226 scheme_whitelist_, |
233 service, *row, languages_, scheme_whitelist_, &private_data_tracker_); | 227 &private_data_tracker_); |
234 } | 228 } |
235 } | 229 } |
236 | 230 |
237 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { | 231 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { |
238 if (details->all_history) { | 232 if (details->all_history) { |
239 ClearPrivateData(); | 233 ClearPrivateData(); |
240 needs_to_be_cached_ = true; | 234 needs_to_be_cached_ = true; |
241 } else { | 235 } else { |
242 for (URLRows::const_iterator row = details->rows.begin(); | 236 for (URLRows::const_iterator row = details->rows.begin(); |
243 row != details->rows.end(); ++row) | 237 row != details->rows.end(); ++row) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 base::Bind(DeleteCacheFile, path)); | 370 base::Bind(DeleteCacheFile, path)); |
377 } | 371 } |
378 } | 372 } |
379 | 373 |
380 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { | 374 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { |
381 if (save_cache_observer_) | 375 if (save_cache_observer_) |
382 save_cache_observer_->OnCacheSaveFinished(succeeded); | 376 save_cache_observer_->OnCacheSaveFinished(succeeded); |
383 } | 377 } |
384 | 378 |
385 } // namespace history | 379 } // namespace history |
OLD | NEW |