Commit c950d6a3 authored by Alexandr Ilin's avatar Alexandr Ilin Committed by Commit Bot

predictors: Don't initialize database after shutdown

PredictorDatabaseInternal::Initialize() can be called after the shutdown of
PredictorDatabase. In testing scenario it could lead to accessing a database
file in a directory that doesn't exist, because profile directories are deleted
after test.

This CL checks a cancellation flag that is set on PredictorDatabase shutdown
before opening a database file.

This CL also enables the predictor by default on ChromeOS since the disk I/O
issue should be resolved.

Bug: 839886
Change-Id: I27fbdda2cac282a44bd1bac962b27bf11de8520b
Reviewed-on: https://chromium-review.googlesource.com/1092851Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Commit-Queue: Alexandr Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565983}
parent 7e4d618d
......@@ -39,15 +39,7 @@ const char kPreconnectMode[] = "preconnect";
const char kNoPreconnectMode[] = "no-preconnect";
const base::Feature kSpeculativePreconnectFeature{
kSpeculativePreconnectFeatureName,
// TODO(https://crbug.com/839886): Enable the feature on ChromeOS after disk I/O
// flakes are fixed.
#if defined(OS_CHROMEOS)
base::FEATURE_DISABLED_BY_DEFAULT
#else
base::FEATURE_ENABLED_BY_DEFAULT
#endif
};
kSpeculativePreconnectFeatureName, base::FEATURE_ENABLED_BY_DEFAULT};
bool MaybeEnableSpeculativePreconnect(LoadingPredictorConfig* config) {
if (!base::FeatureList::IsEnabled(kSpeculativePreconnectFeature))
......
......@@ -97,6 +97,11 @@ void PredictorDatabaseInternal::Initialize() {
DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
// TODO(tburkard): figure out if we need this.
// db_->set_exclusive_locking();
if (autocomplete_table_->IsCancelled() ||
resource_prefetch_tables_->IsCancelled()) {
return;
}
bool success = db_->Open(db_path_);
if (!success)
......
......@@ -36,6 +36,10 @@ void PredictorTableBase::SetCancelled() {
cancelled_.Set();
}
bool PredictorTableBase::IsCancelled() {
return cancelled_.IsSet();
}
sql::Connection* PredictorTableBase::DB() {
DCHECK(db_task_runner_->RunsTasksInCurrentSequence());
return db_;
......
......@@ -40,6 +40,7 @@ class PredictorTableBase
virtual void LogDatabaseStats() = 0;
void Initialize(sql::Connection* db);
void SetCancelled();
bool IsCancelled();
sql::Connection* DB();
void ResetDB();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment