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