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

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

Powered by Google App Engine
This is Rietveld 408576698