blob: 52b1e53178e85b720ba46d993eafae10a5c9140a [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/cancellation_flag.h"
namespace base {
class SequencedTaskRunner;
namespace sql {
class Database;
namespace predictors {
// Base class for all tables in the PredictorDatabase.
// Refcounted as it is created and destroyed in the UI thread but all database
// related functions need to happen in the database sequence. The task runner
// for this sequence is provided by the client to the constructor of this class.
class PredictorTableBase
: public base::RefCountedThreadSafe<PredictorTableBase> {
// Returns a SequencedTaskRunner that is used to run tasks on the DB sequence.
base::SequencedTaskRunner* GetTaskRunner();
explicit PredictorTableBase(
scoped_refptr<base::SequencedTaskRunner> db_task_runner);
virtual ~PredictorTableBase();
// DB sequence functions.
virtual void CreateTableIfNonExistent() = 0;
virtual void LogDatabaseStats() = 0;
void Initialize(sql::Database* db);
void SetCancelled();
bool IsCancelled();
sql::Database* DB();
void ResetDB();
bool CantAccessDatabase();
base::CancellationFlag cancelled_;
friend class base::RefCountedThreadSafe<PredictorTableBase>;
scoped_refptr<base::SequencedTaskRunner> db_task_runner_;
sql::Database* db_;
} // namespace predictors