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

Side by Side Diff: chrome/browser/predictors/autocomplete_action_predictor.cc

Issue 2538763002: Data from the autocomplete predictor wasn't deleted immediately when deleting browsing history. (Closed)
Patch Set: move TryDeleteOldEntries in condition Created 4 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/predictors/autocomplete_action_predictor.h" 5 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::vector<AutocompleteActionPredictorTable::Row>* rows = 328 std::vector<AutocompleteActionPredictorTable::Row>* rows =
329 new std::vector<AutocompleteActionPredictorTable::Row>(); 329 new std::vector<AutocompleteActionPredictorTable::Row>();
330 content::BrowserThread::PostTaskAndReply( 330 content::BrowserThread::PostTaskAndReply(
331 content::BrowserThread::DB, FROM_HERE, 331 content::BrowserThread::DB, FROM_HERE,
332 base::Bind(&AutocompleteActionPredictorTable::GetAllRows, table_, rows), 332 base::Bind(&AutocompleteActionPredictorTable::GetAllRows, table_, rows),
333 base::Bind(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(), 333 base::Bind(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(),
334 base::Owned(rows))); 334 base::Owned(rows)));
335 } 335 }
336 336
337 void AutocompleteActionPredictor::DeleteAllRows() { 337 void AutocompleteActionPredictor::DeleteAllRows() {
338 if (!initialized_) 338 DCHECK(initialized_);
339 return;
340 339
341 db_cache_.clear(); 340 db_cache_.clear();
342 db_id_cache_.clear(); 341 db_id_cache_.clear();
343 342
344 if (table_.get()) { 343 if (table_.get()) {
345 content::BrowserThread::PostTask( 344 content::BrowserThread::PostTask(
346 content::BrowserThread::DB, FROM_HERE, 345 content::BrowserThread::DB, FROM_HERE,
347 base::Bind(&AutocompleteActionPredictorTable::DeleteAllRows, table_)); 346 base::Bind(&AutocompleteActionPredictorTable::DeleteAllRows, table_));
348 } 347 }
349 348
350 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.DatabaseAction", 349 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.DatabaseAction",
351 DATABASE_ACTION_DELETE_ALL, DATABASE_ACTION_COUNT); 350 DATABASE_ACTION_DELETE_ALL, DATABASE_ACTION_COUNT);
352 } 351 }
353 352
354 void AutocompleteActionPredictor::DeleteRowsWithURLs( 353 void AutocompleteActionPredictor::DeleteRowsWithURLs(
355 const history::URLRows& rows) { 354 const history::URLRows& rows) {
356 if (!initialized_) 355 DCHECK(initialized_);
357 return;
358 356
359 std::vector<AutocompleteActionPredictorTable::Row::Id> id_list; 357 std::vector<AutocompleteActionPredictorTable::Row::Id> id_list;
360 358
361 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { 359 for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) {
362 if (std::find_if(rows.begin(), rows.end(), 360 if (std::find_if(rows.begin(), rows.end(),
363 history::URLRow::URLRowHasURL(it->first.url)) != 361 history::URLRow::URLRowHasURL(it->first.url)) !=
364 rows.end()) { 362 rows.end()) {
365 const DBIdCacheMap::iterator id_it = db_id_cache_.find(it->first); 363 const DBIdCacheMap::iterator id_it = db_id_cache_.find(it->first);
366 DCHECK(id_it != db_id_cache_.end()); 364 DCHECK(id_it != db_id_cache_.end());
367 id_list.push_back(id_it->second); 365 id_list.push_back(id_it->second);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 const DBCacheKey key = { it->user_text, it->url }; 433 const DBCacheKey key = { it->user_text, it->url };
436 const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; 434 const DBCacheValue value = { it->number_of_hits, it->number_of_misses };
437 db_cache_[key] = value; 435 db_cache_[key] = value;
438 db_id_cache_[key] = it->id; 436 db_id_cache_[key] = it->id;
439 } 437 }
440 438
441 // If the history service is ready, delete any old or invalid entries. 439 // If the history service is ready, delete any old or invalid entries.
442 history::HistoryService* history_service = 440 history::HistoryService* history_service =
443 HistoryServiceFactory::GetForProfile(profile_, 441 HistoryServiceFactory::GetForProfile(profile_,
444 ServiceAccessType::EXPLICIT_ACCESS); 442 ServiceAccessType::EXPLICIT_ACCESS);
445 if (!TryDeleteOldEntries(history_service)) { 443 if (history_service) {
446 // Wait for the notification that the history service is ready and the URL 444 TryDeleteOldEntries(history_service);
447 // DB is loaded. 445 history_service_observer_.Add(history_service);
448 if (history_service)
449 history_service_observer_.Add(history_service);
450 } 446 }
451 } 447 }
452 448
453 bool AutocompleteActionPredictor::TryDeleteOldEntries( 449 void AutocompleteActionPredictor::TryDeleteOldEntries(
454 history::HistoryService* service) { 450 history::HistoryService* service) {
455 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 451 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
456 DCHECK(!profile_->IsOffTheRecord()); 452 DCHECK(!profile_->IsOffTheRecord());
457 DCHECK(!initialized_); 453 DCHECK(!initialized_);
458 454
459 if (!service) 455 if (!service)
460 return false; 456 return;
461 457
462 history::URLDatabase* url_db = service->InMemoryDatabase(); 458 history::URLDatabase* url_db = service->InMemoryDatabase();
463 if (!url_db) 459 if (!url_db)
464 return false; 460 return;
465 461
466 DeleteOldEntries(url_db); 462 DeleteOldEntries(url_db);
467 return true;
468 } 463 }
469 464
470 void AutocompleteActionPredictor::DeleteOldEntries( 465 void AutocompleteActionPredictor::DeleteOldEntries(
471 history::URLDatabase* url_db) { 466 history::URLDatabase* url_db) {
472 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 467 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
473 DCHECK(!profile_->IsOffTheRecord()); 468 DCHECK(!profile_->IsOffTheRecord());
474 DCHECK(!initialized_); 469 DCHECK(!initialized_);
475 DCHECK(table_.get()); 470 DCHECK(table_.get());
476 471
477 std::vector<AutocompleteActionPredictorTable::Row::Id> ids_to_delete; 472 std::vector<AutocompleteActionPredictorTable::Row::Id> ids_to_delete;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 void AutocompleteActionPredictor::Shutdown() { 557 void AutocompleteActionPredictor::Shutdown() {
563 history_service_observer_.RemoveAll(); 558 history_service_observer_.RemoveAll();
564 } 559 }
565 560
566 void AutocompleteActionPredictor::OnURLsDeleted( 561 void AutocompleteActionPredictor::OnURLsDeleted(
567 history::HistoryService* history_service, 562 history::HistoryService* history_service,
568 bool all_history, 563 bool all_history,
569 bool expired, 564 bool expired,
570 const history::URLRows& deleted_rows, 565 const history::URLRows& deleted_rows,
571 const std::set<GURL>& favicon_urls) { 566 const std::set<GURL>& favicon_urls) {
572 if (!initialized_) 567 DCHECK(initialized_);
573 return;
574 568
575 if (all_history) 569 if (all_history)
576 DeleteAllRows(); 570 DeleteAllRows();
577 else 571 else
578 DeleteRowsWithURLs(deleted_rows); 572 DeleteRowsWithURLs(deleted_rows);
579 } 573 }
580 574
581 void AutocompleteActionPredictor::OnHistoryServiceLoaded( 575 void AutocompleteActionPredictor::OnHistoryServiceLoaded(
582 history::HistoryService* history_service) { 576 history::HistoryService* history_service) {
583 TryDeleteOldEntries(history_service); 577 if (!initialized_)
584 history_service_observer_.Remove(history_service); 578 TryDeleteOldEntries(history_service);
585 } 579 }
586 580
587 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { 581 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() {
588 } 582 }
589 583
590 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch( 584 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch(
591 const TransitionalMatch& other) = default; 585 const TransitionalMatch& other) = default;
592 586
593 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { 587 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() {
594 } 588 }
595 589
596 } // namespace predictors 590 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698