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

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

Issue 2543093002: Split the RequestPicker task into two separate tasks. (Closed)
Patch Set: ADD TODO 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 // Cleanup requests that have expired, exceeded the start or completed retry
102 // limit.
103 void CleanupRequestQueue();
104
100 // Takes ownership of the factory. We use a setter to allow users of the 105 // 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 106 // request queue to not need a CleanupFactory to create it, since we have lots
102 // of code using the request queue. The request coordinator will set a 107 // of code using the request queue. The request coordinator will set a
103 // factory before calling PickNextRequest. 108 // factory before calling CleanupRequestQueue.
104 void SetPickerFactory(std::unique_ptr<PickRequestTaskFactory> factory) { 109 void SetCleanupFactory(std::unique_ptr<CleanupTaskFactory> factory) {
105 picker_factory_ = std::move(factory); 110 cleanup_factory_ = std::move(factory);
106 } 111 }
107 112
108 private: 113 private:
109 // Store initialization functions. 114 // Store initialization functions.
110 void Initialize(); 115 void Initialize();
111 void InitializeStoreDone(bool success); 116 void InitializeStoreDone(bool success);
112 117
113 std::unique_ptr<RequestQueueStore> store_; 118 std::unique_ptr<RequestQueueStore> store_;
114 119
115 // Task queue to serialize store access. 120 // Task queue to serialize store access.
116 TaskQueue task_queue_; 121 TaskQueue task_queue_;
117 122
118 // Builds PickRequestTask objects. 123 // Builds CleanupTask objects.
119 std::unique_ptr<PickRequestTaskFactory> picker_factory_; 124 std::unique_ptr<CleanupTaskFactory> cleanup_factory_;
120 125
121 // Allows us to pass a weak pointer to callbacks. 126 // Allows us to pass a weak pointer to callbacks.
122 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; 127 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
123 128
124 DISALLOW_COPY_AND_ASSIGN(RequestQueue); 129 DISALLOW_COPY_AND_ASSIGN(RequestQueue);
125 }; 130 };
126 131
127 } // namespace offline_pages 132 } // namespace offline_pages
128 133
129 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 134 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698