Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: components/offline_pages/background/request_coordinator.cc

Issue 2277123002: [Offline pages] Hooking up cancel/pause/resume buttons for offline page related notifications (Closed)
Patch Set: Rebasing Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return false; 151 return false;
152 } 152 }
153 153
154 void RequestCoordinator::RemoveRequests( 154 void RequestCoordinator::RemoveRequests(
155 const std::vector<int64_t>& request_ids, 155 const std::vector<int64_t>& request_ids,
156 const RemoveRequestsCallback& callback) { 156 const RemoveRequestsCallback& callback) {
157 bool canceled = CancelActiveRequestIfItMatches(request_ids); 157 bool canceled = CancelActiveRequestIfItMatches(request_ids);
158 queue_->RemoveRequests( 158 queue_->RemoveRequests(
159 request_ids, 159 request_ids,
160 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback, 160 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback,
161 weak_ptr_factory_.GetWeakPtr(), callback)); 161 weak_ptr_factory_.GetWeakPtr(), callback,
162 SavePageStatus::REMOVED));
162 if (canceled) 163 if (canceled)
163 TryNextRequest(); 164 TryNextRequest();
164 } 165 }
165 166
166 void RequestCoordinator::PauseRequests( 167 void RequestCoordinator::PauseRequests(
167 const std::vector<int64_t>& request_ids) { 168 const std::vector<int64_t>& request_ids) {
168 bool canceled = CancelActiveRequestIfItMatches(request_ids); 169 bool canceled = CancelActiveRequestIfItMatches(request_ids);
169 queue_->ChangeRequestsState( 170 queue_->ChangeRequestsState(
170 request_ids, SavePageRequest::RequestState::PAUSED, 171 request_ids, SavePageRequest::RequestState::PAUSED,
171 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, 172 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Called in response to updating multiple requests in the request queue. 209 // Called in response to updating multiple requests in the request queue.
209 void RequestCoordinator::UpdateMultipleRequestsCallback( 210 void RequestCoordinator::UpdateMultipleRequestsCallback(
210 const RequestQueue::UpdateMultipleRequestResults& results, 211 const RequestQueue::UpdateMultipleRequestResults& results,
211 const std::vector<SavePageRequest>& requests) { 212 const std::vector<SavePageRequest>& requests) {
212 for (SavePageRequest request : requests) 213 for (SavePageRequest request : requests)
213 NotifyChanged(request); 214 NotifyChanged(request);
214 } 215 }
215 216
216 void RequestCoordinator::HandleRemovedRequestsAndCallback( 217 void RequestCoordinator::HandleRemovedRequestsAndCallback(
217 const RemoveRequestsCallback& callback, 218 const RemoveRequestsCallback& callback,
219 SavePageStatus status,
218 const RequestQueue::UpdateMultipleRequestResults& results, 220 const RequestQueue::UpdateMultipleRequestResults& results,
219 const std::vector<SavePageRequest>& requests) { 221 const std::vector<SavePageRequest>& requests) {
220 callback.Run(results); 222 callback.Run(results);
221 HandleRemovedRequests(results, requests); 223 HandleRemovedRequests(status, results, requests);
222 } 224 }
223 225
224 void RequestCoordinator::HandleRemovedRequests( 226 void RequestCoordinator::HandleRemovedRequests(
227 SavePageStatus status,
225 const RequestQueue::UpdateMultipleRequestResults& results, 228 const RequestQueue::UpdateMultipleRequestResults& results,
226 const std::vector<SavePageRequest>& requests) { 229 const std::vector<SavePageRequest>& requests) {
227 for (SavePageRequest request : requests) 230 for (SavePageRequest request : requests)
228 NotifyCompleted(request, SavePageStatus::REMOVED); 231 NotifyCompleted(request, status);
229 } 232 }
230 233
231 void RequestCoordinator::StopProcessing() { 234 void RequestCoordinator::StopProcessing() {
232 is_stopped_ = true; 235 is_stopped_ = true;
233 StopPrerendering(); 236 StopPrerendering();
234 237
235 // Let the scheduler know we are done processing. 238 // Let the scheduler know we are done processing.
236 scheduler_callback_.Run(true); 239 scheduler_callback_.Run(true);
237 } 240 }
238 241
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 base::Bind(&RequestCoordinator::UpdateRequestCallback, 363 base::Bind(&RequestCoordinator::UpdateRequestCallback,
361 weak_ptr_factory_.GetWeakPtr(), 364 weak_ptr_factory_.GetWeakPtr(),
362 updated_request.client_id())); 365 updated_request.client_id()));
363 NotifyCompleted(updated_request, SavePageStatus::FOREGROUND_CANCELED); 366 NotifyCompleted(updated_request, SavePageStatus::FOREGROUND_CANCELED);
364 367
365 } else if (status == Offliner::RequestStatus::SAVED) { 368 } else if (status == Offliner::RequestStatus::SAVED) {
366 // Remove the request from the queue if it succeeded. 369 // Remove the request from the queue if it succeeded.
367 std::vector<int64_t> remove_requests; 370 std::vector<int64_t> remove_requests;
368 remove_requests.push_back(request.request_id()); 371 remove_requests.push_back(request.request_id());
369 queue_->RemoveRequests( 372 queue_->RemoveRequests(
370 remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests, 373 remove_requests,
371 weak_ptr_factory_.GetWeakPtr())); 374 base::Bind(&RequestCoordinator::HandleRemovedRequests,
372 NotifyCompleted(request, SavePageStatus::SUCCESS); 375 weak_ptr_factory_.GetWeakPtr(), SavePageStatus::SUCCESS));
373 } else if (request.completed_attempt_count() + 1 >= 376 } else if (request.completed_attempt_count() + 1 >=
374 policy_->GetMaxCompletedTries()) { 377 policy_->GetMaxCompletedTries()) {
375 // Remove from the request queue if we exceeeded max retries. The +1 378 // Remove from the request queue if we exceeeded max retries. The +1
376 // represents the request that just completed. Since we call 379 // represents the request that just completed. Since we call
377 // MarkAttemptCompleted within the if branches, the completed_attempt_count 380 // MarkAttemptCompleted within the if branches, the completed_attempt_count
378 // has not yet been updated when we are checking the if condition. 381 // has not yet been updated when we are checking the if condition.
379 std::vector<int64_t> remove_requests; 382 std::vector<int64_t> remove_requests;
380 remove_requests.push_back(request.request_id()); 383 remove_requests.push_back(request.request_id());
381 queue_->RemoveRequests( 384 queue_->RemoveRequests(
382 remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests, 385 remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests,
383 weak_ptr_factory_.GetWeakPtr())); 386 weak_ptr_factory_.GetWeakPtr(),
384 NotifyCompleted(request, SavePageStatus::RETRY_COUNT_EXCEEDED); 387 SavePageStatus::RETRY_COUNT_EXCEEDED));
385 } else { 388 } else {
386 // If we failed, but are not over the limit, update the request in the 389 // If we failed, but are not over the limit, update the request in the
387 // queue. 390 // queue.
388 SavePageRequest updated_request(request); 391 SavePageRequest updated_request(request);
389 updated_request.MarkAttemptCompleted(); 392 updated_request.MarkAttemptCompleted();
390 queue_->UpdateRequest(updated_request, 393 queue_->UpdateRequest(updated_request,
391 base::Bind(&RequestCoordinator::UpdateRequestCallback, 394 base::Bind(&RequestCoordinator::UpdateRequestCallback,
392 weak_ptr_factory_.GetWeakPtr(), 395 weak_ptr_factory_.GetWeakPtr(),
393 updated_request.client_id())); 396 updated_request.client_id()));
394 NotifyChanged(updated_request); 397 NotifyChanged(updated_request);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); 452 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request));
450 } 453 }
451 454
452 void RequestCoordinator::GetOffliner() { 455 void RequestCoordinator::GetOffliner() {
453 if (!offliner_) { 456 if (!offliner_) {
454 offliner_ = factory_->GetOffliner(policy_.get()); 457 offliner_ = factory_->GetOffliner(policy_.get());
455 } 458 }
456 } 459 }
457 460
458 } // namespace offline_pages 461 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698