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