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

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

Issue 2473553004: Request Picker task (Closed)
Patch Set: CR fixes per DougArnett Created 4 years, 1 month 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
(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_PICK_REQUEST_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_PICK_REQUEST_TASK_H_
7
8 #include <set>
9
10 #include "base/memory/weak_ptr.h"
11 #include "components/offline_pages/background/queue_results.h"
12 #include "components/offline_pages/background/save_page_request.h"
13 #include "components/offline_pages/core/task.h"
14
15 namespace offline_pages {
16
17 class DeviceConditions;
18 class OfflinerPolicy;
19 class PickRequestTask;
20 class RequestCoordinatorEventLogger;
21 class RequestNotifier;
22 class RequestQueue;
23
24 typedef bool (PickRequestTask::*RequestCompareFunction)(
25 const SavePageRequest* left,
26 const SavePageRequest* right);
27
28 class PickRequestTask : public Task {
29 public:
30 // Callback to report when a request was available.
31 typedef base::Callback<void(const SavePageRequest& request)>
32 RequestPickedCallback;
33
34 // Callback to report when no request was available.
35 typedef base::Callback<void(bool)> RequestNotPickedCallback;
36
37 PickRequestTask(RequestQueue* request_queue,
38 OfflinerPolicy* policy,
39 RequestNotifier* notifier,
40 RequestCoordinatorEventLogger* event_logger,
41 RequestPickedCallback picked_callback,
42 RequestNotPickedCallback not_picked_callback,
43 DeviceConditions* device_conditions,
44 const std::set<int64_t>& disabled_requests);
45
46 ~PickRequestTask() override;
47
48 // TaskQueue::Task implementation, starts the async chain
49 void Run() override;
50
51 private:
52 // Step 1, handle getting the results from the store.
53 void HandleGetResults(QueueResults::GetRequestsResult,
fgorski 2016/11/03 22:00:29 Can you focus on the outcome of the step when nami
Pete Williamson 2016/11/04 18:53:37 How about "ChooseAndPrune"?
54 std::vector<std::unique_ptr<SavePageRequest>> requests);
55
56 // Step 2a. Handle choosing an entry, and calling the right callback.
57 void ChooseRequestAndCallback(
58 std::vector<std::unique_ptr<SavePageRequest>> valid_requests);
59
60 // Step 2b. Handle deleting expired entries and notifying observers.
dougarnett 2016/11/03 19:56:51 expired => stale
fgorski 2016/11/03 22:00:29 I am happy with Expired, as long as we are consist
dougarnett 2016/11/03 22:33:15 In case my point is not clear, we should be cullin
Pete Williamson 2016/11/04 18:53:37 I changed it to stale everywhere. I'm not sure th
61 void RemoveStaleRequests(
62 std::vector<std::unique_ptr<SavePageRequest>> expired_requests);
63
64 // Step 3. Send delete notifications for the expired requests.
65 void OnRequestsExpired(
66 std::unique_ptr<QueueResults::UpdateRequestsResult> result);
67
68 // Helper functions.
69
70 // Split requests into valid and expired categories.
71 void SplitRequests(
72 std::vector<std::unique_ptr<SavePageRequest>> requests,
73 std::vector<std::unique_ptr<SavePageRequest>>* valid_requests,
74 std::vector<std::unique_ptr<SavePageRequest>>* expired_requests);
75
76 // Determine if this request has device conditions appropriate for running it.
77 bool RequestConditionsSatisfied(const SavePageRequest* request);
78
79 // Determine if the new request is preferred under current policies.
80 bool IsNewRequestBetter(const SavePageRequest* oldRequest,
81 const SavePageRequest* newRequest,
82 RequestCompareFunction comparator);
83
84 // Returns true if the left hand side is better.
85 bool RetryCountFirstCompareFunction(const SavePageRequest* left,
86 const SavePageRequest* right);
87
88 // Returns true if the left hand side is better.
89 bool RecencyFirstCompareFunction(const SavePageRequest* left,
90 const SavePageRequest* right);
91
92 // Compare left and right side, returning 1 if the left side is better
93 // (preferred by policy), 0 if the same, and -1 if the right side is better.
94 int CompareRetryCount(const SavePageRequest* left,
95 const SavePageRequest* right);
96
97 // Compare left and right side, returning 1 if the left side is better
98 // (preferred by policy), 0 if the same, and -1 if the right side is better.
99 int CompareCreationTime(const SavePageRequest* left,
100 const SavePageRequest* right);
101
102 // Member variables, all pointers unowned.
103 RequestQueue* request_queue_;
104 OfflinerPolicy* policy_;
105 RequestNotifier* notifier_;
106 RequestCoordinatorEventLogger* event_logger_;
107 RequestPickedCallback picked_callback_;
108 RequestNotPickedCallback not_picked_callback_;
109 DeviceConditions* device_conditions_;
110 const std::set<int64_t>& disabled_requests_;
111 // Allows us to pass a weak pointer to callbacks.
112 base::WeakPtrFactory<PickRequestTask> weak_ptr_factory_;
113 };
114
115 } // namespace offline_pages
116
117 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_PICK_REQUEST_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698