Index: components/offline_pages/background/request_picker.h |
diff --git a/components/offline_pages/background/request_picker.h b/components/offline_pages/background/request_picker.h |
index dd2b7ff295ae22a60ead1f0d31d32131641293c5..3062152ed57e2a5fc6775eb4ec927d365a6d4a1d 100644 |
--- a/components/offline_pages/background/request_picker.h |
+++ b/components/offline_pages/background/request_picker.h |
@@ -5,14 +5,22 @@ |
#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ |
#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ |
+#include <memory> |
+ |
#include "base/memory/weak_ptr.h" |
+#include "components/offline_pages/background/device_conditions.h" |
+#include "components/offline_pages/background/offliner_policy.h" |
#include "components/offline_pages/background/request_coordinator.h" |
#include "components/offline_pages/background/request_queue.h" |
namespace offline_pages { |
+ |
+typedef bool (RequestPicker::*RequestCompareFunction)( |
+ const SavePageRequest* left, const SavePageRequest* right); |
+ |
class RequestPicker { |
public: |
- RequestPicker(RequestQueue* requestQueue); |
+ RequestPicker(RequestQueue* requestQueue, OfflinerPolicy* policy); |
~RequestPicker(); |
@@ -20,15 +28,51 @@ class RequestPicker { |
// conditions, and call back to the RequestCoordinator when we have one. |
void ChooseNextRequest( |
RequestCoordinator::RequestPickedCallback picked_callback, |
- RequestCoordinator::RequestQueueEmptyCallback empty_callback); |
+ RequestCoordinator::RequestQueueEmptyCallback empty_callback, |
+ DeviceConditions* device_conditions); |
private: |
// Callback for the GetRequest results to be delivered. |
void GetRequestResultCallback(RequestQueue::GetRequestsResult result, |
const std::vector<SavePageRequest>& results); |
+ // Filter out requests that don't meet the current conditions. For instance, |
+ // if this is a predictive request, and we are not on WiFi, it should be |
+ // ignored this round. |
+ bool RequestConditionsSatisfied(const SavePageRequest& request); |
+ |
+ // Using policies, decide if the new request is preferable to the best we have |
+ // so far. |
+ bool IsNewRequestBetter(const SavePageRequest* oldRequest, |
+ const SavePageRequest* newRequest, |
+ RequestCompareFunction comparator); |
+ |
+ // Is the new request preferable from the retry count first standpoint? |
+ bool RetryCountFirstCompareFunction(const SavePageRequest* left, |
+ const SavePageRequest* right); |
+ |
+ // Is the new request better from the recency first standpoint? |
+ bool RecencyFirstCompareFunction(const SavePageRequest* left, |
+ const SavePageRequest* right); |
+ |
+ // Does the new request have better retry count? |
+ int CompareRetryCount(const SavePageRequest* left, |
+ const SavePageRequest* right); |
+ |
+ // Does the new request have better creation time? |
+ int CompareCreationTime(const SavePageRequest* left, |
+ const SavePageRequest* right); |
+ |
// unowned pointer to the request queue. |
RequestQueue* queue_; |
+ // unowned pointer to the policy object. |
+ OfflinerPolicy* policy_; |
+ // Current conditions on the device |
+ std::unique_ptr<DeviceConditions> current_conditions_; |
+ // True if we prefer less-tried requests |
+ bool fewer_retries_better_; |
+ // True if we prefer requests submitted more recently |
+ bool earlier_requests_better_; |
// Callback for when we are done picking a request to do next. |
RequestCoordinator::RequestPickedCallback picked_callback_; |
// Callback for when there are no more reqeusts to pick. |