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_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
15 | 16 |
16 namespace offline_pages { | 17 namespace offline_pages { |
17 | 18 |
18 class RequestQueueStore; | 19 class RequestQueueStore; |
19 class SavePageRequest; | 20 class SavePageRequest; |
20 | 21 |
21 // Class responsible for managing save page requests. | 22 // Class responsible for managing save page requests. |
22 class RequestQueue { | 23 class RequestQueue { |
23 public: | 24 public: |
24 enum class GetRequestsResult { | 25 enum class GetRequestsResult { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 69 |
69 // Updates a request in the request queue if a request with matching ID | 70 // Updates a request in the request queue if a request with matching ID |
70 // exists. Does nothing otherwise. Result is returned through |callback|. | 71 // exists. Does nothing otherwise. Result is returned through |callback|. |
71 void UpdateRequest(const SavePageRequest& request, | 72 void UpdateRequest(const SavePageRequest& request, |
72 const UpdateRequestCallback& callback); | 73 const UpdateRequestCallback& callback); |
73 | 74 |
74 // Removes the request matching the |request_id|. Result is returned through | 75 // Removes the request matching the |request_id|. Result is returned through |
75 // |callback|. | 76 // |callback|. |
76 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); | 77 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); |
77 | 78 |
| 79 void GetForUpdateDone( |
| 80 const RequestQueue::UpdateRequestCallback& update_callback, |
| 81 const SavePageRequest& update_request, |
| 82 bool success, |
| 83 const std::vector<SavePageRequest>& requests); |
| 84 |
78 private: | 85 private: |
79 // Callback used by |PurgeRequests|. | 86 // Callback used by |PurgeRequests|. |
80 typedef base::Callback<void(UpdateRequestResult, | 87 typedef base::Callback<void(UpdateRequestResult, |
81 int /* removed requests count */)> | 88 int /* removed requests count */)> |
82 PurgeRequestsCallback; | 89 PurgeRequestsCallback; |
83 | 90 |
84 // Purges the queue, removing the requests that are no longer relevant, e.g. | 91 // Purges the queue, removing the requests that are no longer relevant, e.g. |
85 // expired request. Result is returned through |callback| carries the number | 92 // expired request. Result is returned through |callback| carries the number |
86 // of removed requests. | 93 // of removed requests. |
87 void PurgeRequests(const PurgeRequestsCallback& callback); | 94 void PurgeRequests(const PurgeRequestsCallback& callback); |
88 | 95 |
89 std::unique_ptr<RequestQueueStore> store_; | 96 std::unique_ptr<RequestQueueStore> store_; |
90 | 97 |
| 98 // Allows us to pass a weak pointer to callbacks. |
| 99 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 100 |
91 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 101 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
92 }; | 102 }; |
93 | 103 |
94 } // namespace offline_pages | 104 } // namespace offline_pages |
95 | 105 |
96 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 106 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
OLD | NEW |