Chromium Code Reviews| 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 <limits> | 7 #include <limits> |
| 8 #include <string> | |
| 9 #include <utility> | 8 #include <utility> |
| 10 #include <vector> | |
| 11 | 9 |
| 12 #include "base/bind.h" | 10 #include "base/bind.h" |
| 13 #include "base/callback.h" | 11 #include "base/callback.h" |
| 14 #include "base/logging.h" | 12 #include "base/logging.h" |
| 15 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 17 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 18 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 19 #include "components/offline_pages/background/offliner_factory.h" | 17 #include "components/offline_pages/background/offliner_factory.h" |
| 20 #include "components/offline_pages/background/offliner_policy.h" | 18 #include "components/offline_pages/background/offliner_policy.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 RequestQueue::AddRequestResult result, | 359 RequestQueue::AddRequestResult result, |
| 362 const SavePageRequest& request) { | 360 const SavePageRequest& request) { |
| 363 NotifyAdded(request); | 361 NotifyAdded(request); |
| 364 // Inform the scheduler that we have an outstanding task. | 362 // Inform the scheduler that we have an outstanding task. |
| 365 scheduler_->Schedule(GetTriggerConditions(kUserRequest)); | 363 scheduler_->Schedule(GetTriggerConditions(kUserRequest)); |
| 366 | 364 |
| 367 if (request.user_requested()) | 365 if (request.user_requested()) |
| 368 StartImmediatelyIfConnected(); | 366 StartImmediatelyIfConnected(); |
| 369 } | 367 } |
| 370 | 368 |
| 371 // Called in response to updating a request in the request queue. | 369 void RequestCoordinator::MarkAttemptCompletedDoneCallback( |
| 372 void RequestCoordinator::UpdateRequestCallback( | 370 int64_t request_id, |
| 373 const ClientId& client_id, | 371 const ClientId& client_id, |
| 374 RequestQueue::UpdateRequestResult result) { | 372 std::unique_ptr<UpdateRequestsResult> result) { |
| 375 // If the request succeeded, nothing to do. If it failed, we can't really do | 373 if (result->store_state != StoreState::LOADED || |
|
fgorski
2016/10/31 20:33:50
see if in line 301 please and consider if you coul
dougarnett
2016/10/31 22:05:52
Done.
| |
| 376 // much, so just log it. | 374 result->item_statuses.size() != 1 || |
| 377 if (result != RequestQueue::UpdateRequestResult::SUCCESS) { | 375 result->item_statuses.at(0).second != ItemActionStatus::SUCCESS) { |
| 378 DVLOG(1) << "Failed to update request attempt details. " | 376 DVLOG(1) << "Failed to mark request completed " << request_id; |
| 379 << static_cast<int>(result); | 377 event_logger_.RecordUpdateRequestFailed( |
| 380 event_logger_.RecordUpdateRequestFailed(client_id.name_space, result); | 378 client_id.name_space, |
| 379 result->store_state != StoreState::LOADED | |
|
Pete Williamson
2016/10/31 21:38:26
I think having the : ? inside the parameter list m
dougarnett
2016/10/31 22:51:18
Actually mirroring pattern already in this file, n
Pete Williamson
2016/10/31 23:10:08
Let's still fix it, the pattern is not a great one
dougarnett
2016/11/01 00:16:37
ok, done
| |
| 380 ? RequestQueue::UpdateRequestResult::STORE_FAILURE | |
| 381 : RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST); | |
| 382 } else { | |
| 383 NotifyChanged(result->updated_items.at(0)); | |
|
Pete Williamson
2016/10/31 21:38:26
The old code notified changed even if the database
dougarnett
2016/10/31 22:51:17
Great question. I'm not sure. Would we want to Not
| |
| 381 } | 384 } |
| 382 } | 385 } |
| 383 | 386 |
| 384 void RequestCoordinator::UpdateMultipleRequestsCallback( | 387 void RequestCoordinator::UpdateMultipleRequestsCallback( |
| 385 std::unique_ptr<UpdateRequestsResult> result) { | 388 std::unique_ptr<UpdateRequestsResult> result) { |
| 386 for (const auto& request : result->updated_items) | 389 for (const auto& request : result->updated_items) |
| 387 NotifyChanged(request); | 390 NotifyChanged(request); |
| 388 | 391 |
| 389 bool available_user_request = false; | 392 bool available_user_request = false; |
| 390 for (const auto& request : result->updated_items) { | 393 for (const auto& request : result->updated_items) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 // MarkAttemptCompleted within the if branches, the completed_attempt_count | 707 // MarkAttemptCompleted within the if branches, the completed_attempt_count |
| 705 // has not yet been updated when we are checking the if condition. | 708 // has not yet been updated when we are checking the if condition. |
| 706 const BackgroundSavePageResult result( | 709 const BackgroundSavePageResult result( |
| 707 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); | 710 BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); |
| 708 event_logger_.RecordDroppedSavePageRequest(request.client_id().name_space, | 711 event_logger_.RecordDroppedSavePageRequest(request.client_id().name_space, |
| 709 result, request.request_id()); | 712 result, request.request_id()); |
| 710 RemoveAttemptedRequest(request, result); | 713 RemoveAttemptedRequest(request, result); |
| 711 } else { | 714 } else { |
| 712 // If we failed, but are not over the limit, update the request in the | 715 // If we failed, but are not over the limit, update the request in the |
| 713 // queue. | 716 // queue. |
| 714 SavePageRequest updated_request(request); | 717 queue_->MarkAttemptCompleted( |
| 715 updated_request.MarkAttemptCompleted(); | 718 request.request_id(), |
| 716 queue_->UpdateRequest(updated_request, | 719 base::Bind(&RequestCoordinator::MarkAttemptCompletedDoneCallback, |
|
Pete Williamson
2016/10/31 21:38:26
Hmm, if this is really the only place left we used
dougarnett
2016/10/31 22:51:17
Yes. Also have now deleted RequestQueue::UpdateReq
| |
| 717 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 720 weak_ptr_factory_.GetWeakPtr(), request.request_id(), |
| 718 weak_ptr_factory_.GetWeakPtr(), | 721 request.client_id())); |
| 719 updated_request.client_id())); | |
| 720 NotifyChanged(updated_request); | |
| 721 } | 722 } |
| 722 | 723 |
| 723 // Determine whether we might try another request in this | 724 // Determine whether we might try another request in this |
| 724 // processing window based on how the previous request completed. | 725 // processing window based on how the previous request completed. |
| 725 switch (status) { | 726 switch (status) { |
| 726 case Offliner::RequestStatus::SAVED: | 727 case Offliner::RequestStatus::SAVED: |
| 727 case Offliner::RequestStatus::SAVE_FAILED: | 728 case Offliner::RequestStatus::SAVE_FAILED: |
| 728 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: | 729 case Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED: |
| 729 case Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT: | 730 case Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT: |
| 730 case Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY: | 731 case Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 | 815 |
| 815 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 816 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 816 return policy_controller_.get(); | 817 return policy_controller_.get(); |
| 817 } | 818 } |
| 818 | 819 |
| 819 void RequestCoordinator::Shutdown() { | 820 void RequestCoordinator::Shutdown() { |
| 820 network_quality_estimator_ = nullptr; | 821 network_quality_estimator_ = nullptr; |
| 821 } | 822 } |
| 822 | 823 |
| 823 } // namespace offline_pages | 824 } // namespace offline_pages |
| OLD | NEW |