| Index: chrome/browser/predictors/predictor_database.cc
|
| diff --git a/chrome/browser/predictors/predictor_database.cc b/chrome/browser/predictors/predictor_database.cc
|
| index c2fb75b6ae4e0662aad9b40733a7582e59b233c6..eaab6418380a77b6d8c92db748a30056c8582073 100644
|
| --- a/chrome/browser/predictors/predictor_database.cc
|
| +++ b/chrome/browser/predictors/predictor_database.cc
|
| @@ -5,7 +5,6 @@
|
| #include "chrome/browser/predictors/predictor_database.h"
|
|
|
| #include "base/bind.h"
|
| -#include "base/file_path.h"
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/stringprintf.h"
|
| @@ -14,7 +13,6 @@
|
| #include "chrome/browser/predictors/resource_prefetch_predictor.h"
|
| #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
|
| #include "chrome/browser/prerender/prerender_field_trial.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "sql/connection.h"
|
| #include "sql/statement.h"
|
| @@ -31,56 +29,40 @@ const FilePath::CharType kPredictorDatabaseName[] =
|
|
|
| namespace predictors {
|
|
|
| -// Refcounted as it is created, initialized and destroyed on a different thread
|
| -// to the DB thread that is required for all methods performing database access.
|
| -class PredictorDatabaseInternal
|
| - : public base::RefCountedThreadSafe<PredictorDatabaseInternal> {
|
| - private:
|
| - friend class base::RefCountedThreadSafe<PredictorDatabaseInternal>;
|
| - friend class PredictorDatabase;
|
| -
|
| - explicit PredictorDatabaseInternal(Profile* profile);
|
| - virtual ~PredictorDatabaseInternal();
|
| -
|
| - // Opens the database file from the profile path. Separated from the
|
| - // constructor to ease construction/destruction of this object on one thread
|
| - // but database access on the DB thread.
|
| - void Initialize();
|
| - void LogDatabaseStats(); // DB Thread.
|
| -
|
| - // Cancels pending DB transactions. Should only be called on the UI thread.
|
| - void SetCancelled();
|
| -
|
| - bool is_resource_prefetch_predictor_enabled_;
|
| - FilePath db_path_;
|
| - scoped_ptr<sql::Connection> db_;
|
| -
|
| - // TODO(shishir): These tables may not need to be refcounted. Maybe move them
|
| - // to using a WeakPtr instead.
|
| - scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_;
|
| - scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(PredictorDatabaseInternal);
|
| -};
|
| -
|
| -
|
| -PredictorDatabaseInternal::PredictorDatabaseInternal(Profile* profile)
|
| - : db_path_(profile->GetPath().Append(kPredictorDatabaseName)),
|
| +PredictorDatabase::PredictorDatabase(
|
| + const FilePath& path,
|
| + bool is_resource_prefetch_predictor_enabled)
|
| + : db_path_(path.Append(kPredictorDatabaseName)),
|
| + is_resource_prefetch_predictor_enabled_(
|
| + is_resource_prefetch_predictor_enabled),
|
| db_(new sql::Connection()),
|
| autocomplete_table_(new AutocompleteActionPredictorTable()),
|
| resource_prefetch_tables_(new ResourcePrefetchPredictorTables()) {
|
| - ResourcePrefetchPredictorConfig config;
|
| - is_resource_prefetch_predictor_enabled_ =
|
| - IsSpeculativeResourcePrefetchingEnabled(profile, &config);
|
| + BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| + base::Bind(&PredictorDatabase::Initialize, this));
|
| }
|
|
|
| -PredictorDatabaseInternal::~PredictorDatabaseInternal() {
|
| +PredictorDatabase::~PredictorDatabase() {
|
| // The connection pointer needs to be deleted on the DB thread since there
|
| // might be a task in progress on the DB thread which uses this connection.
|
| BrowserThread::DeleteSoon(BrowserThread::DB, FROM_HERE, db_.release());
|
| }
|
|
|
| -void PredictorDatabaseInternal::Initialize() {
|
| +scoped_refptr<AutocompleteActionPredictorTable>
|
| + PredictorDatabase::autocomplete_table() {
|
| + return autocomplete_table_;
|
| +}
|
| +
|
| +scoped_refptr<ResourcePrefetchPredictorTables>
|
| + PredictorDatabase::resource_prefetch_tables() {
|
| + return resource_prefetch_tables_;
|
| +}
|
| +
|
| +sql::Connection* PredictorDatabase::GetDatabase() {
|
| + return db_.get();
|
| +}
|
| +
|
| +void PredictorDatabase::Initialize() {
|
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| db_->set_exclusive_locking();
|
| bool success = db_->Open(db_path_);
|
| @@ -94,14 +76,14 @@ void PredictorDatabaseInternal::Initialize() {
|
| LogDatabaseStats();
|
| }
|
|
|
| -void PredictorDatabaseInternal::SetCancelled() {
|
| +void PredictorDatabase::SetCancelled() {
|
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| autocomplete_table_->SetCancelled();
|
| resource_prefetch_tables_->SetCancelled();
|
| }
|
|
|
| -void PredictorDatabaseInternal::LogDatabaseStats() {
|
| +void PredictorDatabase::LogDatabaseStats() {
|
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
|
|
| int64 db_size;
|
| @@ -115,31 +97,4 @@ void PredictorDatabaseInternal::LogDatabaseStats() {
|
| resource_prefetch_tables_->LogDatabaseStats();
|
| }
|
|
|
| -PredictorDatabase::PredictorDatabase(Profile* profile)
|
| - : db_(new PredictorDatabaseInternal(profile)) {
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&PredictorDatabaseInternal::Initialize, db_));
|
| -}
|
| -
|
| -PredictorDatabase::~PredictorDatabase() {
|
| -}
|
| -
|
| -void PredictorDatabase::Shutdown() {
|
| - db_->SetCancelled();
|
| -}
|
| -
|
| -scoped_refptr<AutocompleteActionPredictorTable>
|
| - PredictorDatabase::autocomplete_table() {
|
| - return db_->autocomplete_table_;
|
| -}
|
| -
|
| -scoped_refptr<ResourcePrefetchPredictorTables>
|
| - PredictorDatabase::resource_prefetch_tables() {
|
| - return db_->resource_prefetch_tables_;
|
| -}
|
| -
|
| -sql::Connection* PredictorDatabase::GetDatabase() {
|
| - return db_->db_.get();
|
| -}
|
| -
|
| } // namespace predictors
|
|
|