| Index: components/offline_pages/background/request_queue_store_sql.h
|
| diff --git a/components/offline_pages/offline_page_metadata_store_sql.h b/components/offline_pages/background/request_queue_store_sql.h
|
| similarity index 52%
|
| copy from components/offline_pages/offline_page_metadata_store_sql.h
|
| copy to components/offline_pages/background/request_queue_store_sql.h
|
| index 8a480293f90bb5f2007b36c79b93d8a606cfc805..1e04420b7ab482ac6f7897553315a8852b4af768 100644
|
| --- a/components/offline_pages/offline_page_metadata_store_sql.h
|
| +++ b/components/offline_pages/background/request_queue_store_sql.h
|
| @@ -2,8 +2,8 @@
|
| // 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_
|
| +#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
|
| +#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
|
|
|
| #include <stdint.h>
|
|
|
| @@ -12,7 +12,7 @@
|
|
|
| #include "base/files/file_path.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "components/offline_pages/offline_page_metadata_store.h"
|
| +#include "components/offline_pages/background/request_queue_store.h"
|
|
|
| namespace base {
|
| class SequencedTaskRunner;
|
| @@ -24,21 +24,20 @@ class Connection;
|
|
|
| namespace offline_pages {
|
|
|
| -// OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore
|
| -// which is implemented using a SQLite database.
|
| -class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
|
| +// SQLite implementation of RequestQueueStore.
|
| +class RequestQueueStoreSQL : public RequestQueueStore {
|
| public:
|
| - OfflinePageMetadataStoreSQL(
|
| + RequestQueueStoreSQL(
|
| scoped_refptr<base::SequencedTaskRunner> background_task_runner,
|
| const base::FilePath& database_dir);
|
| - ~OfflinePageMetadataStoreSQL() override;
|
| + ~RequestQueueStoreSQL() override;
|
|
|
| - // Implementation methods.
|
| - void Load(const LoadCallback& callback) override;
|
| - void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page,
|
| - const UpdateCallback& callback) override;
|
| - void RemoveOfflinePages(const std::vector<int64_t>& offline_ids,
|
| + // RequestQueueStore implementation.
|
| + void GetRequests(const GetRequestsCallback& callback) override;
|
| + void AddOrUpdateRequest(const SavePageRequest& offline_page,
|
| const UpdateCallback& callback) override;
|
| + void RemoveRequests(const std::vector<int64_t>& request_ids,
|
| + const RemoveCallback& callback) override;
|
| void Reset(const ResetCallback& callback) override;
|
|
|
| private:
|
| @@ -46,40 +45,46 @@ class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
|
| // 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.
|
| - static void LoadSync(sql::Connection* db,
|
| - const base::FilePath& path,
|
| - scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| - const LoadCallback& callback);
|
| - static void AddOrUpdateOfflinePageSync(
|
| - const OfflinePageItem& offline_page,
|
| + static void GetRequestsSync(
|
| sql::Connection* db,
|
| scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| - const UpdateCallback& callback);
|
| - static void RemoveOfflinePagesSync(
|
| - const std::vector<int64_t>& offline_ids,
|
| + const GetRequestsCallback& callback);
|
| + static void AddOrUpdateRequestSync(
|
| sql::Connection* db,
|
| scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| + const SavePageRequest& offline_page,
|
| const UpdateCallback& callback);
|
| + static void RemoveRequestsSync(
|
| + sql::Connection* db,
|
| + scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| + const std::vector<int64_t>& request_ids,
|
| + const RemoveCallback& callback);
|
| static void ResetSync(std::unique_ptr<sql::Connection> db,
|
| scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| const ResetCallback& callback);
|
|
|
| - static void NotifyLoadResult(
|
| + // Used to initialize DB connection.
|
| + static void OpenConnectionSync(
|
| + sql::Connection* db,
|
| scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| - const LoadCallback& callback,
|
| - LoadStatus status,
|
| - const std::vector<OfflinePageItem>& result);
|
| + const base::FilePath& path,
|
| + const base::Callback<void(bool)>& callback);
|
| + void OpenConnection();
|
| + void OnOpenConnectionDone(bool success);
|
|
|
| // 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_;
|
| +
|
| + // Database connection.
|
| std::unique_ptr<sql::Connection> db_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL);
|
| + base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_;
|
| + DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL);
|
| };
|
|
|
| } // namespace offline_pages
|
|
|
| -#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_
|
| +#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
|
|
|