| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 RequestQueue* queue() { return queue_.get(); } | 66 RequestQueue* queue() { return queue_.get(); } |
| 67 | 67 |
| 68 // Return an unowned pointer to the Scheduler. | 68 // Return an unowned pointer to the Scheduler. |
| 69 Scheduler* scheduler() { return scheduler_.get(); } | 69 Scheduler* scheduler() { return scheduler_.get(); } |
| 70 | 70 |
| 71 // Returns the status of the most recent offlining. | 71 // Returns the status of the most recent offlining. |
| 72 Offliner::RequestStatus last_offlining_status() { | 72 Offliner::RequestStatus last_offlining_status() { |
| 73 return last_offlining_status_; | 73 return last_offlining_status_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool is_busy() { |
| 77 return is_busy_; |
| 78 } |
| 79 |
| 76 private: | 80 private: |
| 77 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 81 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 78 const SavePageRequest& request); | 82 const SavePageRequest& request); |
| 79 | 83 |
| 80 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); | 84 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); |
| 81 | 85 |
| 82 // Callback from the request picker when it has chosen our next request. | 86 // Callback from the request picker when it has chosen our next request. |
| 83 void RequestPicked(const SavePageRequest& request); | 87 void RequestPicked(const SavePageRequest& request); |
| 84 | 88 |
| 85 // Callback from the request picker when no more requests are in the queue. | 89 // Callback from the request picker when no more requests are in the queue. |
| 86 void RequestQueueEmpty(); | 90 void RequestQueueEmpty(); |
| 87 | 91 |
| 88 void SendRequestToOffliner(const SavePageRequest& request); | 92 void SendRequestToOffliner(const SavePageRequest& request); |
| 89 | 93 |
| 90 // Called by the offliner when an offlining request is completed. (and by | 94 // Called by the offliner when an offlining request is completed. (and by |
| 91 // tests). | 95 // tests). |
| 92 void OfflinerDoneCallback(const SavePageRequest& request, | 96 void OfflinerDoneCallback(const SavePageRequest& request, |
| 93 Offliner::RequestStatus status); | 97 Offliner::RequestStatus status); |
| 94 | 98 |
| 95 void TryNextRequest(); | 99 void TryNextRequest(); |
| 96 | 100 |
| 97 friend class RequestCoordinatorTest; | 101 friend class RequestCoordinatorTest; |
| 98 | 102 |
| 103 // The offliner can only handle one request at a time - if the offliner is |
| 104 // busy, prevent other requests. This flag marks whether the offliner is in |
| 105 // use. |
| 106 bool is_busy_; |
| 99 // RequestCoordinator takes over ownership of the policy | 107 // RequestCoordinator takes over ownership of the policy |
| 100 std::unique_ptr<OfflinerPolicy> policy_; | 108 std::unique_ptr<OfflinerPolicy> policy_; |
| 101 // OfflinerFactory. Used to create offline pages. Owned. | 109 // OfflinerFactory. Used to create offline pages. Owned. |
| 102 std::unique_ptr<OfflinerFactory> factory_; | 110 std::unique_ptr<OfflinerFactory> factory_; |
| 103 // RequestQueue. Used to store incoming requests. Owned. | 111 // RequestQueue. Used to store incoming requests. Owned. |
| 104 std::unique_ptr<RequestQueue> queue_; | 112 std::unique_ptr<RequestQueue> queue_; |
| 105 // Scheduler. Used to request a callback when network is available. Owned. | 113 // Scheduler. Used to request a callback when network is available. Owned. |
| 106 std::unique_ptr<Scheduler> scheduler_; | 114 std::unique_ptr<Scheduler> scheduler_; |
| 107 // Status of the most recent offlining. | 115 // Status of the most recent offlining. |
| 108 Offliner::RequestStatus last_offlining_status_; | 116 Offliner::RequestStatus last_offlining_status_; |
| 109 // Class to choose which request to schedule next | 117 // Class to choose which request to schedule next |
| 110 std::unique_ptr<RequestPicker> picker_; | 118 std::unique_ptr<RequestPicker> picker_; |
| 111 // Calling this returns to the scheduler across the JNI bridge. | 119 // Calling this returns to the scheduler across the JNI bridge. |
| 112 base::Callback<void(bool)> scheduler_callback_; | 120 base::Callback<void(bool)> scheduler_callback_; |
| 113 // Allows us to pass a weak pointer to callbacks. | 121 // Allows us to pass a weak pointer to callbacks. |
| 114 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 122 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 115 | 123 |
| 116 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 124 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 117 }; | 125 }; |
| 118 | 126 |
| 119 } // namespace offline_pages | 127 } // namespace offline_pages |
| 120 | 128 |
| 121 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 129 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |