| Index: chrome/browser/predictors/autocomplete_action_predictor.cc
|
| diff --git a/chrome/browser/predictors/autocomplete_action_predictor.cc b/chrome/browser/predictors/autocomplete_action_predictor.cc
|
| index ddd6afb99a6b06f2546f2d9df78d980a3a5035b2..4a4408e5a492bf06a2d481bf3be6b40c3f228b05 100644
|
| --- a/chrome/browser/predictors/autocomplete_action_predictor.cc
|
| +++ b/chrome/browser/predictors/autocomplete_action_predictor.cc
|
| @@ -102,16 +102,11 @@ AutocompleteActionPredictor::AutocompleteActionPredictor(Profile* profile)
|
| table_ =
|
| PredictorDatabaseFactory::GetForProfile(profile_)->autocomplete_table();
|
|
|
| - // Create local caches using the database as loaded. We will garbage collect
|
| - // rows from the caches and the database once the history service is
|
| - // available.
|
| - std::vector<AutocompleteActionPredictorTable::Row>* rows =
|
| - new std::vector<AutocompleteActionPredictorTable::Row>();
|
| - content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
|
| - FROM_HERE,
|
| - base::Bind(&AutocompleteActionPredictorTable::GetAllRows, table_, rows),
|
| - base::Bind(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(),
|
| - base::Owned(rows)));
|
| + // Observe all main frame loads so we can wait for the first to complete
|
| + // before accessing DB and IO threads to build the local cache.
|
| + notification_registrar_.Add(this,
|
| + content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| + content::NotificationService::AllSources());
|
| }
|
| }
|
|
|
| @@ -233,6 +228,14 @@ void AutocompleteActionPredictor::Observe(
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| switch (type) {
|
| + case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
|
| + CreateLocalCachesFromDatabase();
|
| + notification_registrar_.Remove(
|
| + this,
|
| + content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| + content::NotificationService::AllSources());
|
| + break;
|
| +
|
| case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
|
| DCHECK(initialized_);
|
| const content::Details<const history::URLsDeletedDetails>
|
| @@ -272,6 +275,19 @@ void AutocompleteActionPredictor::Observe(
|
| }
|
| }
|
|
|
| +void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() {
|
| + // Create local caches using the database as loaded. We will garbage collect
|
| + // rows from the caches and the database once the history service is
|
| + // available.
|
| + std::vector<AutocompleteActionPredictorTable::Row>* rows =
|
| + new std::vector<AutocompleteActionPredictorTable::Row>();
|
| + content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
|
| + FROM_HERE,
|
| + base::Bind(&AutocompleteActionPredictorTable::GetAllRows, table_, rows),
|
| + base::Bind(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(),
|
| + base::Owned(rows)));
|
| +}
|
| +
|
| void AutocompleteActionPredictor::DeleteAllRows() {
|
| if (!initialized_)
|
| return;
|
|
|