| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 DCHECK_NE(status, Offliner::RequestStatus::LOADED); | 399 DCHECK_NE(status, Offliner::RequestStatus::LOADED); |
| 400 event_logger_.RecordSavePageRequestUpdated(request.client_id().name_space, | 400 event_logger_.RecordSavePageRequestUpdated(request.client_id().name_space, |
| 401 status, request.request_id()); | 401 status, request.request_id()); |
| 402 last_offlining_status_ = status; | 402 last_offlining_status_ = status; |
| 403 RecordOfflinerResultUMA(request.client_id(), last_offlining_status_); | 403 RecordOfflinerResultUMA(request.client_id(), last_offlining_status_); |
| 404 watchdog_timer_.Stop(); | 404 watchdog_timer_.Stop(); |
| 405 | 405 |
| 406 is_busy_ = false; | 406 is_busy_ = false; |
| 407 active_request_.reset(nullptr); | 407 active_request_.reset(nullptr); |
| 408 | 408 |
| 409 if (status == Offliner::RequestStatus::FOREGROUND_CANCELED) { | 409 if (status == Offliner::RequestStatus::FOREGROUND_CANCELED || |
| 410 status == Offliner::RequestStatus::PRERENDERING_CANCELED) { |
| 410 // Update the request for the canceled attempt. | 411 // Update the request for the canceled attempt. |
| 411 // TODO(dougarnett): See if we can conclusively identify other attempt | 412 // TODO(dougarnett): See if we can conclusively identify other attempt |
| 412 // aborted cases to treat this way (eg, for Render Process Killed). | 413 // aborted cases to treat this way (eg, for Render Process Killed). |
| 413 SavePageRequest updated_request(request); | 414 SavePageRequest updated_request(request); |
| 414 updated_request.MarkAttemptAborted(); | 415 updated_request.MarkAttemptAborted(); |
| 415 queue_->UpdateRequest(updated_request, | 416 queue_->UpdateRequest(updated_request, |
| 416 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 417 base::Bind(&RequestCoordinator::UpdateRequestCallback, |
| 417 weak_ptr_factory_.GetWeakPtr(), | 418 weak_ptr_factory_.GetWeakPtr(), |
| 418 updated_request.client_id())); | 419 updated_request.client_id())); |
| 419 NotifyCompleted(updated_request, SavePageStatus::FOREGROUND_CANCELED); | 420 SavePageStatus notify_status = |
| 421 (status == Offliner::RequestStatus::FOREGROUND_CANCELED) |
| 422 ? SavePageStatus::FOREGROUND_CANCELED |
| 423 : SavePageStatus::PRERENDER_CANCELED; |
| 424 NotifyCompleted(updated_request, notify_status); |
| 420 | 425 |
| 421 } else if (status == Offliner::RequestStatus::SAVED) { | 426 } else if (status == Offliner::RequestStatus::SAVED) { |
| 422 // Remove the request from the queue if it succeeded. | 427 // Remove the request from the queue if it succeeded. |
| 423 std::vector<int64_t> remove_requests; | 428 std::vector<int64_t> remove_requests; |
| 424 remove_requests.push_back(request.request_id()); | 429 remove_requests.push_back(request.request_id()); |
| 425 queue_->RemoveRequests( | 430 queue_->RemoveRequests( |
| 426 remove_requests, | 431 remove_requests, |
| 427 base::Bind(&RequestCoordinator::HandleRemovedRequests, | 432 base::Bind(&RequestCoordinator::HandleRemovedRequests, |
| 428 weak_ptr_factory_.GetWeakPtr(), SavePageStatus::SUCCESS)); | 433 weak_ptr_factory_.GetWeakPtr(), SavePageStatus::SUCCESS)); |
| 429 } else if (request.completed_attempt_count() + 1 >= | 434 } else if (request.completed_attempt_count() + 1 >= |
| (...skipping 22 matching lines...) Expand all Loading... |
| 452 | 457 |
| 453 // Determine whether we might try another request in this | 458 // Determine whether we might try another request in this |
| 454 // processing window based on how the previous request completed. | 459 // processing window based on how the previous request completed. |
| 455 // | 460 // |
| 456 // TODO(dougarnett): Need to split PRERENDERING_FAILED into separate | 461 // TODO(dougarnett): Need to split PRERENDERING_FAILED into separate |
| 457 // codes as to whether we should try another request or not. | 462 // codes as to whether we should try another request or not. |
| 458 switch (status) { | 463 switch (status) { |
| 459 case Offliner::RequestStatus::SAVED: | 464 case Offliner::RequestStatus::SAVED: |
| 460 case Offliner::RequestStatus::SAVE_FAILED: | 465 case Offliner::RequestStatus::SAVE_FAILED: |
| 461 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: // timeout | 466 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: // timeout |
| 462 case Offliner::RequestStatus::PRERENDERING_CANCELED: | |
| 463 // Consider processing another request in this service window. | 467 // Consider processing another request in this service window. |
| 464 TryNextRequest(); | 468 TryNextRequest(); |
| 465 break; | 469 break; |
| 466 case Offliner::RequestStatus::FOREGROUND_CANCELED: | 470 case Offliner::RequestStatus::FOREGROUND_CANCELED: |
| 471 case Offliner::RequestStatus::PRERENDERING_CANCELED: |
| 467 case Offliner::RequestStatus::PRERENDERING_FAILED: | 472 case Offliner::RequestStatus::PRERENDERING_FAILED: |
| 468 // No further processing in this service window. | 473 // No further processing in this service window. |
| 469 break; | 474 break; |
| 470 default: | 475 default: |
| 471 // Make explicit choice about new status codes that actually reach here. | 476 // Make explicit choice about new status codes that actually reach here. |
| 472 // Their default is no further processing in this service window. | 477 // Their default is no further processing in this service window. |
| 473 DCHECK(false); | 478 DCHECK(false); |
| 474 } | 479 } |
| 475 } | 480 } |
| 476 | 481 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 505 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); | 510 FOR_EACH_OBSERVER(Observer, observers_, OnChanged(request)); |
| 506 } | 511 } |
| 507 | 512 |
| 508 void RequestCoordinator::GetOffliner() { | 513 void RequestCoordinator::GetOffliner() { |
| 509 if (!offliner_) { | 514 if (!offliner_) { |
| 510 offliner_ = factory_->GetOffliner(policy_.get()); | 515 offliner_ = factory_->GetOffliner(policy_.get()); |
| 511 } | 516 } |
| 512 } | 517 } |
| 513 | 518 |
| 514 } // namespace offline_pages | 519 } // namespace offline_pages |
| OLD | NEW |