| 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 status == Offliner::RequestStatus::PRERENDERING_CANCELED) { | 515 status == Offliner::RequestStatus::PRERENDERING_CANCELED) { |
| 516 // Update the request for the canceled attempt. | 516 // Update the request for the canceled attempt. |
| 517 // TODO(dougarnett): See if we can conclusively identify other attempt | 517 // TODO(dougarnett): See if we can conclusively identify other attempt |
| 518 // aborted cases to treat this way (eg, for Render Process Killed). | 518 // aborted cases to treat this way (eg, for Render Process Killed). |
| 519 SavePageRequest updated_request(request); | 519 SavePageRequest updated_request(request); |
| 520 AbortRequestAttempt(&updated_request); | 520 AbortRequestAttempt(&updated_request); |
| 521 NotifyChanged(updated_request); | 521 NotifyChanged(updated_request); |
| 522 } else if (status == Offliner::RequestStatus::SAVED) { | 522 } else if (status == Offliner::RequestStatus::SAVED) { |
| 523 // Remove the request from the queue if it succeeded. | 523 // Remove the request from the queue if it succeeded. |
| 524 RemoveAttemptedRequest(request, BackgroundSavePageResult::SUCCESS); | 524 RemoveAttemptedRequest(request, BackgroundSavePageResult::SUCCESS); |
| 525 } else if (status == Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY) { |
| 526 RemoveAttemptedRequest(request, |
| 527 BackgroundSavePageResult::PRERENDER_FAILURE); |
| 525 } else if (request.completed_attempt_count() + 1 >= | 528 } else if (request.completed_attempt_count() + 1 >= |
| 526 policy_->GetMaxCompletedTries()) { | 529 policy_->GetMaxCompletedTries()) { |
| 527 // Remove from the request queue if we exceeded max retries. The +1 | 530 // Remove from the request queue if we exceeded max retries. The +1 |
| 528 // represents the request that just completed. Since we call | 531 // represents the request that just completed. Since we call |
| 529 // MarkAttemptCompleted within the if branches, the completed_attempt_count | 532 // MarkAttemptCompleted within the if branches, the completed_attempt_count |
| 530 // has not yet been updated when we are checking the if condition. | 533 // has not yet been updated when we are checking the if condition. |
| 531 const BackgroundSavePageResult result( | 534 const BackgroundSavePageResult result( |
| 532 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); | 535 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); |
| 533 event_logger_.RecordDroppedSavePageRequest(request.client_id().name_space, | 536 event_logger_.RecordDroppedSavePageRequest(request.client_id().name_space, |
| 534 result, request.request_id()); | 537 result, request.request_id()); |
| 535 RemoveAttemptedRequest(request, result); | 538 RemoveAttemptedRequest(request, result); |
| 536 } else { | 539 } else { |
| 537 // If we failed, but are not over the limit, update the request in the | 540 // If we failed, but are not over the limit, update the request in the |
| 538 // queue. | 541 // queue. |
| 539 SavePageRequest updated_request(request); | 542 SavePageRequest updated_request(request); |
| 540 updated_request.MarkAttemptCompleted(); | 543 updated_request.MarkAttemptCompleted(); |
| 541 queue_->UpdateRequest(updated_request, | 544 queue_->UpdateRequest(updated_request, |
| 542 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 545 base::Bind(&RequestCoordinator::UpdateRequestCallback, |
| 543 weak_ptr_factory_.GetWeakPtr(), | 546 weak_ptr_factory_.GetWeakPtr(), |
| 544 updated_request.client_id())); | 547 updated_request.client_id())); |
| 545 NotifyChanged(updated_request); | 548 NotifyChanged(updated_request); |
| 546 } | 549 } |
| 547 | 550 |
| 548 // Determine whether we might try another request in this | 551 // Determine whether we might try another request in this |
| 549 // processing window based on how the previous request completed. | 552 // processing window based on how the previous request completed. |
| 550 // | |
| 551 // TODO(dougarnett): Need to split PRERENDERING_FAILED into separate | |
| 552 // codes as to whether we should try another request or not. | |
| 553 switch (status) { | 553 switch (status) { |
| 554 case Offliner::RequestStatus::SAVED: | 554 case Offliner::RequestStatus::SAVED: |
| 555 case Offliner::RequestStatus::SAVE_FAILED: | 555 case Offliner::RequestStatus::SAVE_FAILED: |
| 556 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: // timeout | 556 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: |
| 557 case Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT: |
| 558 case Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY: |
| 557 // Consider processing another request in this service window. | 559 // Consider processing another request in this service window. |
| 558 TryNextRequest(); | 560 TryNextRequest(); |
| 559 break; | 561 break; |
| 560 case Offliner::RequestStatus::FOREGROUND_CANCELED: | 562 case Offliner::RequestStatus::FOREGROUND_CANCELED: |
| 561 case Offliner::RequestStatus::PRERENDERING_CANCELED: | 563 case Offliner::RequestStatus::PRERENDERING_CANCELED: |
| 562 case Offliner::RequestStatus::PRERENDERING_FAILED: | 564 case Offliner::RequestStatus::PRERENDERING_FAILED: |
| 563 // No further processing in this service window. | 565 // No further processing in this service window. |
| 564 break; | 566 break; |
| 565 default: | 567 default: |
| 566 // Make explicit choice about new status codes that actually reach here. | 568 // Make explicit choice about new status codes that actually reach here. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (!offliner_) { | 605 if (!offliner_) { |
| 604 offliner_ = factory_->GetOffliner(policy_.get()); | 606 offliner_ = factory_->GetOffliner(policy_.get()); |
| 605 } | 607 } |
| 606 } | 608 } |
| 607 | 609 |
| 608 void RequestCoordinator::Shutdown() { | 610 void RequestCoordinator::Shutdown() { |
| 609 network_quality_estimator_ = nullptr; | 611 network_quality_estimator_ = nullptr; |
| 610 } | 612 } |
| 611 | 613 |
| 612 } // namespace offline_pages | 614 } // namespace offline_pages |
| OLD | NEW |