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_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 bool is_busy_; | |
|
fgorski
2016/06/21 18:11:18
please add documentation here. What does is_busy m
Pete Williamson
2016/06/21 18:33:56
Done.
| |
| 99 // RequestCoordinator takes over ownership of the policy | 104 // RequestCoordinator takes over ownership of the policy |
| 100 std::unique_ptr<OfflinerPolicy> policy_; | 105 std::unique_ptr<OfflinerPolicy> policy_; |
| 101 // OfflinerFactory. Used to create offline pages. Owned. | 106 // OfflinerFactory. Used to create offline pages. Owned. |
| 102 std::unique_ptr<OfflinerFactory> factory_; | 107 std::unique_ptr<OfflinerFactory> factory_; |
| 103 // RequestQueue. Used to store incoming requests. Owned. | 108 // RequestQueue. Used to store incoming requests. Owned. |
| 104 std::unique_ptr<RequestQueue> queue_; | 109 std::unique_ptr<RequestQueue> queue_; |
| 105 // Scheduler. Used to request a callback when network is available. Owned. | 110 // Scheduler. Used to request a callback when network is available. Owned. |
| 106 std::unique_ptr<Scheduler> scheduler_; | 111 std::unique_ptr<Scheduler> scheduler_; |
| 107 // Status of the most recent offlining. | 112 // Status of the most recent offlining. |
| 108 Offliner::RequestStatus last_offlining_status_; | 113 Offliner::RequestStatus last_offlining_status_; |
| 109 // Class to choose which request to schedule next | 114 // Class to choose which request to schedule next |
| 110 std::unique_ptr<RequestPicker> picker_; | 115 std::unique_ptr<RequestPicker> picker_; |
| 111 // Calling this returns to the scheduler across the JNI bridge. | 116 // Calling this returns to the scheduler across the JNI bridge. |
| 112 base::Callback<void(bool)> scheduler_callback_; | 117 base::Callback<void(bool)> scheduler_callback_; |
| 113 // Allows us to pass a weak pointer to callbacks. | 118 // Allows us to pass a weak pointer to callbacks. |
| 114 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 119 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 115 | 120 |
| 116 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 121 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 117 }; | 122 }; |
| 118 | 123 |
| 119 } // namespace offline_pages | 124 } // namespace offline_pages |
| 120 | 125 |
| 121 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 126 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |