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

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

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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_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/file_util.h" 8 #include "base/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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // If there was a history directory (which there won't be for some unit tests) 130 // If there was a history directory (which there won't be for some unit tests)
131 // then insure that the cache has already been saved. 131 // then insure that the cache has already been saved.
132 DCHECK(history_dir_.empty() || !needs_to_be_cached_); 132 DCHECK(history_dir_.empty() || !needs_to_be_cached_);
133 } 133 }
134 134
135 void InMemoryURLIndex::Init() { 135 void InMemoryURLIndex::Init() {
136 PostRestoreFromCacheFileTask(); 136 PostRestoreFromCacheFileTask();
137 } 137 }
138 138
139 void InMemoryURLIndex::ShutDown() { 139 void InMemoryURLIndex::ShutDown() {
140 HistoryService* service =
141 HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
142 if (service)
143 service->RemoveHistoryServiceObserver(this);
sdefresne 2014/10/20 13:15:42 You can use ScopedObserver<> to simplify the code.
140 registrar_.RemoveAll(); 144 registrar_.RemoveAll();
141 cache_reader_tracker_.TryCancelAll(); 145 cache_reader_tracker_.TryCancelAll();
142 shutdown_ = true; 146 shutdown_ = true;
143 base::FilePath path; 147 base::FilePath path;
144 if (!GetCacheFilePath(&path)) 148 if (!GetCacheFilePath(&path))
145 return; 149 return;
146 private_data_tracker_.TryCancelAll(); 150 private_data_tracker_.TryCancelAll();
147 URLIndexPrivateData::WritePrivateDataToCacheFileTask(private_data_, path); 151 URLIndexPrivateData::WritePrivateDataToCacheFileTask(private_data_, path);
148 needs_to_be_cached_ = false; 152 needs_to_be_cached_ = false;
149 } 153 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 OnURLVisited(content::Details<URLVisitedDetails>(details).ptr()); 191 OnURLVisited(content::Details<URLVisitedDetails>(details).ptr());
188 break; 192 break;
189 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: 193 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
190 OnURLsModified( 194 OnURLsModified(
191 content::Details<history::URLsModifiedDetails>(details).ptr()); 195 content::Details<history::URLsModifiedDetails>(details).ptr());
192 break; 196 break;
193 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: 197 case chrome::NOTIFICATION_HISTORY_URLS_DELETED:
194 OnURLsDeleted( 198 OnURLsDeleted(
195 content::Details<history::URLsDeletedDetails>(details).ptr()); 199 content::Details<history::URLsDeletedDetails>(details).ptr());
196 break; 200 break;
197 case chrome::NOTIFICATION_HISTORY_LOADED:
198 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED,
199 content::Source<Profile>(profile_));
200 ScheduleRebuildFromHistory();
201 break;
202 default: 201 default:
203 // For simplicity, the unit tests send us all notifications, even when 202 // For simplicity, the unit tests send us all notifications, even when
204 // we haven't registered for them, so don't assert here. 203 // we haven't registered for them, so don't assert here.
205 break; 204 break;
206 } 205 }
207 } 206 }
208 207
209 void InMemoryURLIndex::OnURLVisited(const URLVisitedDetails* details) { 208 void InMemoryURLIndex::OnURLVisited(const URLVisitedDetails* details) {
210 HistoryService* service = 209 HistoryService* service =
211 HistoryServiceFactory::GetForProfile(profile_, 210 HistoryServiceFactory::GetForProfile(profile_,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // When unable to restore from the cache file delete the cache file, if 291 // When unable to restore from the cache file delete the cache file, if
293 // it exists, and then rebuild from the history database if it's available, 292 // it exists, and then rebuild from the history database if it's available,
294 // otherwise wait until the history database loaded and then rebuild. 293 // otherwise wait until the history database loaded and then rebuild.
295 base::FilePath path; 294 base::FilePath path;
296 if (!GetCacheFilePath(&path) || shutdown_) 295 if (!GetCacheFilePath(&path) || shutdown_)
297 return; 296 return;
298 content::BrowserThread::PostBlockingPoolTask( 297 content::BrowserThread::PostBlockingPoolTask(
299 FROM_HERE, base::Bind(DeleteCacheFile, path)); 298 FROM_HERE, base::Bind(DeleteCacheFile, path));
300 HistoryService* service = 299 HistoryService* service =
301 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); 300 HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
302 if (service && service->backend_loaded()) { 301 if (service && service->backend_loaded()) {
sdefresne 2014/10/20 13:15:41 |service| can only be NULL if running tests, so re
nshaik 2014/10/29 08:43:39 Done.
303 ScheduleRebuildFromHistory(); 302 ScheduleRebuildFromHistory();
304 } else { 303 } else {
305 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, 304 service->AddHistoryServiceObserver(this);
306 content::Source<Profile>(profile_));
307 } 305 }
308 } 306 }
309 } 307 }
310 308
311 // Restoring from the History DB ----------------------------------------------- 309 // Restoring from the History DB -----------------------------------------------
312 310
313 void InMemoryURLIndex::ScheduleRebuildFromHistory() { 311 void InMemoryURLIndex::ScheduleRebuildFromHistory() {
314 HistoryService* service = 312 HistoryService* service =
315 HistoryServiceFactory::GetForProfile(profile_, 313 HistoryServiceFactory::GetForProfile(profile_,
316 Profile::EXPLICIT_ACCESS); 314 Profile::EXPLICIT_ACCESS);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 FROM_HERE, 368 FROM_HERE,
371 base::Bind(DeleteCacheFile, path)); 369 base::Bind(DeleteCacheFile, path));
372 } 370 }
373 } 371 }
374 372
375 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { 373 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) {
376 if (save_cache_observer_) 374 if (save_cache_observer_)
377 save_cache_observer_->OnCacheSaveFinished(succeeded); 375 save_cache_observer_->OnCacheSaveFinished(succeeded);
378 } 376 }
379 377
378 void InMemoryURLIndex::HistoryServiceLoaded(HistoryService* history_service) {
379 ScheduleRebuildFromHistory();
380 history_service->RemoveHistoryServiceObserver(this);
381 }
382
380 } // namespace history 383 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698