| 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/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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const DBCacheKey key = { it->user_text, it->url }; | 435 const DBCacheKey key = { it->user_text, it->url }; |
| 436 const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; | 436 const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; |
| 437 db_cache_[key] = value; | 437 db_cache_[key] = value; |
| 438 db_id_cache_[key] = it->id; | 438 db_id_cache_[key] = it->id; |
| 439 } | 439 } |
| 440 | 440 |
| 441 // If the history service is ready, delete any old or invalid entries. | 441 // If the history service is ready, delete any old or invalid entries. |
| 442 history::HistoryService* history_service = | 442 history::HistoryService* history_service = |
| 443 HistoryServiceFactory::GetForProfile(profile_, | 443 HistoryServiceFactory::GetForProfile(profile_, |
| 444 ServiceAccessType::EXPLICIT_ACCESS); | 444 ServiceAccessType::EXPLICIT_ACCESS); |
| 445 if (!TryDeleteOldEntries(history_service)) { | 445 TryDeleteOldEntries(history_service); |
| 446 // Wait for the notification that the history service is ready and the URL | 446 if (history_service) |
| 447 // DB is loaded. | 447 history_service_observer_.Add(history_service); |
| 448 if (history_service) | |
| 449 history_service_observer_.Add(history_service); | |
| 450 } | |
| 451 } | 448 } |
| 452 | 449 |
| 453 bool AutocompleteActionPredictor::TryDeleteOldEntries( | 450 void AutocompleteActionPredictor::TryDeleteOldEntries( |
| 454 history::HistoryService* service) { | 451 history::HistoryService* service) { |
| 455 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 452 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 456 DCHECK(!profile_->IsOffTheRecord()); | 453 DCHECK(!profile_->IsOffTheRecord()); |
| 457 DCHECK(!initialized_); | 454 DCHECK(!initialized_); |
| 458 | 455 |
| 459 if (!service) | 456 if (!service) |
| 460 return false; | 457 return; |
| 461 | 458 |
| 462 history::URLDatabase* url_db = service->InMemoryDatabase(); | 459 history::URLDatabase* url_db = service->InMemoryDatabase(); |
| 463 if (!url_db) | 460 if (!url_db) |
| 464 return false; | 461 return; |
| 465 | 462 |
| 466 DeleteOldEntries(url_db); | 463 DeleteOldEntries(url_db); |
| 467 return true; | |
| 468 } | 464 } |
| 469 | 465 |
| 470 void AutocompleteActionPredictor::DeleteOldEntries( | 466 void AutocompleteActionPredictor::DeleteOldEntries( |
| 471 history::URLDatabase* url_db) { | 467 history::URLDatabase* url_db) { |
| 472 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 468 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 473 DCHECK(!profile_->IsOffTheRecord()); | 469 DCHECK(!profile_->IsOffTheRecord()); |
| 474 DCHECK(!initialized_); | 470 DCHECK(!initialized_); |
| 475 DCHECK(table_.get()); | 471 DCHECK(table_.get()); |
| 476 | 472 |
| 477 std::vector<AutocompleteActionPredictorTable::Row::Id> ids_to_delete; | 473 std::vector<AutocompleteActionPredictorTable::Row::Id> ids_to_delete; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 void AutocompleteActionPredictor::Shutdown() { | 558 void AutocompleteActionPredictor::Shutdown() { |
| 563 history_service_observer_.RemoveAll(); | 559 history_service_observer_.RemoveAll(); |
| 564 } | 560 } |
| 565 | 561 |
| 566 void AutocompleteActionPredictor::OnURLsDeleted( | 562 void AutocompleteActionPredictor::OnURLsDeleted( |
| 567 history::HistoryService* history_service, | 563 history::HistoryService* history_service, |
| 568 bool all_history, | 564 bool all_history, |
| 569 bool expired, | 565 bool expired, |
| 570 const history::URLRows& deleted_rows, | 566 const history::URLRows& deleted_rows, |
| 571 const std::set<GURL>& favicon_urls) { | 567 const std::set<GURL>& favicon_urls) { |
| 572 if (!initialized_) | 568 DCHECK(initialized_); |
| 573 return; | |
| 574 | 569 |
| 575 if (all_history) | 570 if (all_history) |
| 576 DeleteAllRows(); | 571 DeleteAllRows(); |
| 577 else | 572 else |
| 578 DeleteRowsWithURLs(deleted_rows); | 573 DeleteRowsWithURLs(deleted_rows); |
| 579 } | 574 } |
| 580 | 575 |
| 581 void AutocompleteActionPredictor::OnHistoryServiceLoaded( | 576 void AutocompleteActionPredictor::OnHistoryServiceLoaded( |
| 582 history::HistoryService* history_service) { | 577 history::HistoryService* history_service) { |
| 583 TryDeleteOldEntries(history_service); | 578 if (!initialized_) |
| 584 history_service_observer_.Remove(history_service); | 579 TryDeleteOldEntries(history_service); |
| 585 } | 580 } |
| 586 | 581 |
| 587 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 582 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 588 } | 583 } |
| 589 | 584 |
| 590 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch( | 585 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch( |
| 591 const TransitionalMatch& other) = default; | 586 const TransitionalMatch& other) = default; |
| 592 | 587 |
| 593 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 588 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 594 } | 589 } |
| 595 | 590 |
| 596 } // namespace predictors | 591 } // namespace predictors |
| OLD | NEW |