| 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 | |
| 10 #include <memory> | 9 #include <memory> |
| 11 #include <vector> | 10 #include <vector> |
| 12 | 11 |
| 13 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 15 #include "components/offline_pages/background/request_queue_store.h" | 14 #include "components/offline_pages/background/request_queue_store.h" |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 class SequencedTaskRunner; | 17 class SequencedTaskRunner; |
| 19 } | 18 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 const AddCallback& callback) override; | 37 const AddCallback& callback) override; |
| 39 void UpdateRequests(const std::vector<SavePageRequest>& requests, | 38 void UpdateRequests(const std::vector<SavePageRequest>& requests, |
| 40 const UpdateCallback& callback) override; | 39 const UpdateCallback& callback) override; |
| 41 void RemoveRequests(const std::vector<int64_t>& request_ids, | 40 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 42 const RemoveCallback& callback) override; | 41 const RemoveCallback& callback) override; |
| 43 void ChangeRequestsState( | 42 void ChangeRequestsState( |
| 44 const std::vector<int64_t>& request_ids, | 43 const std::vector<int64_t>& request_ids, |
| 45 const SavePageRequest::RequestState new_state, | 44 const SavePageRequest::RequestState new_state, |
| 46 const UpdateMultipleRequestsCallback& callback) override; | 45 const UpdateMultipleRequestsCallback& callback) override; |
| 47 void Reset(const ResetCallback& callback) override; | 46 void Reset(const ResetCallback& callback) override; |
| 47 StoreState state() const override; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // Helper functions to return immediately if no database is found. | 50 // Helper functions to return immediately if no database is found. |
| 51 bool CheckDb(const base::Closure& callback); | 51 bool CheckDb(const base::Closure& callback); |
| 52 | 52 |
| 53 // Used to initialize DB connection. | 53 // Used to initialize DB connection. |
| 54 void OpenConnection(); | 54 void OpenConnection(); |
| 55 void OnOpenConnectionDone(bool success); | 55 void OnOpenConnectionDone(StoreState state); |
| 56 | 56 |
| 57 // Used to finalize connection reset. | 57 // Used to finalize connection reset. |
| 58 void OnResetDone(const ResetCallback& callback, bool success); | 58 void OnResetDone(const ResetCallback& callback, StoreState state); |
| 59 | 59 |
| 60 // Background thread where all SQL access should be run. | 60 // Background thread where all SQL access should be run. |
| 61 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 61 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
| 62 | 62 |
| 63 // Path to the database on disk. | 63 // Path to the database on disk. |
| 64 base::FilePath db_file_path_; | 64 base::FilePath db_file_path_; |
| 65 | 65 |
| 66 // Database connection. | 66 // Database connection. |
| 67 std::unique_ptr<sql::Connection> db_; | 67 std::unique_ptr<sql::Connection> db_; |
| 68 | 68 |
| 69 // State of the store. |
| 70 StoreState state_; |
| 71 |
| 69 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_; | 72 base::WeakPtrFactory<RequestQueueStoreSQL> weak_ptr_factory_; |
| 70 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL); | 73 DISALLOW_COPY_AND_ASSIGN(RequestQueueStoreSQL); |
| 71 }; | 74 }; |
| 72 | 75 |
| 73 } // namespace offline_pages | 76 } // namespace offline_pages |
| 74 | 77 |
| 75 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_ | 78 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_SQL_H_ |
| OLD | NEW |