Chromium Code Reviews| Index: components/previews/core/previews_opt_out_store_sql.h |
| diff --git a/components/previews/core/previews_opt_out_store_sql.h b/components/previews/core/previews_opt_out_store_sql.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a7aff744aada54e4f8b18c5651e5f45bb3b5cb0 |
| --- /dev/null |
| +++ b/components/previews/core/previews_opt_out_store_sql.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2016 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. |
| + |
| +#ifndef COMPONENTS_PREVIEWS_PREVIEWS_OPT_OUT_STORE_SQL_H_ |
| +#define COMPONENTS_PREVIEWS_PREVIEWS_OPT_OUT_STORE_SQL_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "components/previews/core/previews_opt_out_store.h" |
| + |
| +namespace base { |
| +class SequencedTaskRunner; |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace previews { |
| + |
| +// PreviewsOptOutStoreSQL is an instance of PreviewsOptOutStore |
| +// which is implemented using a SQLite database. |
| +class PreviewsOptOutStoreSQL : public PreviewsOptOutStore { |
| + public: |
| + PreviewsOptOutStoreSQL( |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| + scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| + const base::FilePath& database_dir); |
| + ~PreviewsOptOutStoreSQL() override; |
| + |
| + // PreviewsOptOutStore implementation: |
| + void AddPreviewNavigation(bool opt_out, |
| + const std::string& host_name, |
| + PreviewsType type, |
| + base::Time now) override; |
| + void LoadBlackList(LoadBlackListCallback callback) override; |
| + |
| + private: |
| + // Synchronous implementation, this is run on the background thread |
| + // and actually does the work to access SQL. |
| + static void LoadBlackListSync( |
| + sql::Connection* db, |
| + const base::FilePath& path, |
| + bool needs_initialization, |
| + scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + LoadBlackListCallback callback); |
| + |
| + // Thread this object is accessed on. |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + |
| + // Background thread where all SQL access should be run. |
| + scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| + |
| + // Path to the database on disk. |
| + base::FilePath db_file_path_; |
|
tbansal1
2016/10/04 15:01:21
can this be const?
RyanSturm
2016/10/04 19:10:23
Done.
|
| + |
| + // SQL connection to the SQLite database. |
| + std::unique_ptr<sql::Connection> db_; |
| + |
| + // Whether the database initialization was started yet. |
| + bool initialized_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PreviewsOptOutStoreSQL); |
| +}; |
| + |
| +} // namespace previews |
| + |
| +#endif // COMPONENTS_PREVIEWS_PREVIEWS_OPT_OUT_STORE_SQL_H_ |