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

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

Issue 2543093002: Split the RequestPicker task into two separate tasks. (Closed)
Patch Set: Created 4 years 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 <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "components/offline_pages/background/cleanup_task_factory.h"
18 #include "components/offline_pages/background/device_conditions.h" 19 #include "components/offline_pages/background/device_conditions.h"
19 #include "components/offline_pages/background/pick_request_task.h" 20 #include "components/offline_pages/background/pick_request_task.h"
20 #include "components/offline_pages/background/pick_request_task_factory.h"
21 #include "components/offline_pages/background/request_queue_results.h" 21 #include "components/offline_pages/background/request_queue_results.h"
22 #include "components/offline_pages/background/save_page_request.h" 22 #include "components/offline_pages/background/save_page_request.h"
23 #include "components/offline_pages/core/task_queue.h" 23 #include "components/offline_pages/core/task_queue.h"
24 #include "components/offline_pages/offline_page_item.h" 24 #include "components/offline_pages/offline_page_item.h"
25 #include "components/offline_pages/offline_store_types.h" 25 #include "components/offline_pages/offline_store_types.h"
26 26
27 namespace offline_pages { 27 namespace offline_pages {
28 28
29 class CleanupTaskFactory;
29 class RequestQueueStore; 30 class RequestQueueStore;
30 class PickRequestTaskFactory;
31 31
32 // Class responsible for managing save page requests. 32 // Class responsible for managing save page requests.
33 class RequestQueue { 33 class RequestQueue {
34 public: 34 public:
35 35
36 // Callback used for |GetRequests|. 36 // Callback used for |GetRequests|.
37 typedef base::Callback<void(GetRequestsResult, 37 typedef base::Callback<void(GetRequestsResult,
38 std::vector<std::unique_ptr<SavePageRequest>>)> 38 std::vector<std::unique_ptr<SavePageRequest>>)>
39 GetRequestsCallback; 39 GetRequestsCallback;
40 40
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void MarkAttemptAborted(int64_t request_id, const UpdateCallback& callback); 84 void MarkAttemptAborted(int64_t request_id, const UpdateCallback& callback);
85 85
86 // Marks attempt with |request_id| as completed. The attempt may have 86 // Marks attempt with |request_id| as completed. The attempt may have
87 // completed with either success or failure (not denoted here). Results 87 // completed with either success or failure (not denoted here). Results
88 // are returned through |callback|. 88 // are returned through |callback|.
89 void MarkAttemptCompleted(int64_t request_id, const UpdateCallback& callback); 89 void MarkAttemptCompleted(int64_t request_id, const UpdateCallback& callback);
90 90
91 // Make a task to pick the next request, and report our choice to the 91 // Make a task to pick the next request, and report our choice to the
92 // callbacks. 92 // callbacks.
93 void PickNextRequest( 93 void PickNextRequest(
94 OfflinerPolicy* policy,
94 PickRequestTask::RequestPickedCallback picked_callback, 95 PickRequestTask::RequestPickedCallback picked_callback,
95 PickRequestTask::RequestNotPickedCallback not_picked_callback, 96 PickRequestTask::RequestNotPickedCallback not_picked_callback,
96 PickRequestTask::RequestCountCallback request_count_callback, 97 PickRequestTask::RequestCountCallback request_count_callback,
97 DeviceConditions& conditions, 98 DeviceConditions& conditions,
98 std::set<int64_t>& disabled_requests); 99 std::set<int64_t>& disabled_requests);
99 100
101 void CleanupRequestQueue();
fgorski 2016/12/02 21:44:04 add documentation please.
Pete Williamson 2016/12/05 20:39:46 Done.
102
100 // Takes ownership of the factory. We use a setter to allow users of the 103 // Takes ownership of the factory. We use a setter to allow users of the
101 // request queue to not need a PickerFactory to create it, since we have lots 104 // request queue to not need a PickerFactory to create it, since we have lots
fgorski 2016/12/02 21:44:04 fix
Pete Williamson 2016/12/05 20:39:46 Done.
102 // of code using the request queue. The request coordinator will set a 105 // of code using the request queue. The request coordinator will set a
103 // factory before calling PickNextRequest. 106 // factory before calling PickNextRequest.
fgorski 2016/12/02 21:44:05 fix
Pete Williamson 2016/12/05 20:39:46 Done.
104 void SetPickerFactory(std::unique_ptr<PickRequestTaskFactory> factory) { 107 void SetCleanupFactory(std::unique_ptr<CleanupTaskFactory> factory) {
105 picker_factory_ = std::move(factory); 108 cleanup_factory_ = std::move(factory);
106 } 109 }
107 110
108 private: 111 private:
109 // Store initialization functions. 112 // Store initialization functions.
110 void Initialize(); 113 void Initialize();
111 void InitializeStoreDone(bool success); 114 void InitializeStoreDone(bool success);
112 115
113 std::unique_ptr<RequestQueueStore> store_; 116 std::unique_ptr<RequestQueueStore> store_;
114 117
115 // Task queue to serialize store access. 118 // Task queue to serialize store access.
116 TaskQueue task_queue_; 119 TaskQueue task_queue_;
117 120
118 // Builds PickRequestTask objects. 121 // Builds CleanupTask objects.
119 std::unique_ptr<PickRequestTaskFactory> picker_factory_; 122 std::unique_ptr<CleanupTaskFactory> cleanup_factory_;
120 123
121 // Allows us to pass a weak pointer to callbacks. 124 // Allows us to pass a weak pointer to callbacks.
122 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; 125 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
123 126
124 DISALLOW_COPY_AND_ASSIGN(RequestQueue); 127 DISALLOW_COPY_AND_ASSIGN(RequestQueue);
125 }; 128 };
126 129
127 } // namespace offline_pages 130 } // namespace offline_pages
128 131
129 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 132 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698