| 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_COORDINATOR_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 // Returns the status of the most recent offlining. | 75 // Returns the status of the most recent offlining. |
| 76 Offliner::RequestStatus last_offlining_status() { | 76 Offliner::RequestStatus last_offlining_status() { |
| 77 return last_offlining_status_; | 77 return last_offlining_status_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool is_busy() { | 80 bool is_busy() { |
| 81 return is_busy_; | 81 return is_busy_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Tracks whether the last offlining attempt got canceled. This is reset by |
| 85 // the next StartProcessing() call. |
| 86 bool is_canceled() { |
| 87 return is_canceled_; |
| 88 } |
| 89 |
| 84 private: | 90 private: |
| 85 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 91 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 86 const SavePageRequest& request); | 92 const SavePageRequest& request); |
| 87 | 93 |
| 88 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); | 94 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); |
| 89 | 95 |
| 90 // Callback from the request picker when it has chosen our next request. | 96 // Callback from the request picker when it has chosen our next request. |
| 91 void RequestPicked(const SavePageRequest& request); | 97 void RequestPicked(const SavePageRequest& request); |
| 92 | 98 |
| 93 // Callback from the request picker when no more requests are in the queue. | 99 // Callback from the request picker when no more requests are in the queue. |
| 94 void RequestQueueEmpty(); | 100 void RequestQueueEmpty(); |
| 95 | 101 |
| 96 void SendRequestToOffliner(const SavePageRequest& request); | 102 void SendRequestToOffliner(const SavePageRequest& request); |
| 97 | 103 |
| 98 // Called by the offliner when an offlining request is completed. (and by | 104 // Called by the offliner when an offlining request is completed. (and by |
| 99 // tests). | 105 // tests). |
| 100 void OfflinerDoneCallback(const SavePageRequest& request, | 106 void OfflinerDoneCallback(const SavePageRequest& request, |
| 101 Offliner::RequestStatus status); | 107 Offliner::RequestStatus status); |
| 102 | 108 |
| 103 void TryNextRequest(); | 109 void TryNextRequest(); |
| 104 | 110 |
| 111 // Returns the appropriate offliner to use, getting a new one from the factory |
| 112 // if needed. |
| 113 void GetOffliner(); |
| 114 |
| 105 friend class RequestCoordinatorTest; | 115 friend class RequestCoordinatorTest; |
| 106 | 116 |
| 107 // The offliner can only handle one request at a time - if the offliner is | 117 // The offliner can only handle one request at a time - if the offliner is |
| 108 // busy, prevent other requests. This flag marks whether the offliner is in | 118 // busy, prevent other requests. This flag marks whether the offliner is in |
| 109 // use. | 119 // use. |
| 110 bool is_busy_; | 120 bool is_busy_; |
| 121 // True if the current request has been canceled. |
| 122 bool is_canceled_; |
| 123 // Unowned pointer to the current offliner, if any. |
| 124 Offliner* offliner_; |
| 111 // RequestCoordinator takes over ownership of the policy | 125 // RequestCoordinator takes over ownership of the policy |
| 112 std::unique_ptr<OfflinerPolicy> policy_; | 126 std::unique_ptr<OfflinerPolicy> policy_; |
| 113 // OfflinerFactory. Used to create offline pages. Owned. | 127 // OfflinerFactory. Used to create offline pages. Owned. |
| 114 std::unique_ptr<OfflinerFactory> factory_; | 128 std::unique_ptr<OfflinerFactory> factory_; |
| 115 // RequestQueue. Used to store incoming requests. Owned. | 129 // RequestQueue. Used to store incoming requests. Owned. |
| 116 std::unique_ptr<RequestQueue> queue_; | 130 std::unique_ptr<RequestQueue> queue_; |
| 117 // Scheduler. Used to request a callback when network is available. Owned. | 131 // Scheduler. Used to request a callback when network is available. Owned. |
| 118 std::unique_ptr<Scheduler> scheduler_; | 132 std::unique_ptr<Scheduler> scheduler_; |
| 119 // Status of the most recent offlining. | 133 // Status of the most recent offlining. |
| 120 Offliner::RequestStatus last_offlining_status_; | 134 Offliner::RequestStatus last_offlining_status_; |
| 121 // Class to choose which request to schedule next | 135 // Class to choose which request to schedule next |
| 122 std::unique_ptr<RequestPicker> picker_; | 136 std::unique_ptr<RequestPicker> picker_; |
| 123 // Calling this returns to the scheduler across the JNI bridge. | 137 // Calling this returns to the scheduler across the JNI bridge. |
| 124 base::Callback<void(bool)> scheduler_callback_; | 138 base::Callback<void(bool)> scheduler_callback_; |
| 125 // Allows us to pass a weak pointer to callbacks. | 139 // Allows us to pass a weak pointer to callbacks. |
| 126 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 140 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 127 | 141 |
| 128 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 142 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 129 }; | 143 }; |
| 130 | 144 |
| 131 } // namespace offline_pages | 145 } // namespace offline_pages |
| 132 | 146 |
| 133 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 147 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |