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 bd82c99ef2af5ec477d697ce1199839d5e4ab8b6..510361bc4ab13d306e971f553febe1f75a0d4096 100644 |
--- a/components/offline_pages/background/request_coordinator.cc |
+++ b/components/offline_pages/background/request_coordinator.cc |
@@ -88,6 +88,7 @@ bool RequestCoordinator::SavePageLater( |
queue_->AddRequest(request, |
base::Bind(&RequestCoordinator::AddRequestResultCallback, |
weak_ptr_factory_.GetWeakPtr())); |
+ NotifyAvailable(client_id); |
return true; |
} |
void RequestCoordinator::GetQueuedRequests( |
@@ -129,6 +130,8 @@ void RequestCoordinator::PauseRequests( |
queue_->PauseRequestsByClientId( |
client_ids, base::Bind(&RequestCoordinator::UpdateMultipleRequestCallback, |
weak_ptr_factory_.GetWeakPtr())); |
+ for(ClientId client_id : client_ids) |
+ NotifyPaused(client_id); |
} |
void RequestCoordinator::ResumeRequests( |
@@ -137,12 +140,13 @@ void RequestCoordinator::ResumeRequests( |
client_ids, base::Bind(&RequestCoordinator::UpdateMultipleRequestCallback, |
weak_ptr_factory_.GetWeakPtr())); |
// TODO: Should we also schedule a task, in case there is not one scheduled? |
+ for (ClientId client_id : client_ids) |
+ NotifyAvailable(client_id); |
} |
void RequestCoordinator::AddRequestResultCallback( |
RequestQueue::AddRequestResult result, |
const SavePageRequest& request) { |
- |
// Inform the scheduler that we have an outstanding task.. |
scheduler_->Schedule(GetTriggerConditionsForUserRequest()); |
} |
@@ -316,21 +320,30 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
base::Bind(&RequestCoordinator::UpdateRequestCallback, |
weak_ptr_factory_.GetWeakPtr(), |
updated_request.client_id())); |
+ NotifyFailed(request.client_id()); |
- } else if (status == Offliner::RequestStatus::SAVED || |
- request.completed_attempt_count() + 1 >= |
- policy_->GetMaxCompletedTries()) { |
- // Remove the request from the queue if it either succeeded or exceeded the |
- // max number of retries. The +1 represents the request that just |
- // completed. Since we call MarkAttemptCompleted within the if branches, |
- // the completed_attempt_count has not yet been updated when we are checking |
- // the if condition. |
+ } else if (status == Offliner::RequestStatus::SAVED) { |
+ // Remove the request from the queue if it either succeeded. |
+ std::vector<ClientId> client_ids; |
+ client_ids.push_back(request.client_id()); |
+ queue_->RemoveRequestsByClientId( |
+ client_ids, |
+ base::Bind(&RequestCoordinator::UpdateRequestCallback, |
+ weak_ptr_factory_.GetWeakPtr(), request.client_id())); |
+ NotifySucceeded(request.client_id()); |
+ } else if (request.completed_attempt_count() + 1 >= |
+ policy_->GetMaxCompletedTries()) { |
+ // Remove from the request queue if we exceeeded max retries. The +1 |
+ // represents the request that just completed. Since we call |
+ // MarkAttemptCompleted within the if branches, the completed_attempt_count |
+ // has not yet been updated when we are checking the if condition. |
std::vector<ClientId> client_ids; |
client_ids.push_back(request.client_id()); |
queue_->RemoveRequestsByClientId( |
client_ids, |
base::Bind(&RequestCoordinator::UpdateRequestCallback, |
weak_ptr_factory_.GetWeakPtr(), request.client_id())); |
+ NotifyFailed(request.client_id()); |
} else { |
// If we failed, but are not over the limit, update the request in the |
// queue. |
@@ -340,6 +353,7 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
base::Bind(&RequestCoordinator::UpdateRequestCallback, |
weak_ptr_factory_.GetWeakPtr(), |
updated_request.client_id())); |
+ NotifyAvailable(request.client_id()); |
} |
// Determine whether we might try another request in this |
@@ -375,6 +389,39 @@ RequestCoordinator::GetTriggerConditionsForUserRequest() { |
return trigger_conditions; |
} |
+void RequestCoordinator::AddObserver(Observer* observer) { |
+ DCHECK(observer); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void RequestCoordinator::RemoveObserver(Observer* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+void RequestCoordinator::NotifyAvailable(ClientId client_id) { |
+ RequestInfo info; |
+ info.client_id = client_id; |
+ FOR_EACH_OBSERVER(Observer, observers_, OnAvailable(info)); |
+} |
+ |
+void RequestCoordinator::NotifySucceeded(ClientId client_id) { |
+ RequestInfo info; |
+ info.client_id = client_id;; |
+ FOR_EACH_OBSERVER(Observer, observers_, OnSucceeded(info)); |
+} |
+ |
+void RequestCoordinator::NotifyFailed(ClientId client_id) { |
+ RequestInfo info; |
+ info.client_id = client_id; |
+ FOR_EACH_OBSERVER(Observer, observers_, OnFailed(info)); |
+} |
+ |
+void RequestCoordinator::NotifyPaused(ClientId client_id) { |
+ RequestInfo info; |
+ info.client_id = client_id; |
+ FOR_EACH_OBSERVER(Observer, observers_, OnPaused(info)); |
+} |
+ |
void RequestCoordinator::GetOffliner() { |
if (!offliner_) { |
offliner_ = factory_->GetOffliner(policy_.get()); |