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

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

Issue 352913002: Port HistoryService::ScheduleDBTask to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 registrar_.RemoveAll(); 140 registrar_.RemoveAll();
141 cache_reader_consumer_.CancelAllRequests(); 141 cache_reader_tracker_.TryCancelAll();
142 shutdown_ = true; 142 shutdown_ = true;
143 base::FilePath path; 143 base::FilePath path;
144 if (!GetCacheFilePath(&path)) 144 if (!GetCacheFilePath(&path))
145 return; 145 return;
146 private_data_->CancelPendingUpdates(); 146 private_data_tracker_.TryCancelAll();
147 URLIndexPrivateData::WritePrivateDataToCacheFileTask(private_data_, path); 147 URLIndexPrivateData::WritePrivateDataToCacheFileTask(private_data_, path);
148 needs_to_be_cached_ = false; 148 needs_to_be_cached_ = false;
149 } 149 }
150 150
151 void InMemoryURLIndex::ClearPrivateData() { 151 void InMemoryURLIndex::ClearPrivateData() {
152 private_data_->Clear(); 152 private_data_->Clear();
153 } 153 }
154 154
155 bool InMemoryURLIndex::GetCacheFilePath(base::FilePath* file_path) { 155 bool InMemoryURLIndex::GetCacheFilePath(base::FilePath* file_path) {
156 if (history_dir_.empty()) 156 if (history_dir_.empty())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // For simplicity, the unit tests send us all notifications, even when 203 // For simplicity, the unit tests send us all notifications, even when
204 // we haven't registered for them, so don't assert here. 204 // we haven't registered for them, so don't assert here.
205 break; 205 break;
206 } 206 }
207 } 207 }
208 208
209 void InMemoryURLIndex::OnURLVisited(const URLVisitedDetails* details) { 209 void InMemoryURLIndex::OnURLVisited(const URLVisitedDetails* details) {
210 HistoryService* service = 210 HistoryService* service =
211 HistoryServiceFactory::GetForProfile(profile_, 211 HistoryServiceFactory::GetForProfile(profile_,
212 Profile::EXPLICIT_ACCESS); 212 Profile::EXPLICIT_ACCESS);
213 needs_to_be_cached_ |= private_data_->UpdateURL( 213 needs_to_be_cached_ |= private_data_->UpdateURL(service,
214 service, details->row, languages_, scheme_whitelist_); 214 details->row,
215 languages_,
216 scheme_whitelist_,
217 &private_data_tracker_);
215 } 218 }
216 219
217 void InMemoryURLIndex::OnURLsModified(const URLsModifiedDetails* details) { 220 void InMemoryURLIndex::OnURLsModified(const URLsModifiedDetails* details) {
218 HistoryService* service = 221 HistoryService* service =
219 HistoryServiceFactory::GetForProfile(profile_, 222 HistoryServiceFactory::GetForProfile(profile_,
220 Profile::EXPLICIT_ACCESS); 223 Profile::EXPLICIT_ACCESS);
221 for (URLRows::const_iterator row = details->changed_urls.begin(); 224 for (URLRows::const_iterator row = details->changed_urls.begin();
222 row != details->changed_urls.end(); ++row) 225 row != details->changed_urls.end(); ++row) {
223 needs_to_be_cached_ |= 226 needs_to_be_cached_ |= private_data_->UpdateURL(
224 private_data_->UpdateURL(service, *row, languages_, scheme_whitelist_); 227 service, *row, languages_, scheme_whitelist_, &private_data_tracker_);
228 }
225 } 229 }
226 230
227 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { 231 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) {
228 if (details->all_history) { 232 if (details->all_history) {
229 ClearPrivateData(); 233 ClearPrivateData();
230 needs_to_be_cached_ = true; 234 needs_to_be_cached_ = true;
231 } else { 235 } else {
232 for (URLRows::const_iterator row = details->rows.begin(); 236 for (URLRows::const_iterator row = details->rows.begin();
233 row != details->rows.end(); ++row) 237 row != details->rows.end(); ++row)
234 needs_to_be_cached_ |= private_data_->DeleteURL(row->url()); 238 needs_to_be_cached_ |= private_data_->DeleteURL(row->url());
(...skipping 17 matching lines...) Expand all
252 content::BrowserThread::PostTaskAndReplyWithResult 256 content::BrowserThread::PostTaskAndReplyWithResult
253 <scoped_refptr<URLIndexPrivateData> >( 257 <scoped_refptr<URLIndexPrivateData> >(
254 content::BrowserThread::FILE, FROM_HERE, 258 content::BrowserThread::FILE, FROM_HERE,
255 base::Bind(&URLIndexPrivateData::RestoreFromFile, path, languages_), 259 base::Bind(&URLIndexPrivateData::RestoreFromFile, path, languages_),
256 base::Bind(&InMemoryURLIndex::OnCacheLoadDone, AsWeakPtr())); 260 base::Bind(&InMemoryURLIndex::OnCacheLoadDone, AsWeakPtr()));
257 } 261 }
258 262
259 void InMemoryURLIndex::OnCacheLoadDone( 263 void InMemoryURLIndex::OnCacheLoadDone(
260 scoped_refptr<URLIndexPrivateData> private_data) { 264 scoped_refptr<URLIndexPrivateData> private_data) {
261 if (private_data.get() && !private_data->Empty()) { 265 if (private_data.get() && !private_data->Empty()) {
266 private_data_tracker_.TryCancelAll();
262 private_data_ = private_data; 267 private_data_ = private_data;
263 restored_ = true; 268 restored_ = true;
264 if (restore_cache_observer_) 269 if (restore_cache_observer_)
265 restore_cache_observer_->OnCacheRestoreFinished(true); 270 restore_cache_observer_->OnCacheRestoreFinished(true);
266 } else if (profile_) { 271 } else if (profile_) {
267 // When unable to restore from the cache file delete the cache file, if 272 // When unable to restore from the cache file delete the cache file, if
268 // it exists, and then rebuild from the history database if it's available, 273 // it exists, and then rebuild from the history database if it's available,
269 // otherwise wait until the history database loaded and then rebuild. 274 // otherwise wait until the history database loaded and then rebuild.
270 base::FilePath path; 275 base::FilePath path;
271 if (!GetCacheFilePath(&path) || shutdown_) 276 if (!GetCacheFilePath(&path) || shutdown_)
(...skipping 13 matching lines...) Expand all
285 290
286 // Restoring from the History DB ----------------------------------------------- 291 // Restoring from the History DB -----------------------------------------------
287 292
288 void InMemoryURLIndex::ScheduleRebuildFromHistory() { 293 void InMemoryURLIndex::ScheduleRebuildFromHistory() {
289 HistoryService* service = 294 HistoryService* service =
290 HistoryServiceFactory::GetForProfile(profile_, 295 HistoryServiceFactory::GetForProfile(profile_,
291 Profile::EXPLICIT_ACCESS); 296 Profile::EXPLICIT_ACCESS);
292 service->ScheduleDBTask( 297 service->ScheduleDBTask(
293 new InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask( 298 new InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask(
294 this, languages_, scheme_whitelist_), 299 this, languages_, scheme_whitelist_),
295 &cache_reader_consumer_); 300 &cache_reader_tracker_);
296 } 301 }
297 302
298 void InMemoryURLIndex::DoneRebuidingPrivateDataFromHistoryDB( 303 void InMemoryURLIndex::DoneRebuidingPrivateDataFromHistoryDB(
299 bool succeeded, 304 bool succeeded,
300 scoped_refptr<URLIndexPrivateData> private_data) { 305 scoped_refptr<URLIndexPrivateData> private_data) {
301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 306 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
302 if (succeeded) { 307 if (succeeded) {
308 private_data_tracker_.TryCancelAll();
303 private_data_ = private_data; 309 private_data_ = private_data;
304 PostSaveToCacheFileTask(); // Cache the newly rebuilt index. 310 PostSaveToCacheFileTask(); // Cache the newly rebuilt index.
305 } else { 311 } else {
306 private_data_->Clear(); // Dump the old private data. 312 private_data_->Clear(); // Dump the old private data.
307 // There is no need to do anything with the cache file as it was deleted 313 // There is no need to do anything with the cache file as it was deleted
308 // when the rebuild from the history operation was kicked off. 314 // when the rebuild from the history operation was kicked off.
309 } 315 }
310 restored_ = true; 316 restored_ = true;
311 if (restore_cache_observer_) 317 if (restore_cache_observer_)
312 restore_cache_observer_->OnCacheRestoreFinished(succeeded); 318 restore_cache_observer_->OnCacheRestoreFinished(succeeded);
313 } 319 }
314 320
315 void InMemoryURLIndex::RebuildFromHistory(HistoryDatabase* history_db) { 321 void InMemoryURLIndex::RebuildFromHistory(HistoryDatabase* history_db) {
322 private_data_tracker_.TryCancelAll();
316 private_data_ = URLIndexPrivateData::RebuildFromHistory(history_db, 323 private_data_ = URLIndexPrivateData::RebuildFromHistory(history_db,
317 languages_, 324 languages_,
318 scheme_whitelist_); 325 scheme_whitelist_);
319 } 326 }
320 327
321 // Saving to Cache ------------------------------------------------------------- 328 // Saving to Cache -------------------------------------------------------------
322 329
323 void InMemoryURLIndex::PostSaveToCacheFileTask() { 330 void InMemoryURLIndex::PostSaveToCacheFileTask() {
324 base::FilePath path; 331 base::FilePath path;
325 if (!GetCacheFilePath(&path)) 332 if (!GetCacheFilePath(&path))
(...skipping 17 matching lines...) Expand all
343 base::Bind(DeleteCacheFile, path)); 350 base::Bind(DeleteCacheFile, path));
344 } 351 }
345 } 352 }
346 353
347 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { 354 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) {
348 if (save_cache_observer_) 355 if (save_cache_observer_)
349 save_cache_observer_->OnCacheSaveFinished(succeeded); 356 save_cache_observer_->OnCacheSaveFinished(succeeded);
350 } 357 }
351 358
352 } // namespace history 359 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698