| 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> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "components/offline_pages/background/device_conditions.h" | 11 #include "components/offline_pages/background/device_conditions.h" |
| 12 #include "components/offline_pages/background/offliner_policy.h" | 12 #include "components/offline_pages/background/offliner_policy.h" |
| 13 #include "components/offline_pages/background/request_coordinator.h" | 13 #include "components/offline_pages/background/request_coordinator.h" |
| 14 #include "components/offline_pages/background/request_queue.h" | 14 #include "components/offline_pages/background/request_queue.h" |
| 15 | 15 |
| 16 namespace offline_pages { | 16 namespace offline_pages { |
| 17 | 17 |
| 18 class RequestNotifier; |
| 19 |
| 18 typedef bool (RequestPicker::*RequestCompareFunction)( | 20 typedef bool (RequestPicker::*RequestCompareFunction)( |
| 19 const SavePageRequest* left, const SavePageRequest* right); | 21 const SavePageRequest* left, const SavePageRequest* right); |
| 20 | 22 |
| 21 class RequestPicker { | 23 class RequestPicker { |
| 22 public: | 24 public: |
| 23 RequestPicker(RequestQueue* requestQueue, OfflinerPolicy* policy); | 25 RequestPicker(RequestQueue* requestQueue, |
| 26 OfflinerPolicy* policy, |
| 27 RequestNotifier* notifier); |
| 24 | 28 |
| 25 ~RequestPicker(); | 29 ~RequestPicker(); |
| 26 | 30 |
| 27 // Choose which request we should process next based on the current | 31 // Choose which request we should process next based on the current |
| 28 // conditions, and call back to the RequestCoordinator when we have one. | 32 // conditions, and call back to the RequestCoordinator when we have one. |
| 29 void ChooseNextRequest( | 33 void ChooseNextRequest( |
| 30 RequestCoordinator::RequestPickedCallback picked_callback, | 34 RequestCoordinator::RequestPickedCallback picked_callback, |
| 31 RequestCoordinator::RequestQueueEmptyCallback empty_callback, | 35 RequestCoordinator::RequestQueueEmptyCallback empty_callback, |
| 32 DeviceConditions* device_conditions); | 36 DeviceConditions* device_conditions); |
| 33 | 37 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 const SavePageRequest* right); | 60 const SavePageRequest* right); |
| 57 | 61 |
| 58 // Does the new request have better retry count? | 62 // Does the new request have better retry count? |
| 59 int CompareRetryCount(const SavePageRequest* left, | 63 int CompareRetryCount(const SavePageRequest* left, |
| 60 const SavePageRequest* right); | 64 const SavePageRequest* right); |
| 61 | 65 |
| 62 // Does the new request have better creation time? | 66 // Does the new request have better creation time? |
| 63 int CompareCreationTime(const SavePageRequest* left, | 67 int CompareCreationTime(const SavePageRequest* left, |
| 64 const SavePageRequest* right); | 68 const SavePageRequest* right); |
| 65 | 69 |
| 66 // unowned pointer to the request queue. | 70 // Split all requests into expired ones and still valid ones. |
| 71 void SplitRequests(const std::vector<SavePageRequest>& requests, |
| 72 std::vector<SavePageRequest>& valid_requests, |
| 73 std::vector<SavePageRequest>& expired_requests); |
| 74 |
| 75 // Callback used after requests get expired. |
| 76 void OnRequestExpired( |
| 77 const RequestQueue::UpdateMultipleRequestResults& results, |
| 78 const std::vector<SavePageRequest>& requests); |
| 79 |
| 80 // Unowned pointer to the request queue. |
| 67 RequestQueue* queue_; | 81 RequestQueue* queue_; |
| 68 // unowned pointer to the policy object. | 82 // Unowned pointer to the policy object. |
| 69 OfflinerPolicy* policy_; | 83 OfflinerPolicy* policy_; |
| 84 // Unowned pointer to the request coordinator. |
| 85 RequestNotifier* notifier_; |
| 70 // Current conditions on the device | 86 // Current conditions on the device |
| 71 std::unique_ptr<DeviceConditions> current_conditions_; | 87 std::unique_ptr<DeviceConditions> current_conditions_; |
| 72 // True if we prefer less-tried requests | 88 // True if we prefer less-tried requests |
| 73 bool fewer_retries_better_; | 89 bool fewer_retries_better_; |
| 74 // True if we prefer requests submitted more recently | 90 // True if we prefer requests submitted more recently |
| 75 bool earlier_requests_better_; | 91 bool earlier_requests_better_; |
| 76 // Callback for when we are done picking a request to do next. | 92 // Callback for when we are done picking a request to do next. |
| 77 RequestCoordinator::RequestPickedCallback picked_callback_; | 93 RequestCoordinator::RequestPickedCallback picked_callback_; |
| 78 // Callback for when there are no more reqeusts to pick. | 94 // Callback for when there are no more reqeusts to pick. |
| 79 RequestCoordinator::RequestQueueEmptyCallback empty_callback_; | 95 RequestCoordinator::RequestQueueEmptyCallback empty_callback_; |
| 80 // Allows us to pass a weak pointer to callbacks. | 96 // Allows us to pass a weak pointer to callbacks. |
| 81 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; | 97 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; |
| 82 }; | 98 }; |
| 83 | 99 |
| 84 } // namespace offline_pages | 100 } // namespace offline_pages |
| 85 | 101 |
| 86 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ | 102 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ |
| OLD | NEW |