Chromium Code Reviews| Index: components/offline_pages/background/request_coordinator.cc |
| diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc |
| index d5e87d26a47a8fd93aa7af30aa2dacef1ad23837..eba6616180de5e6fffc432c832be4ca0690de600 100644 |
| --- a/components/offline_pages/background/request_coordinator.cc |
| +++ b/components/offline_pages/background/request_coordinator.cc |
| @@ -22,7 +22,8 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| std::unique_ptr<OfflinerFactory> factory, |
| std::unique_ptr<RequestQueue> queue, |
| std::unique_ptr<Scheduler> scheduler) |
| - : policy_(std::move(policy)), |
| + : request_in_progress_(false), |
| + policy_(std::move(policy)), |
| factory_(std::move(factory)), |
| queue_(std::move(queue)), |
| scheduler_(std::move(scheduler)), |
| @@ -50,11 +51,6 @@ bool RequestCoordinator::SavePageLater( |
| queue_->AddRequest(request, |
| base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| weak_ptr_factory_.GetWeakPtr())); |
| - // TODO(petewil): Do I need to persist the request in case the add fails? |
| - |
| - // TODO(petewil): Make a new chromium command line switch to send the request |
| - // immediately for testing. It should call SendRequestToOffliner() |
| - |
| return true; |
| } |
| @@ -85,19 +81,21 @@ void RequestCoordinator::RequestQueueEmpty() { |
| scheduler_callback_.Run(true); |
| } |
| +// Returns true if the caller should expect a callback, false otherwise. For |
| +// instance, this would return false if a request is already in progress. |
| bool RequestCoordinator::StartProcessing( |
| const DeviceConditions& device_conditions, |
| const base::Callback<void(bool)>& callback) { |
| + if (request_in_progress_) { |
|
fgorski
2016/06/20 20:24:07
nit: {} are not necessary here. (not required by t
Pete Williamson
2016/06/21 17:55:25
Done.
|
| + return false; |
| + } |
| + |
| scheduler_callback_ = callback; |
| // TODO(petewil): Check existing conditions (should be passed down from |
| // BackgroundTask) |
| TryNextRequest(); |
| - // TODO(petewil): Should return true if the caller should expect a |
| - // callback. Return false if there is already a request running. |
| - // Probably best to do this when I prevent multiple instances from |
| - // running at the same time. |
| return true; |
| } |
| @@ -115,7 +113,6 @@ void RequestCoordinator::StopProcessing() { |
| } |
| void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
| - // TODO(petewil): Ensure only one offliner at a time is used. |
| // TODO(petewil): When we have multiple offliners, we need to pick one. |
| Offliner* offliner = factory_->GetOffliner(policy_.get()); |
| if (!offliner) { |
| @@ -124,6 +121,9 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
| return; |
| } |
| + DCHECK(request_in_progress_ == false); |
|
fgorski
2016/06/20 20:24:07
nit: DCHECK(!request_in_progress_);
Pete Williamson
2016/06/21 17:55:25
Done.
|
| + request_in_progress_ = true; |
| + |
| // Start the load and save process in the offliner (Async). |
| offliner->LoadAndSave(request, |
| base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
| @@ -137,6 +137,8 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| << __FUNCTION__; |
| last_offlining_status_ = status; |
| + request_in_progress_ = false; |
|
fgorski
2016/06/20 20:24:07
do you think it makes sense to DCHECK(request_in_p
Pete Williamson
2016/06/21 17:55:25
Done.
Pete Williamson
2016/06/21 17:57:45
Oops, I did it and then undid it. I undid it sinc
|
| + |
| // If the request succeeded, remove it from the Queue and maybe schedule |
| // another one. |
| if (status == Offliner::RequestStatus::SAVED) { |