Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | |
| 9 | |
| 8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "components/offline_pages/background/device_conditions.h" | |
| 12 #include "components/offline_pages/background/offliner_policy.h" | |
| 9 #include "components/offline_pages/background/request_coordinator.h" | 13 #include "components/offline_pages/background/request_coordinator.h" |
| 10 #include "components/offline_pages/background/request_queue.h" | 14 #include "components/offline_pages/background/request_queue.h" |
| 11 | 15 |
| 12 namespace offline_pages { | 16 namespace offline_pages { |
| 13 class RequestPicker { | 17 class RequestPicker { |
| 14 public: | 18 public: |
| 15 RequestPicker(RequestQueue* requestQueue); | 19 RequestPicker(RequestQueue* requestQueue, OfflinerPolicy* policy); |
|
dougarnett
2016/07/18 21:45:45
indent
Pete Williamson
2016/07/18 22:52:09
Done.
| |
| 16 | 20 |
| 17 ~RequestPicker(); | 21 ~RequestPicker(); |
| 18 | 22 |
| 19 // Choose which request we should process next based on the current | 23 // Choose which request we should process next based on the current |
| 20 // conditions, and call back to the RequestCoordinator when we have one. | 24 // conditions, and call back to the RequestCoordinator when we have one. |
| 21 void ChooseNextRequest( | 25 void ChooseNextRequest( |
| 22 RequestCoordinator::RequestPickedCallback picked_callback, | 26 RequestCoordinator::RequestPickedCallback picked_callback, |
| 23 RequestCoordinator::RequestQueueEmptyCallback empty_callback); | 27 RequestCoordinator::RequestQueueEmptyCallback empty_callback, |
| 28 DeviceConditions* device_conditions); | |
| 24 | 29 |
| 25 private: | 30 private: |
| 26 // Callback for the GetRequest results to be delivered. | 31 // Callback for the GetRequest results to be delivered. |
| 27 void GetRequestResultCallback(RequestQueue::GetRequestsResult result, | 32 void GetRequestResultCallback(RequestQueue::GetRequestsResult result, |
| 28 const std::vector<SavePageRequest>& results); | 33 const std::vector<SavePageRequest>& results); |
| 29 | 34 |
| 35 // Filter out requests that don't meet the current conditions. For instance, | |
| 36 // if this is a predictive request, and we are not on WiFi, it should be | |
| 37 // ignored this round. | |
| 38 bool RequestMeetsConditions(const SavePageRequest& request); | |
| 39 | |
| 40 // Using policies, decide if the new request is preferable to the best we have | |
| 41 // so far. | |
| 42 bool IsNewRequestBetter(const SavePageRequest* oldRequest, | |
| 43 const SavePageRequest* newRequest); | |
| 44 | |
| 30 // unowned pointer to the request queue. | 45 // unowned pointer to the request queue. |
| 31 RequestQueue* queue_; | 46 RequestQueue* queue_; |
| 47 // unowned pointer to the policy object. | |
| 48 OfflinerPolicy* policy_; | |
| 49 // Current conditions on the device | |
| 50 std::unique_ptr<DeviceConditions> current_conditions_; | |
| 32 // Callback for when we are done picking a request to do next. | 51 // Callback for when we are done picking a request to do next. |
| 33 RequestCoordinator::RequestPickedCallback picked_callback_; | 52 RequestCoordinator::RequestPickedCallback picked_callback_; |
| 34 // Callback for when there are no more reqeusts to pick. | 53 // Callback for when there are no more reqeusts to pick. |
| 35 RequestCoordinator::RequestQueueEmptyCallback empty_callback_; | 54 RequestCoordinator::RequestQueueEmptyCallback empty_callback_; |
| 36 // Allows us to pass a weak pointer to callbacks. | 55 // Allows us to pass a weak pointer to callbacks. |
| 37 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; | 56 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; |
| 38 }; | 57 }; |
| 39 | 58 |
| 40 } // namespace offline_pages | 59 } // namespace offline_pages |
| 41 | 60 |
| 42 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ | 61 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ |
| OLD | NEW |