| 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_coordinator_event_logger.h
" |
| 14 #include "components/offline_pages/background/request_queue.h" | 15 #include "components/offline_pages/background/request_queue.h" |
| 15 | 16 |
| 16 namespace offline_pages { | 17 namespace offline_pages { |
| 17 | 18 |
| 18 class RequestNotifier; | 19 class RequestNotifier; |
| 19 | 20 |
| 20 typedef bool (RequestPicker::*RequestCompareFunction)( | 21 typedef bool (RequestPicker::*RequestCompareFunction)( |
| 21 const SavePageRequest* left, const SavePageRequest* right); | 22 const SavePageRequest* left, const SavePageRequest* right); |
| 22 | 23 |
| 23 class RequestPicker { | 24 class RequestPicker { |
| 24 public: | 25 public: |
| 25 RequestPicker(RequestQueue* requestQueue, | 26 RequestPicker(RequestQueue* requestQueue, |
| 26 OfflinerPolicy* policy, | 27 OfflinerPolicy* policy, |
| 27 RequestNotifier* notifier); | 28 RequestNotifier* notifier, |
| 29 RequestCoordinatorEventLogger* event_logger); |
| 28 | 30 |
| 29 ~RequestPicker(); | 31 ~RequestPicker(); |
| 30 | 32 |
| 31 // Choose which request we should process next based on the current | 33 // Choose which request we should process next based on the current |
| 32 // conditions, and call back to the RequestCoordinator when we have one. | 34 // conditions, and call back to the RequestCoordinator when we have one. |
| 33 void ChooseNextRequest( | 35 void ChooseNextRequest( |
| 34 RequestCoordinator::RequestPickedCallback picked_callback, | 36 RequestCoordinator::RequestPickedCallback picked_callback, |
| 35 RequestCoordinator::RequestNotPickedCallback not_picked_callback, | 37 RequestCoordinator::RequestNotPickedCallback not_picked_callback, |
| 36 DeviceConditions* device_conditions); | 38 DeviceConditions* device_conditions); |
| 37 | 39 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void OnRequestExpired( | 81 void OnRequestExpired( |
| 80 const RequestQueue::UpdateMultipleRequestResults& results, | 82 const RequestQueue::UpdateMultipleRequestResults& results, |
| 81 const std::vector<std::unique_ptr<SavePageRequest>> requests); | 83 const std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 82 | 84 |
| 83 // Unowned pointer to the request queue. | 85 // Unowned pointer to the request queue. |
| 84 RequestQueue* queue_; | 86 RequestQueue* queue_; |
| 85 // Unowned pointer to the policy object. | 87 // Unowned pointer to the policy object. |
| 86 OfflinerPolicy* policy_; | 88 OfflinerPolicy* policy_; |
| 87 // Unowned pointer to the request coordinator. | 89 // Unowned pointer to the request coordinator. |
| 88 RequestNotifier* notifier_; | 90 RequestNotifier* notifier_; |
| 91 // Unowned pointer to the event logger. |
| 92 RequestCoordinatorEventLogger* event_logger_; |
| 89 // Current conditions on the device | 93 // Current conditions on the device |
| 90 std::unique_ptr<DeviceConditions> current_conditions_; | 94 std::unique_ptr<DeviceConditions> current_conditions_; |
| 91 // True if we prefer less-tried requests | 95 // True if we prefer less-tried requests |
| 92 bool fewer_retries_better_; | 96 bool fewer_retries_better_; |
| 93 // True if we prefer requests submitted more recently | 97 // True if we prefer requests submitted more recently |
| 94 bool earlier_requests_better_; | 98 bool earlier_requests_better_; |
| 95 // Callback for when we are done picking a request to do next. | 99 // Callback for when we are done picking a request to do next. |
| 96 RequestCoordinator::RequestPickedCallback picked_callback_; | 100 RequestCoordinator::RequestPickedCallback picked_callback_; |
| 97 // Callback for when there are no more reqeusts to pick. | 101 // Callback for when there are no more reqeusts to pick. |
| 98 RequestCoordinator::RequestNotPickedCallback not_picked_callback_; | 102 RequestCoordinator::RequestNotPickedCallback not_picked_callback_; |
| 99 // Allows us to pass a weak pointer to callbacks. | 103 // Allows us to pass a weak pointer to callbacks. |
| 100 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; | 104 base::WeakPtrFactory<RequestPicker> weak_ptr_factory_; |
| 101 }; | 105 }; |
| 102 | 106 |
| 103 } // namespace offline_pages | 107 } // namespace offline_pages |
| 104 | 108 |
| 105 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ | 109 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_PICKER_H_ |
| OLD | NEW |