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

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

Issue 2221323003: Add an API to Pause and Resume background offlining requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a check function to reduce common code. Created 4 years, 4 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_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_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>
(...skipping 16 matching lines...) Expand all
27 // SQLite implementation of RequestQueueStore. 27 // SQLite implementation of RequestQueueStore.
28 class RequestQueueStoreSQL : public RequestQueueStore { 28 class RequestQueueStoreSQL : public RequestQueueStore {
29 public: 29 public:
30 RequestQueueStoreSQL( 30 RequestQueueStoreSQL(
31 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 31 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
32 const base::FilePath& database_dir); 32 const base::FilePath& database_dir);
33 ~RequestQueueStoreSQL() override; 33 ~RequestQueueStoreSQL() override;
34 34
35 // RequestQueueStore implementation. 35 // RequestQueueStore implementation.
36 void GetRequests(const GetRequestsCallback& callback) override; 36 void GetRequests(const GetRequestsCallback& callback) override;
37
37 void AddOrUpdateRequest(const SavePageRequest& offline_page, 38 void AddOrUpdateRequest(const SavePageRequest& offline_page,
38 const UpdateCallback& callback) override; 39 const UpdateCallback& callback) override;
39 void RemoveRequests(const std::vector<int64_t>& request_ids, 40 void RemoveRequests(const std::vector<int64_t>& request_ids,
40 const RemoveCallback& callback) override; 41 const RemoveCallback& callback) override;
41 void RemoveRequestsByClientId(const std::vector<ClientId>& client_ids, 42 void RemoveRequestsByClientId(const std::vector<ClientId>& client_ids,
42 const RemoveCallback& callback) override; 43 const RemoveCallback& callback) override;
44
45 void PauseRequests(const std::vector<int64_t>& request_ids,
46 const UpdateCallback& callback) override;
47
48 void ResumeRequests(const std::vector<int64_t>& request_ids,
49 const UpdateCallback& callback) override;
50
43 void Reset(const ResetCallback& callback) override; 51 void Reset(const ResetCallback& callback) override;
44 52
45 private: 53 private:
46 // Synchronous implementations, these are run on the background thread 54 // Synchronous implementations, these are run on the background thread
47 // and actually do the work to access SQL. The implementations above 55 // and actually do the work to access SQL. The implementations above
48 // simply dispatch to the corresponding *Sync method on the background thread. 56 // simply dispatch to the corresponding *Sync method on the background thread.
49 // 'runner' is where to run the callback. 57 // 'runner' is where to run the callback.
50 static void GetRequestsSync( 58 static void GetRequestsSync(
51 sql::Connection* db, 59 sql::Connection* db,
52 scoped_refptr<base::SingleThreadTaskRunner> runner, 60 scoped_refptr<base::SingleThreadTaskRunner> runner,
53 const GetRequestsCallback& callback); 61 const GetRequestsCallback& callback);
54 static void AddOrUpdateRequestSync( 62 static void AddOrUpdateRequestSync(
55 sql::Connection* db, 63 sql::Connection* db,
56 scoped_refptr<base::SingleThreadTaskRunner> runner, 64 scoped_refptr<base::SingleThreadTaskRunner> runner,
57 const SavePageRequest& offline_page, 65 const SavePageRequest& offline_page,
58 const UpdateCallback& callback); 66 const UpdateCallback& callback);
59 static void RemoveRequestsSync( 67 static void RemoveRequestsSync(
60 sql::Connection* db, 68 sql::Connection* db,
61 scoped_refptr<base::SingleThreadTaskRunner> runner, 69 scoped_refptr<base::SingleThreadTaskRunner> runner,
62 const std::vector<int64_t>& request_ids, 70 const std::vector<int64_t>& request_ids,
63 const RemoveCallback& callback); 71 const RemoveCallback& callback);
64 static void RemoveRequestsByClientIdSync( 72 static void RemoveRequestsByClientIdSync(
65 sql::Connection* db, 73 sql::Connection* db,
66 scoped_refptr<base::SingleThreadTaskRunner> runner, 74 scoped_refptr<base::SingleThreadTaskRunner> runner,
67 const std::vector<ClientId>& client_ids, 75 const std::vector<ClientId>& client_ids,
68 const RemoveCallback& callback); 76 const RemoveCallback& callback);
77 static void PauseRequestsSync(
78 sql::Connection* db,
79 scoped_refptr<base::SingleThreadTaskRunner> runner,
80 const std::vector<int64_t>& request_ids,
81 const UpdateCallback& callback);
82 static void ResumeRequestsSync(
83 sql::Connection* db,
84 scoped_refptr<base::SingleThreadTaskRunner> runner,
85 const std::vector<int64_t>& request_ids,
86 const UpdateCallback& callback);
69 static void ResetSync(sql::Connection* db, 87 static void ResetSync(sql::Connection* db,
70 const base::FilePath& db_file_path, 88 const base::FilePath& db_file_path,
71 scoped_refptr<base::SingleThreadTaskRunner> runner, 89 scoped_refptr<base::SingleThreadTaskRunner> runner,
72 const ResetCallback& callback); 90 const ResetCallback& callback);
73 91
92 // Helper functions to return immediately if no database is found.
93 bool CheckDb(const RemoveCallback& callback);
94 bool CheckDb(const GetRequestsCallback& callback);
95 bool CheckDb(const UpdateCallback& callback);
96 bool CheckDb(const ResetCallback& callback);
97
74 // Used to initialize DB connection. 98 // Used to initialize DB connection.
75 static void OpenConnectionSync( 99 static void OpenConnectionSync(
76 sql::Connection* db, 100 sql::Connection* db,
77 scoped_refptr<base::SingleThreadTaskRunner> runner, 101 scoped_refptr<base::SingleThreadTaskRunner> runner,
78 const base::FilePath& path, 102 const base::FilePath& path,
79 const base::Callback<void(bool)>& callback); 103 const base::Callback<void(bool)>& callback);
80 void OpenConnection(); 104 void OpenConnection();
81 void OnOpenConnectionDone(bool success); 105 void OnOpenConnectionDone(bool success);
82 106
83 // Used to finalize connection reset. 107 // Used to finalize connection reset.
84 void OnResetDone(const ResetCallback& callback, bool success); 108 void OnResetDone(const ResetCallback& callback, bool success);
85 109
86 // Background thread where all SQL access should be run. 110 // Background thread where all SQL access should be run.
87 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 111 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
88 112
89 // Path to the database on disk. 113 // Path to the database on disk.
90 base::FilePath db_file_path_; 114 base::FilePath db_file_path_;
91 115
92 // Database connection. 116 // Database connection.
93 std::unique_ptr<sql::Connection> db_; 117 std::unique_ptr<sql::Connection> db_;
94 118
95 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_; 119 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_;
96 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL); 120 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL);
97 }; 121 };
98 122
99 } // namespace offline_pages 123 } // namespace offline_pages
100 124
101 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_ 125 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698