Chromium Code Reviews| Index: components/offline_pages/offline_page_metadata_store_sql.h |
| diff --git a/components/offline_pages/offline_page_metadata_store_sql.h b/components/offline_pages/offline_page_metadata_store_sql.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d32d208776cdf145e03b68668c59616a6c4c26f0 |
| --- /dev/null |
| +++ b/components/offline_pages/offline_page_metadata_store_sql.h |
| @@ -0,0 +1,88 @@ |
| +// 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_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| +#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/offline_pages/offline_page_metadata_store.h" |
| + |
| +namespace sql { |
| +class Connection; |
| +class MetaTable; |
| +class Statement; |
| +class StatementID; |
| +} |
| + |
| +namespace base { |
| +class SequencedTaskRunner; |
| +} |
| + |
| +namespace offline_pages { |
| + |
| +// OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore |
| +// which is implemented using a SQLite database. |
| +class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore { |
| + public: |
| + OfflinePageMetadataStoreSQL( |
| + scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
| + const base::FilePath& database_dir, |
| + bool in_memory); |
|
fgorski
2016/03/29 06:50:19
don't expose it here if it is only for testing.
P
bburns
2016/03/30 16:54:40
Done.
|
| + virtual ~OfflinePageMetadataStoreSQL(); |
| + |
| + // Implementation methods |
| + virtual void Load(const LoadCallback& callback); |
| + virtual void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, |
| + const UpdateCallback& callback); |
| + virtual void RemoveOfflinePages(const std::vector<int64_t>& offline_ids, |
| + const UpdateCallback& callback); |
| + virtual void Reset(const ResetCallback& callback); |
| + |
| + private: |
| + // Synchronous implementations, these are run on the background thread |
| + // and actually do the work to access SQL. The implementations above |
| + // simply dispatch to the corresponding *Sync method on the background thread. |
| + // 'runner' is where to run the callback. |
| + void LoadSync(scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + const LoadCallback& callback); |
| + void AddOrUpdateOfflinePageSync( |
| + const OfflinePageItem& offline_page, |
| + scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + const UpdateCallback& callback); |
| + void RemoveOfflinePagesSync( |
| + const std::vector<int64_t>& offline_ids, |
| + scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + const UpdateCallback& callback); |
| + |
| + void NotifyLoadResult(const LoadCallback& callback, |
| + scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + LoadStatus status, |
| + const std::vector<OfflinePageItem>& result); |
| + |
| + // 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_; |
| + |
| + scoped_ptr<sql::Connection> db_; |
| + // Metadatable is used for table storage metadata (e.g. table version, etc) |
| + scoped_ptr<sql::MetaTable> meta_table_; |
| + |
| + // only useful for testing |
| + bool use_in_memory_; |
| + |
| + base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); |
| +}; |
| + |
| +} // namespace offline_pages |
| + |
| +#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ |