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

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: Fix unit test break introduced by merge 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 20 matching lines...) Expand all
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 void AddOrUpdateRequest(const SavePageRequest& offline_page, 37 void AddOrUpdateRequest(const SavePageRequest& offline_page,
38 const UpdateCallback& callback) override; 38 const UpdateCallback& callback) override;
39 void RemoveRequests(const std::vector<int64_t>& request_ids, 39 void RemoveRequests(const std::vector<int64_t>& request_ids,
40 const RemoveCallback& callback) override; 40 const RemoveCallback& callback) override;
41 void ChangeRequestsState(const std::vector<int64_t>& request_ids,
42 const SavePageRequest::RequestState new_state,
43 const UpdateCallback& callback) override;
41 void Reset(const ResetCallback& callback) override; 44 void Reset(const ResetCallback& callback) override;
42 45
43 private: 46 private:
44 // Synchronous implementations, these are run on the background thread 47 // Synchronous implementations, these are run on the background thread
45 // and actually do the work to access SQL. The implementations above 48 // and actually do the work to access SQL. The implementations above
46 // simply dispatch to the corresponding *Sync method on the background thread. 49 // simply dispatch to the corresponding *Sync method on the background thread.
47 // 'runner' is where to run the callback. 50 // 'runner' is where to run the callback.
48 static void GetRequestsSync( 51 static void GetRequestsSync(
49 sql::Connection* db, 52 sql::Connection* db,
50 scoped_refptr<base::SingleThreadTaskRunner> runner, 53 scoped_refptr<base::SingleThreadTaskRunner> runner,
51 const GetRequestsCallback& callback); 54 const GetRequestsCallback& callback);
52 static void AddOrUpdateRequestSync( 55 static void AddOrUpdateRequestSync(
53 sql::Connection* db, 56 sql::Connection* db,
54 scoped_refptr<base::SingleThreadTaskRunner> runner, 57 scoped_refptr<base::SingleThreadTaskRunner> runner,
55 const SavePageRequest& offline_page, 58 const SavePageRequest& offline_page,
56 const UpdateCallback& callback); 59 const UpdateCallback& callback);
57 static void RemoveRequestsSync( 60 static void RemoveRequestsSync(
58 sql::Connection* db, 61 sql::Connection* db,
59 scoped_refptr<base::SingleThreadTaskRunner> runner, 62 scoped_refptr<base::SingleThreadTaskRunner> runner,
60 const std::vector<int64_t>& request_ids, 63 const std::vector<int64_t>& request_ids,
61 const RemoveCallback& callback); 64 const RemoveCallback& callback);
65 static void ChangeRequestsStateSync(
66 sql::Connection* db,
67 scoped_refptr<base::SingleThreadTaskRunner> runner,
68 const std::vector<int64_t>& request_ids,
69 const SavePageRequest::RequestState new_state,
70 const UpdateCallback& callback);
62 static void ResetSync(sql::Connection* db, 71 static void ResetSync(sql::Connection* db,
63 const base::FilePath& db_file_path, 72 const base::FilePath& db_file_path,
64 scoped_refptr<base::SingleThreadTaskRunner> runner, 73 scoped_refptr<base::SingleThreadTaskRunner> runner,
65 const ResetCallback& callback); 74 const ResetCallback& callback);
66 75
76 // Helper functions to return immediately if no database is found.
77 bool CheckDb(const base::Closure& callback);
78
67 // Used to initialize DB connection. 79 // Used to initialize DB connection.
68 static void OpenConnectionSync( 80 static void OpenConnectionSync(
69 sql::Connection* db, 81 sql::Connection* db,
70 scoped_refptr<base::SingleThreadTaskRunner> runner, 82 scoped_refptr<base::SingleThreadTaskRunner> runner,
71 const base::FilePath& path, 83 const base::FilePath& path,
72 const base::Callback<void(bool)>& callback); 84 const base::Callback<void(bool)>& callback);
73 void OpenConnection(); 85 void OpenConnection();
74 void OnOpenConnectionDone(bool success); 86 void OnOpenConnectionDone(bool success);
75 87
76 // Used to finalize connection reset. 88 // Used to finalize connection reset.
77 void OnResetDone(const ResetCallback& callback, bool success); 89 void OnResetDone(const ResetCallback& callback, bool success);
78 90
79 // Background thread where all SQL access should be run. 91 // Background thread where all SQL access should be run.
80 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 92 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
81 93
82 // Path to the database on disk. 94 // Path to the database on disk.
83 base::FilePath db_file_path_; 95 base::FilePath db_file_path_;
84 96
85 // Database connection. 97 // Database connection.
86 std::unique_ptr<sql::Connection> db_; 98 std::unique_ptr<sql::Connection> db_;
87 99
88 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_; 100 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_;
89 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL); 101 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL);
90 }; 102 };
91 103
92 } // namespace offline_pages 104 } // namespace offline_pages
93 105
94 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_ 106 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698