Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1076)

Unified Diff: components/offline_pages/offline_page_metadata_store_sql.h

Issue 1834563002: initial add of SQL based storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ff0a27e613b6004d08bb04d9aebd99ac830f0e9e
--- /dev/null
+++ b/components/offline_pages/offline_page_metadata_store_sql.h
@@ -0,0 +1,92 @@
+// 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 <memory>
+#include <vector>
+
+#include "base/files/file_path.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);
+ ~OfflinePageMetadataStoreSQL() 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,
+ const UpdateCallback& callback) override;
+ void Reset(const ResetCallback& callback) override;
+
+ // If true, use an in-memory database to make testing easier.
+ // Only has an effect if you call it before a call to Load(...).
+ // Should only be used for testing.
+ void SetInMemoryDatabaseForTesting(bool in_memory);
+
+ 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 ResetSync(scoped_refptr<base::SingleThreadTaskRunner> runner,
+ const ResetCallback& callback);
+
+ void NotifyLoadResult(scoped_refptr<base::SingleThreadTaskRunner> runner,
+ const LoadCallback& callback,
+ 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_;
+
+ std::unique_ptr<sql::Connection> db_;
+
+ // only useful for testing.
+ bool use_in_memory_;
+
+ base::WeakPtrFactory<OfflinePageMetadataStoreSQL> weak_ptr_factory_;
Scott Hess - ex-Googler 2016/04/25 19:57:55 I am not entirely able to follow whether this adhe
bburns 2016/04/26 23:27:02 I believe that this is covered by the fact that in
Scott Hess - ex-Googler 2016/04/27 15:21:00 My understanding is that you can't run is_valid()
bburns 2016/04/27 19:59:21 So I think that this is covered because all of the
Scott Hess - ex-Googler 2016/04/27 21:16:45 base::Bind knows how to use a weak pointer as a ta
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL);
+};
+
+} // namespace offline_pages
+
+#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_

Powered by Google App Engine
This is Rietveld 408576698