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

Unified Diff: chrome/browser/predictors/autocomplete_action_predictor.cc

Issue 10918007: Delay predictor DB access until after the first main frame load complete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698