| 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 #include "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 offliner_->LoadAndSave(request, | 143 offliner_->LoadAndSave(request, |
| 144 base::Bind(&RequestCoordinator::OfflinerDoneCallback, | 144 base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
| 145 weak_ptr_factory_.GetWeakPtr())); | 145 weak_ptr_factory_.GetWeakPtr())); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, | 148 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| 149 Offliner::RequestStatus status) { | 149 Offliner::RequestStatus status) { |
| 150 DVLOG(2) << "offliner finished, saved: " | 150 DVLOG(2) << "offliner finished, saved: " |
| 151 << (status == Offliner::RequestStatus::SAVED) << ", status: " | 151 << (status == Offliner::RequestStatus::SAVED) << ", status: " |
| 152 << (int) status << ", " << __FUNCTION__; | 152 << (int) status << ", " << __FUNCTION__; |
| 153 event_logger_.RecordSavePageRequestUpdated( |
| 154 request.client_id().name_space, |
| 155 "Saved", |
| 156 request.request_id()); |
| 153 last_offlining_status_ = status; | 157 last_offlining_status_ = status; |
| 154 | 158 |
| 155 is_busy_ = false; | 159 is_busy_ = false; |
| 156 | 160 |
| 157 // If the request succeeded, remove it from the Queue and maybe schedule | 161 // If the request succeeded, remove it from the Queue and maybe schedule |
| 158 // another one. | 162 // another one. |
| 159 if (status == Offliner::RequestStatus::SAVED) { | 163 if (status == Offliner::RequestStatus::SAVED) { |
| 160 queue_->RemoveRequest(request.request_id(), | 164 queue_->RemoveRequest(request.request_id(), |
| 161 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 165 base::Bind(&RequestCoordinator::UpdateRequestCallback, |
| 162 weak_ptr_factory_.GetWeakPtr())); | 166 weak_ptr_factory_.GetWeakPtr())); |
| 163 | 167 |
| 164 // TODO(petewil): Check time budget. Return to the scheduler if we are out. | 168 // TODO(petewil): Check time budget. Return to the scheduler if we are out. |
| 165 | 169 |
| 166 // Start another request if we have time. | 170 // Start another request if we have time. |
| 167 TryNextRequest(); | 171 TryNextRequest(); |
| 168 } | 172 } |
| 169 } | 173 } |
| 170 | 174 |
| 171 const Scheduler::TriggerConditions& | 175 const Scheduler::TriggerConditions& |
| 172 RequestCoordinator::GetTriggerConditionsForUserRequest() { | 176 RequestCoordinator::GetTriggerConditionsForUserRequest() { |
| 173 return kUserRequestTriggerConditions; | 177 return kUserRequestTriggerConditions; |
| 174 } | 178 } |
| 175 | 179 |
| 176 void RequestCoordinator::GetOffliner() { | 180 void RequestCoordinator::GetOffliner() { |
| 177 if (!offliner_) { | 181 if (!offliner_) { |
| 178 offliner_ = factory_->GetOffliner(policy_.get()); | 182 offliner_ = factory_->GetOffliner(policy_.get()); |
| 179 } | 183 } |
| 180 } | 184 } |
| 181 | 185 |
| 182 } // namespace offline_pages | 186 } // namespace offline_pages |
| OLD | NEW |