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

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

Issue 2473553004: Request Picker task (Closed)
Patch Set: Replace use of header file with forward declare for enum 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/request_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 RequestQueueStore;
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(RequestQueueStore* store,
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 ChooseAndPrune(bool request,
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 stale entries and notifying observers.
61 void RemoveStaleRequests(
62 std::vector<std::unique_ptr<SavePageRequest>> stale_requests);
63
64 // Step 3. Send delete notifications for the expired requests.
65 void OnRequestsExpired(std::unique_ptr<UpdateRequestsResult> result);
66
67 // Helper functions.
68
69 // Split requests into valid and expired categories.
70 void SplitRequests(
71 std::vector<std::unique_ptr<SavePageRequest>> requests,
72 std::vector<std::unique_ptr<SavePageRequest>>* valid_requests,
73 std::vector<std::unique_ptr<SavePageRequest>>* expired_requests);
74
75 // Determine if this request has device conditions appropriate for running it.
76 bool RequestConditionsSatisfied(const SavePageRequest* request);
77
78 // Determine if the new request is preferred under current policies.
79 bool IsNewRequestBetter(const SavePageRequest* oldRequest,
80 const SavePageRequest* newRequest,
81 RequestCompareFunction comparator);
82
83 // Returns true if the left hand side is better.
84 bool RetryCountFirstCompareFunction(const SavePageRequest* left,
85 const SavePageRequest* right);
86
87 // Returns true if the left hand side is better.
88 bool RecencyFirstCompareFunction(const SavePageRequest* left,
89 const SavePageRequest* right);
90
91 // Compare left and right side, returning 1 if the left side is better
92 // (preferred by policy), 0 if the same, and -1 if the right side is better.
93 int CompareRetryCount(const SavePageRequest* left,
94 const SavePageRequest* right);
95
96 // Compare left and right side, returning 1 if the left side is better
97 // (preferred by policy), 0 if the same, and -1 if the right side is better.
98 int CompareCreationTime(const SavePageRequest* left,
99 const SavePageRequest* right);
100
101 // Member variables, all pointers unowned.
fgorski 2016/11/09 17:58:07 nit: not owned. "unown" does not seem to be a wor
Pete Williamson 2016/11/09 23:53:55 Unown is not a word, but unowned does seem to be,
fgorski 2016/11/10 19:15:50 Cool, but having read the definition: adjective 1.
Pete Williamson 2016/11/10 23:43:25 OK, see if you like the new wording.
102 RequestQueueStore* store_;
103 OfflinerPolicy* policy_;
104 RequestNotifier* notifier_;
105 RequestCoordinatorEventLogger* event_logger_;
106 RequestPickedCallback picked_callback_;
107 RequestNotPickedCallback not_picked_callback_;
108 std::unique_ptr<DeviceConditions> device_conditions_;
109 const std::set<int64_t>& disabled_requests_;
110 // Allows us to pass a weak pointer to callbacks.
111 base::WeakPtrFactory<PickRequestTask> weak_ptr_factory_;
112 };
113
114 } // namespace offline_pages
115
116 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_PICK_REQUEST_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698