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..5dbd5f12e6170b220373ce4a7ad62b6c9cc8e27f 100644 |
--- a/components/offline_pages/background/request_picker.h |
+++ b/components/offline_pages/background/request_picker.h |
@@ -5,14 +5,18 @@ |
#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 { |
class RequestPicker { |
public: |
- RequestPicker(RequestQueue* requestQueue); |
+ RequestPicker(RequestQueue* requestQueue, OfflinerPolicy* policy); |
~RequestPicker(); |
@@ -20,15 +24,38 @@ 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); |
+ |
+ // Is the new request preferable from the retry count standpoint? |
+ int IsNewRequestRetryCountBetter(const SavePageRequest* oldRequest, |
+ const SavePageRequest* newRequest); |
+ |
+ // Is the new request better from the recency standpoint? |
+ int IsNewRequestRecencyBetter(const SavePageRequest* oldRequest, |
+ const SavePageRequest* newRequest); |
+ |
// 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_; |
// 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. |