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