OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | |
7 | |
8 #include <stdint.h> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "components/offline_pages/background/request_queue.h" | |
13 #include "components/offline_pages/background/save_page_request.h" | |
14 #include "components/offline_pages/offline_store_types.h" | |
15 | |
16 namespace offline_pages { | |
17 | |
18 // Interface for classes storing save page requests. | |
19 class RequestQueueStore { | |
20 public: | |
21 enum class UpdateStatus { | |
22 ADDED, // Request was added successfully. | |
23 UPDATED, // Request was updated successfully. | |
24 FAILED, // Add or update attempt failed. | |
25 }; | |
26 | |
27 using UpdateCallback = RequestQueue::UpdateCallback; | |
28 | |
29 typedef base::Callback<void( | |
30 bool /* success */, | |
31 std::vector<std::unique_ptr<SavePageRequest>> /* requests */)> | |
32 GetRequestsCallback; | |
33 typedef base::Callback<void(ItemActionStatus)> AddCallback; | |
34 typedef base::Callback<void(bool /* success */)> ResetCallback; | |
35 | |
36 virtual ~RequestQueueStore(){}; | |
37 | |
38 // Gets all of the requests from the store. | |
39 virtual void GetRequests(const GetRequestsCallback& callback) = 0; | |
40 | |
41 // Gets requests with specified IDs from the store. UpdateCallback is used | |
42 // instead of GetRequestsCallback to indicate which requests where not found. | |
43 virtual void GetRequestsByIds(const std::vector<int64_t>& request_ids, | |
44 const UpdateCallback& callback) = 0; | |
45 | |
46 // Asynchronously adds request in store. Fails if request with the same | |
47 // offline ID already exists. | |
48 virtual void AddRequest(const SavePageRequest& offline_page, | |
49 const AddCallback& callback) = 0; | |
50 | |
51 // Asynchronously updates requests in store. | |
52 virtual void UpdateRequests(const std::vector<SavePageRequest>& requests, | |
53 const UpdateCallback& callback) = 0; | |
54 | |
55 // Asynchronously removes requests from the store using their IDs. | |
56 // Result of the update, and a number of removed pages is passed in the | |
57 // callback. | |
58 // Result of remove should be false, when one of the provided items couldn't | |
59 // be deleted, e.g. because it was missing. | |
60 virtual void RemoveRequests(const std::vector<int64_t>& request_ids, | |
61 const UpdateCallback& callback) = 0; | |
62 | |
63 // Resets the store. | |
64 virtual void Reset(const ResetCallback& callback) = 0; | |
65 | |
66 // Gets the store state. | |
67 virtual StoreState state() const = 0; | |
68 }; | |
69 | |
70 } // namespace offline_pages | |
71 | |
72 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_ | |
OLD | NEW |