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

Unified Diff: components/offline_pages/background/request_coordinator.cc

Issue 2416083002: [Offline pages] Introduction of MarkAttemptStartedTask with tests (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_coordinator.cc
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc
index 087be6fa282ab13431bbe9e88b9f980e9117a73a..ba9ec510a9333f87d30dee39fc78a46694a7837f 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -538,18 +538,41 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {
is_busy_ = true;
// 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.
- SavePageRequest updated_request(request);
- updated_request.MarkAttemptStarted(base::Time::Now());
- queue_->UpdateRequest(
- updated_request,
- base::Bind(&RequestCoordinator::UpdateRequestCallback,
- weak_ptr_factory_.GetWeakPtr(), updated_request.client_id()));
- active_request_.reset(new SavePageRequest(updated_request));
+ queue_->MarkAttemptStarted(
+ request.request_id(),
+ base::Bind(&RequestCoordinator::StartOffliner,
+ weak_ptr_factory_.GetWeakPtr(), request.request_id(),
+ request.client_id().name_space));
+}
+
+void RequestCoordinator::StartOffliner(
+ int64_t request_id,
+ const std::string& client_namespace,
+ std::unique_ptr<UpdateRequestsResult> update_result) {
+ 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
+ update_result->item_statuses.size() != 1 ||
+ update_result->item_statuses.at(0).first != request_id ||
+ update_result->item_statuses.at(0).second != ItemActionStatus::SUCCESS) {
+ is_busy_ = false;
+ // TODO(fgorski): what is the best result? Do we create a new status?
+ StopProcessing(Offliner::PRERENDERING_NOT_STARTED);
+ DVLOG(1) << "Failed to mark attempt started: " << request_id;
+ event_logger_.RecordUpdateRequestFailed(
+ client_namespace,
+ update_result->store_state != StoreState::LOADED
+ ? RequestQueue::UpdateRequestResult::STORE_FAILURE
+ : RequestQueue::UpdateRequestResult::REQUEST_DOES_NOT_EXIST);
+ }
+
+ // 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.
+ active_request_.reset(
+ new SavePageRequest(update_result->updated_items.at(0)));
// Start the load and save process in the offliner (Async).
if (offliner_->LoadAndSave(
- updated_request, base::Bind(&RequestCoordinator::OfflinerDoneCallback,
- weak_ptr_factory_.GetWeakPtr()))) {
+ update_result->updated_items.at(0),
+ base::Bind(&RequestCoordinator::OfflinerDoneCallback,
+ weak_ptr_factory_.GetWeakPtr()))) {
// Start a watchdog timer to catch pre-renders running too long
watchdog_timer_.Start(FROM_HERE, offliner_timeout_, this,
&RequestCoordinator::HandleWatchdogTimeout);
@@ -557,6 +580,8 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {
is_busy_ = false;
DVLOG(0) << "Unable to start LoadAndSave";
StopProcessing(Offliner::PRERENDERING_NOT_STARTED);
+ // 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.
+ // done if the offliner does not accept the task?
}
}

Powered by Google App Engine
This is Rietveld 408576698