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 <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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 GetOffliner(); | 530 GetOffliner(); |
| 531 if (!offliner_) { | 531 if (!offliner_) { |
| 532 DVLOG(0) << "Unable to create Offliner. " | 532 DVLOG(0) << "Unable to create Offliner. " |
| 533 << "Cannot background offline page."; | 533 << "Cannot background offline page."; |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 | 536 |
| 537 DCHECK(!is_busy_); | 537 DCHECK(!is_busy_); |
| 538 is_busy_ = true; | 538 is_busy_ = true; |
| 539 | 539 |
| 540 // Update the request for this attempt to start it. | 540 // Update the request for this attempt to start it. |
|
Pete Williamson
2016/10/14 17:02:35
Comment needs to be updated to say "and then send
fgorski
2016/10/19 03:26:33
Done.
| |
| 541 SavePageRequest updated_request(request); | 541 queue_->MarkAttemptStarted( |
| 542 updated_request.MarkAttemptStarted(base::Time::Now()); | 542 request.request_id(), |
| 543 queue_->UpdateRequest( | 543 base::Bind(&RequestCoordinator::StartOffliner, |
| 544 updated_request, | 544 weak_ptr_factory_.GetWeakPtr(), request.request_id(), |
| 545 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 545 request.client_id().name_space)); |
| 546 weak_ptr_factory_.GetWeakPtr(), updated_request.client_id())); | 546 } |
| 547 active_request_.reset(new SavePageRequest(updated_request)); | 547 |
| 548 void RequestCoordinator::StartOffliner( | |
| 549 int64_t request_id, | |
| 550 const std::string& client_namespace, | |
| 551 std::unique_ptr<UpdateRequestsResult> update_result) { | |
| 552 if (update_result->store_state != StoreState::LOADED || | |
|
Pete Williamson
2016/10/14 17:02:35
I think our original decision was to keep processi
fgorski
2016/10/19 03:26:34
What if request is not in database? What if the st
| |
| 553 update_result->item_statuses.size() != 1 || | |
| 554 update_result->item_statuses.at(0).first != request_id || | |
| 555 update_result->item_statuses.at(0).second != ItemActionStatus::SUCCESS) { | |
| 556 is_busy_ = false; | |
| 557 // TODO(fgorski): what is the best result? Do we create a new status? | |
| 558 StopProcessing(Offliner::PRERENDERING_NOT_STARTED); | |
| 559 DVLOG(1) << "Failed to mark attempt started: " << request_id; | |
| 560 event_logger_.RecordUpdateRequestFailed( | |
| 561 client_namespace, | |
| 562 update_result->store_state != StoreState::LOADED | |
| 563 ? RequestQueue::UpdateRequestResult::STORE_FAILURE | |
| 564 : RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST); | |
| 565 } | |
| 566 | |
| 567 // TODO(fgorski): Drop the in-memory caching. | |
|
Pete Williamson
2016/10/14 17:02:35
I don't understand this comment. Are you suggesti
fgorski
2016/10/14 20:37:19
this is explicitly about active_request_ which is
dougarnett
2016/10/14 20:59:04
Yes, we want to set active_request_ if we call Loa
fgorski
2016/10/17 14:22:13
Doug, you confirmed what the code does right now,
dougarnett
2016/10/17 16:36:58
It tracks state of pending operation and which req
dougarnett
2016/10/17 18:59:44
Please clarify the TODO wrt your idea of only cach
fgorski
2016/10/19 03:26:33
Done.
| |
| 568 active_request_.reset( | |
| 569 new SavePageRequest(update_result->updated_items.at(0))); | |
| 548 | 570 |
| 549 // Start the load and save process in the offliner (Async). | 571 // Start the load and save process in the offliner (Async). |
| 550 if (offliner_->LoadAndSave( | 572 if (offliner_->LoadAndSave( |
| 551 updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback, | 573 update_result->updated_items.at(0), |
| 552 weak_ptr_factory_.GetWeakPtr()))) { | 574 base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
| 575 weak_ptr_factory_.GetWeakPtr()))) { | |
| 553 // Start a watchdog timer to catch pre-renders running too long | 576 // Start a watchdog timer to catch pre-renders running too long |
| 554 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this, | 577 watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this, |
| 555 &RequestCoordinator::HandleWatchdogTimeout); | 578 &RequestCoordinator::HandleWatchdogTimeout); |
| 556 } else { | 579 } else { |
| 557 is_busy_ = false; | 580 is_busy_ = false; |
| 558 DVLOG(0) << "Unable to start LoadAndSave"; | 581 DVLOG(0) << "Unable to start LoadAndSave"; |
| 559 StopProcessing(Offliner::PRERENDERING_NOT_STARTED); | 582 StopProcessing(Offliner::PRERENDERING_NOT_STARTED); |
| 583 // TODO(fgorski): We should probably mark attempt failed here. How is that | |
|
dougarnett
2016/10/13 22:54:56
Unfortunately we do not know if it is a failure or
fgorski
2016/10/14 20:37:19
Yeah, thanks for the explanation. I spoke with Pet
fgorski
2016/10/19 03:26:34
Done.
| |
| 584 // done if the offliner does not accept the task? | |
| 560 } | 585 } |
| 561 } | 586 } |
| 562 | 587 |
| 563 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, | 588 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| 564 Offliner::RequestStatus status) { | 589 Offliner::RequestStatus status) { |
| 565 DVLOG(2) << "offliner finished, saved: " | 590 DVLOG(2) << "offliner finished, saved: " |
| 566 << (status == Offliner::RequestStatus::SAVED) | 591 << (status == Offliner::RequestStatus::SAVED) |
| 567 << ", status: " << static_cast<int>(status) << ", " << __func__; | 592 << ", status: " << static_cast<int>(status) << ", " << __func__; |
| 568 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN); | 593 DCHECK_NE(status, Offliner::RequestStatus::UNKNOWN); |
| 569 DCHECK_NE(status, Offliner::RequestStatus::LOADED); | 594 DCHECK_NE(status, Offliner::RequestStatus::LOADED); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 | 728 |
| 704 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 729 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 705 return policy_controller_.get(); | 730 return policy_controller_.get(); |
| 706 } | 731 } |
| 707 | 732 |
| 708 void RequestCoordinator::Shutdown() { | 733 void RequestCoordinator::Shutdown() { |
| 709 network_quality_estimator_ = nullptr; | 734 network_quality_estimator_ = nullptr; |
| 710 } | 735 } |
| 711 | 736 |
| 712 } // namespace offline_pages | 737 } // namespace offline_pages |
| OLD | NEW |