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

Side by Side Diff: components/offline_pages/background/request_queue_store_sql.h

Issue 2053163002: [Offline pages] Adding persistent request queue based on SQLite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "components/offline_pages/offline_page_metadata_store.h" 15 #include "components/offline_pages/background/request_queue_store.h"
16 16
17 namespace base { 17 namespace base {
18 class SequencedTaskRunner; 18 class SequencedTaskRunner;
19 } 19 }
20 20
21 namespace sql { 21 namespace sql {
22 class Connection; 22 class Connection;
23 } 23 }
24 24
25 namespace offline_pages { 25 namespace offline_pages {
26 26
27 // OfflinePageMetadataStoreSQL is an instance of OfflinePageMetadataStore 27 // SQLite implementation of RequestQueueStore.
28 // which is implemented using a SQLite database. 28 class RequestQueueStoreSQL : public RequestQueueStore {
29 class OfflinePageMetadataStoreSQL : public OfflinePageMetadataStore {
30 public: 29 public:
31 OfflinePageMetadataStoreSQL( 30 RequestQueueStoreSQL(
32 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 31 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
33 const base::FilePath& database_dir); 32 const base::FilePath& database_dir);
34 ~OfflinePageMetadataStoreSQL() override; 33 ~RequestQueueStoreSQL() override;
35 34
36 // Implementation methods. 35 // RequestQueueStore implementation.
37 void Load(const LoadCallback& callback) override; 36 void GetRequests(const GetRequestsCallback& callback) override;
38 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, 37 void AddOrUpdateRequest(const SavePageRequest& offline_page,
39 const UpdateCallback& callback) override;
40 void RemoveOfflinePages(const std::vector<int64_t>& offline_ids,
41 const UpdateCallback& callback) override; 38 const UpdateCallback& callback) override;
39 void RemoveRequests(const std::vector<int64_t>& request_ids,
40 const RemoveCallback& callback) override;
42 void Reset(const ResetCallback& callback) override; 41 void Reset(const ResetCallback& callback) override;
43 42
44 private: 43 private:
45 // Synchronous implementations, these are run on the background thread 44 // Synchronous implementations, these are run on the background thread
46 // and actually do the work to access SQL. The implementations above 45 // and actually do the work to access SQL. The implementations above
47 // simply dispatch to the corresponding *Sync method on the background thread. 46 // simply dispatch to the corresponding *Sync method on the background thread.
48 // 'runner' is where to run the callback. 47 // 'runner' is where to run the callback.
49 static void LoadSync(sql::Connection* db, 48 static void GetRequestsSync(
50 const base::FilePath& path,
51 scoped_refptr<base::SingleThreadTaskRunner> runner,
52 const LoadCallback& callback);
53 static void AddOrUpdateOfflinePageSync(
54 const OfflinePageItem& offline_page,
55 sql::Connection* db, 49 sql::Connection* db,
56 scoped_refptr<base::SingleThreadTaskRunner> runner, 50 scoped_refptr<base::SingleThreadTaskRunner> runner,
57 const UpdateCallback& callback); 51 const GetRequestsCallback& callback);
58 static void RemoveOfflinePagesSync( 52 static void AddOrUpdateRequestSync(
59 const std::vector<int64_t>& offline_ids,
60 sql::Connection* db, 53 sql::Connection* db,
61 scoped_refptr<base::SingleThreadTaskRunner> runner, 54 scoped_refptr<base::SingleThreadTaskRunner> runner,
55 const SavePageRequest& offline_page,
62 const UpdateCallback& callback); 56 const UpdateCallback& callback);
57 static void RemoveRequestsSync(
58 sql::Connection* db,
59 scoped_refptr<base::SingleThreadTaskRunner> runner,
60 const std::vector<int64_t>& request_ids,
61 const RemoveCallback& callback);
63 static void ResetSync(std::unique_ptr<sql::Connection> db, 62 static void ResetSync(std::unique_ptr<sql::Connection> db,
64 scoped_refptr<base::SingleThreadTaskRunner> runner, 63 scoped_refptr<base::SingleThreadTaskRunner> runner,
65 const ResetCallback& callback); 64 const ResetCallback& callback);
66 65
67 static void NotifyLoadResult( 66 // Used to initialize DB connection.
67 static void OpenConnectionSync(
68 sql::Connection* db,
68 scoped_refptr<base::SingleThreadTaskRunner> runner, 69 scoped_refptr<base::SingleThreadTaskRunner> runner,
69 const LoadCallback& callback, 70 const base::FilePath& path,
70 LoadStatus status, 71 const base::Callback<void(bool)>& callback);
71 const std::vector<OfflinePageItem>& result); 72 void OpenConnection();
73 void OnOpenConnectionDone(bool success);
72 74
73 // Background thread where all SQL access should be run. 75 // Background thread where all SQL access should be run.
74 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 76 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
75 77
76 // Path to the database on disk. 78 // Path to the database on disk.
77 base::FilePath db_file_path_; 79 base::FilePath db_file_path_;
80
81 // Database connection.
78 std::unique_ptr<sql::Connection> db_; 82 std::unique_ptr<sql::Connection> db_;
79 83
80 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreSQL); 84 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_;
85 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL);
81 }; 86 };
82 87
83 } // namespace offline_pages 88 } // namespace offline_pages
84 89
85 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_SQL_H_ 90 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698