Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: components/offline_pages/background/request_queue.h

Issue 2372043002: [Offline pages] Applying TaskQueue to RequestQueue::ChangeRequestsState (Closed)
Patch Set: Addressing feedback from dougarnett Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "components/offline_pages/background/save_page_request.h" 17 #include "components/offline_pages/background/save_page_request.h"
18 #include "components/offline_pages/core/task_queue.h"
18 #include "components/offline_pages/offline_page_item.h" 19 #include "components/offline_pages/offline_page_item.h"
20 #include "components/offline_pages/offline_store_types.h"
19 21
20 namespace offline_pages { 22 namespace offline_pages {
21 23
22 class RequestQueueStore; 24 class RequestQueueStore;
25 typedef StoreUpdateResult<SavePageRequest> UpdateRequestsResult;
23 26
24 // Class responsible for managing save page requests. 27 // Class responsible for managing save page requests.
25 class RequestQueue { 28 class RequestQueue {
26 public: 29 public:
27 enum class GetRequestsResult { 30 enum class GetRequestsResult {
28 SUCCESS, 31 SUCCESS,
29 STORE_FAILURE, 32 STORE_FAILURE,
30 }; 33 };
31 34
32 enum class AddRequestResult { 35 enum class AddRequestResult {
(...skipping 18 matching lines...) Expand all
51 54
52 // Callback used for |GetRequests|. 55 // Callback used for |GetRequests|.
53 typedef base::Callback<void(GetRequestsResult, 56 typedef base::Callback<void(GetRequestsResult,
54 std::vector<std::unique_ptr<SavePageRequest>>)> 57 std::vector<std::unique_ptr<SavePageRequest>>)>
55 GetRequestsCallback; 58 GetRequestsCallback;
56 59
57 // Callback used for |AddRequest|. 60 // Callback used for |AddRequest|.
58 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)> 61 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)>
59 AddRequestCallback; 62 AddRequestCallback;
60 63
64 // Callback used by |ChangeRequestsState|.
65 typedef base::Callback<void(std::unique_ptr<UpdateRequestsResult>)>
66 UpdateCallback;
67
61 // Callback used by |UdpateRequest|. 68 // Callback used by |UdpateRequest|.
62 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback; 69 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback;
63 70
64 // Callback used by |ChangeState| for more than one update at a time. 71 // Callback used by |ChangeState| for more than one update at a time.
65 typedef base::Callback<void( 72 typedef base::Callback<void(
66 const UpdateMultipleRequestResults& results, 73 const UpdateMultipleRequestResults& results,
67 std::vector<std::unique_ptr<SavePageRequest>> requests)> 74 std::vector<std::unique_ptr<SavePageRequest>> requests)>
68 UpdateMultipleRequestsCallback; 75 UpdateMultipleRequestsCallback;
69 76
70 // Callback used by |RemoveRequests|. 77 // Callback used by |RemoveRequests|.
(...skipping 20 matching lines...) Expand all
91 // exists. Does nothing otherwise. Result is returned through |callback|. 98 // exists. Does nothing otherwise. Result is returned through |callback|.
92 void UpdateRequest(const SavePageRequest& request, 99 void UpdateRequest(const SavePageRequest& request,
93 const UpdateRequestCallback& callback); 100 const UpdateRequestCallback& callback);
94 101
95 // Removes the requests matching the |request_ids|. Result is returned through 102 // Removes the requests matching the |request_ids|. Result is returned through
96 // |callback|. If a request id cannot be removed, this will still remove the 103 // |callback|. If a request id cannot be removed, this will still remove the
97 // others. 104 // others.
98 void RemoveRequests(const std::vector<int64_t>& request_ids, 105 void RemoveRequests(const std::vector<int64_t>& request_ids,
99 const RemoveRequestsCallback& callback); 106 const RemoveRequestsCallback& callback);
100 107
101 // Changes the state to |new_state_ for requests matching the 108 // Changes the state to |new_state| for requests matching the
102 // |request_ids|. Results are returned through |callback|. 109 // |request_ids|. Results are returned through |callback|.
103 // TODO(petewil): Instead of having one function per property,
104 // modify this to have a single update function that updates an entire
105 // request, and doesn't need to care what updates.
106 void ChangeRequestsState(const std::vector<int64_t>& request_ids, 110 void ChangeRequestsState(const std::vector<int64_t>& request_ids,
107 const SavePageRequest::RequestState new_state, 111 const SavePageRequest::RequestState new_state,
108 const UpdateMultipleRequestsCallback& callback); 112 const UpdateCallback& callback);
109 113
110 void GetForUpdateDone( 114 void GetForUpdateDone(
111 const RequestQueue::UpdateRequestCallback& update_callback, 115 const RequestQueue::UpdateRequestCallback& update_callback,
112 const SavePageRequest& update_request, 116 const SavePageRequest& update_request,
113 bool success, 117 bool success,
114 std::vector<std::unique_ptr<SavePageRequest>> requests); 118 std::vector<std::unique_ptr<SavePageRequest>> requests);
115 119
116 private: 120 private:
117 // Callback used by |PurgeRequests|. 121 // Callback used by |PurgeRequests|.
118 typedef base::Callback<void(UpdateRequestResult, 122 typedef base::Callback<void(UpdateRequestResult,
119 int /* removed requests count */)> 123 int /* removed requests count */)>
120 PurgeRequestsCallback; 124 PurgeRequestsCallback;
121 125
122 // Purges the queue, removing the requests that are no longer relevant, e.g. 126 // Purges the queue, removing the requests that are no longer relevant, e.g.
123 // expired request. Result is returned through |callback| carries the number 127 // expired request. Result is returned through |callback| carries the number
124 // of removed requests. 128 // of removed requests.
125 void PurgeRequests(const PurgeRequestsCallback& callback); 129 void PurgeRequests(const PurgeRequestsCallback& callback);
126 130
127 std::unique_ptr<RequestQueueStore> store_; 131 std::unique_ptr<RequestQueueStore> store_;
128 132
133 // Task queue to serialize store access.
134 TaskQueue task_queue_;
135
129 // Allows us to pass a weak pointer to callbacks. 136 // Allows us to pass a weak pointer to callbacks.
130 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; 137 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
131 138
132 DISALLOW_COPY_AND_ASSIGN(RequestQueue); 139 DISALLOW_COPY_AND_ASSIGN(RequestQueue);
133 }; 140 };
134 141
135 } // namespace offline_pages 142 } // namespace offline_pages
136 143
137 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 144 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/request_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698