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

Unified Diff: components/offline_pages/background/request_picker.h

Issue 2113383002: More detailed implementation of the RequestPicker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify picker logic for multiple criteria Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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..ca66093fd03459bf183ee1457d5cbdd95f11c3d7 100644
--- a/components/offline_pages/background/request_picker.h
+++ b/components/offline_pages/background/request_picker.h
@@ -5,14 +5,25 @@
#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 {
+// This is used to compare requests to find the more desirable request under
+// current policies.
+enum ComparisonResult {
+ Worse = -1, Same = 0, Better = 1
fgorski 2016/07/20 16:23:31 nit: there are some indentation issues here.
Pete Williamson 2016/07/20 19:50:44 Done. (danger of cut and paste coding, their stand
+ };
+
+
class RequestPicker {
public:
- RequestPicker(RequestQueue* requestQueue);
+ RequestPicker(RequestQueue* requestQueue, OfflinerPolicy* policy);
~RequestPicker();
@@ -20,15 +31,39 @@ 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?
+ ComparisonResult IsNewRequestRetryCountBetter(
+ const SavePageRequest* oldRequest, const SavePageRequest* newRequest);
+
+ // Is the new request better from the recency standpoint?
+ ComparisonResult
+ 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.

Powered by Google App Engine
This is Rietveld 408576698