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

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

Issue 2262423002: Use a vector of smart pointers for callback return type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 3 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_PICKER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 19 matching lines...) Expand all
30 30
31 // Choose which request we should process next based on the current 31 // Choose which request we should process next based on the current
32 // conditions, and call back to the RequestCoordinator when we have one. 32 // conditions, and call back to the RequestCoordinator when we have one.
33 void ChooseNextRequest( 33 void ChooseNextRequest(
34 RequestCoordinator::RequestPickedCallback picked_callback, 34 RequestCoordinator::RequestPickedCallback picked_callback,
35 RequestCoordinator::RequestNotPickedCallback not_picked_callback, 35 RequestCoordinator::RequestNotPickedCallback not_picked_callback,
36 DeviceConditions* device_conditions); 36 DeviceConditions* device_conditions);
37 37
38 private: 38 private:
39 // Callback for the GetRequest results to be delivered. 39 // Callback for the GetRequest results to be delivered.
40 void GetRequestResultCallback(RequestQueue::GetRequestsResult result, 40 void GetRequestResultCallback(
41 const std::vector<SavePageRequest>& results); 41 RequestQueue::GetRequestsResult result,
42 std::vector<std::unique_ptr<SavePageRequest>> results);
42 43
43 // Filter out requests that don't meet the current conditions. For instance, 44 // Filter out requests that don't meet the current conditions. For instance,
44 // if this is a predictive request, and we are not on WiFi, it should be 45 // if this is a predictive request, and we are not on WiFi, it should be
45 // ignored this round. 46 // ignored this round.
46 bool RequestConditionsSatisfied(const SavePageRequest& request); 47 bool RequestConditionsSatisfied(const SavePageRequest* request);
47 48
48 // Using policies, decide if the new request is preferable to the best we have 49 // Using policies, decide if the new request is preferable to the best we have
49 // so far. 50 // so far.
50 bool IsNewRequestBetter(const SavePageRequest* oldRequest, 51 bool IsNewRequestBetter(const SavePageRequest* oldRequest,
51 const SavePageRequest* newRequest, 52 const SavePageRequest* newRequest,
52 RequestCompareFunction comparator); 53 RequestCompareFunction comparator);
53 54
54 // Is the new request preferable from the retry count first standpoint? 55 // Is the new request preferable from the retry count first standpoint?
55 bool RetryCountFirstCompareFunction(const SavePageRequest* left, 56 bool RetryCountFirstCompareFunction(const SavePageRequest* left,
56 const SavePageRequest* right); 57 const SavePageRequest* right);
57 58
58 // Is the new request better from the recency first standpoint? 59 // Is the new request better from the recency first standpoint?
59 bool RecencyFirstCompareFunction(const SavePageRequest* left, 60 bool RecencyFirstCompareFunction(const SavePageRequest* left,
60 const SavePageRequest* right); 61 const SavePageRequest* right);
61 62
62 // Does the new request have better retry count? 63 // Does the new request have better retry count?
63 int CompareRetryCount(const SavePageRequest* left, 64 int CompareRetryCount(const SavePageRequest* left,
64 const SavePageRequest* right); 65 const SavePageRequest* right);
65 66
66 // Does the new request have better creation time? 67 // Does the new request have better creation time?
67 int CompareCreationTime(const SavePageRequest* left, 68 int CompareCreationTime(const SavePageRequest* left,
68 const SavePageRequest* right); 69 const SavePageRequest* right);
69 70
70 // Split all requests into expired ones and still valid ones. 71 // Split all requests into expired ones and still valid ones. Takes ownership
71 void SplitRequests(const std::vector<SavePageRequest>& requests, 72 // of the requests, and moves them into either valid or expired requests.
72 std::vector<SavePageRequest>& valid_requests, 73 void SplitRequests(
73 std::vector<SavePageRequest>& expired_requests); 74 std::vector<std::unique_ptr<SavePageRequest>> requests,
75 std::vector<std::unique_ptr<SavePageRequest>>* valid_requests,
76 std::vector<std::unique_ptr<SavePageRequest>>* expired_requests);
74 77
75 // Callback used after requests get expired. 78 // Callback used after requests get expired.
76 void OnRequestExpired( 79 void OnRequestExpired(
77 const RequestQueue::UpdateMultipleRequestResults& results, 80 const RequestQueue::UpdateMultipleRequestResults& results,
78 const std::vector<SavePageRequest>& requests); 81 const std::vector<std::unique_ptr<SavePageRequest>> requests);
79 82
80 // Unowned pointer to the request queue. 83 // Unowned pointer to the request queue.
81 RequestQueue* queue_; 84 RequestQueue* queue_;
82 // Unowned pointer to the policy object. 85 // Unowned pointer to the policy object.
83 OfflinerPolicy* policy_; 86 OfflinerPolicy* policy_;
84 // Unowned pointer to the request coordinator. 87 // Unowned pointer to the request coordinator.
85 RequestNotifier* notifier_; 88 RequestNotifier* notifier_;
86 // Current conditions on the device 89 // Current conditions on the device
87 std::unique_ptr<DeviceConditions> current_conditions_; 90 std::unique_ptr<DeviceConditions> current_conditions_;
88 // True if we prefer less-tried requests 91 // True if we prefer less-tried requests
89 bool fewer_retries_better_; 92 bool fewer_retries_better_;
90 // True if we prefer requests submitted more recently 93 // True if we prefer requests submitted more recently
91 bool earlier_requests_better_; 94 bool earlier_requests_better_;
92 // Callback for when we are done picking a request to do next. 95 // Callback for when we are done picking a request to do next.
93 RequestCoordinator::RequestPickedCallback picked_callback_; 96 RequestCoordinator::RequestPickedCallback picked_callback_;
94 // Callback for when there are no more reqeusts to pick. 97 // Callback for when there are no more reqeusts to pick.
95 RequestCoordinator::RequestNotPickedCallback not_picked_callback_; 98 RequestCoordinator::RequestNotPickedCallback not_picked_callback_;
96 // Allows us to pass a weak pointer to callbacks. 99 // Allows us to pass a weak pointer to callbacks.
97 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; 100 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_;
98 }; 101 };
99 102
100 } // namespace offline_pages 103 } // namespace offline_pages
101 104
102 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ 105 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698