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

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

Issue 2301703002: [Offline Pages] Adds UMA for number of started attempts and for network connection when Unsupported… (Closed)
Patch Set: kMaxStartedTries from 5 to 4 Created 4 years, 4 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 d6fc9858312ded63053eb3844293a68d5ec9bab4..0f032e227776ae1c7d9607b00a62957b8597fad2 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -45,6 +45,21 @@ void RecordOfflinerResultUMA(const ClientId& client_id,
histogram->Add(static_cast<int>(request_status));
}
+// Records the number of started attempts for completed requests (whether
+// successful or not).
+void RecordAttemptCount(const SavePageRequest& request,
Pete Williamson 2016/09/01 00:27:20 Maybe this should be RecordStartedAttemptCount(),
dougarnett 2016/09/01 19:27:37 Actually, my thought was to just add the completed
+ RequestNotifier::SavePageStatus status) {
+ if (status == RequestNotifier::SavePageStatus::SUCCESS) {
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "OfflinePages.Background.RequestSuccess.StartedAttemptCount",
+ request.started_attempt_count(), 1, 10, 10);
+ } else {
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "OfflinePages.Background.RequestFailure.StartedAttemptCount",
+ request.started_attempt_count(), 1, 10, 10);
+ }
+}
+
// This should use the same algorithm as we use for OfflinePageItem, so the IDs
// are similar.
int64_t GenerateOfflineId() {
@@ -119,13 +134,9 @@ void RequestCoordinator::GetQueuedRequestsCallback(
void RequestCoordinator::StopPrerendering() {
if (offliner_ && is_busy_) {
+ DCHECK(active_request_.get());
offliner_->Cancel();
- // Find current request and mark attempt aborted.
- active_request_->MarkAttemptAborted();
- queue_->UpdateRequest(*(active_request_.get()),
- base::Bind(&RequestCoordinator::UpdateRequestCallback,
- weak_ptr_factory_.GetWeakPtr(),
- active_request_->client_id()));
+ AbortRequestAttempt(active_request_.get());
}
// Stopping offliner means it will not call callback.
@@ -157,6 +168,28 @@ bool RequestCoordinator::CancelActiveRequestIfItMatches(
return false;
}
+void RequestCoordinator::AbortRequestAttempt(SavePageRequest* request) {
Pete Williamson 2016/09/01 00:27:20 This splits the responsibility for garbage collect
dougarnett 2016/09/01 19:27:37 We are deleting the DoneCallback requests in other
+ request->MarkAttemptAborted();
+ if (request->started_attempt_count() >= policy_->GetMaxStartedTries()) {
+ RemoveAttemptedRequest(*request, SavePageStatus::START_COUNT_EXCEEDED);
+ } else {
+ queue_->UpdateRequest(
+ *request,
+ base::Bind(&RequestCoordinator::UpdateRequestCallback,
+ weak_ptr_factory_.GetWeakPtr(), request->client_id()));
+ }
+}
+
+void RequestCoordinator::RemoveAttemptedRequest(const SavePageRequest& request,
+ SavePageStatus status) {
+ std::vector<int64_t> remove_requests;
+ remove_requests.push_back(request.request_id());
+ queue_->RemoveRequests(remove_requests,
+ base::Bind(&RequestCoordinator::HandleRemovedRequests,
+ weak_ptr_factory_.GetWeakPtr(), status));
+ RecordAttemptCount(request, status);
+}
+
void RequestCoordinator::RemoveRequests(
const std::vector<int64_t>& request_ids,
const RemoveRequestsCallback& callback) {
@@ -412,37 +445,22 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
// TODO(dougarnett): See if we can conclusively identify other attempt
// aborted cases to treat this way (eg, for Render Process Killed).
SavePageRequest updated_request(request);
- updated_request.MarkAttemptAborted();
- queue_->UpdateRequest(updated_request,
- base::Bind(&RequestCoordinator::UpdateRequestCallback,
- weak_ptr_factory_.GetWeakPtr(),
- updated_request.client_id()));
+ AbortRequestAttempt(&updated_request);
SavePageStatus notify_status =
(status == Offliner::RequestStatus::FOREGROUND_CANCELED)
? SavePageStatus::FOREGROUND_CANCELED
: SavePageStatus::PRERENDER_CANCELED;
NotifyCompleted(updated_request, notify_status);
-
} else if (status == Offliner::RequestStatus::SAVED) {
// Remove the request from the queue if it succeeded.
- std::vector<int64_t> remove_requests;
- remove_requests.push_back(request.request_id());
- queue_->RemoveRequests(
- remove_requests,
- base::Bind(&RequestCoordinator::HandleRemovedRequests,
- weak_ptr_factory_.GetWeakPtr(), SavePageStatus::SUCCESS));
+ RemoveAttemptedRequest(request, SavePageStatus::SUCCESS);
} else if (request.completed_attempt_count() + 1 >=
policy_->GetMaxCompletedTries()) {
- // Remove from the request queue if we exceeeded max retries. The +1
+ // Remove from the request queue if we exceeded max retries. The +1
// represents the request that just completed. Since we call
// MarkAttemptCompleted within the if branches, the completed_attempt_count
// has not yet been updated when we are checking the if condition.
- std::vector<int64_t> remove_requests;
- remove_requests.push_back(request.request_id());
- queue_->RemoveRequests(
- remove_requests, base::Bind(&RequestCoordinator::HandleRemovedRequests,
- weak_ptr_factory_.GetWeakPtr(),
- SavePageStatus::RETRY_COUNT_EXCEEDED));
+ RemoveAttemptedRequest(request, SavePageStatus::RETRY_COUNT_EXCEEDED);
} else {
// If we failed, but are not over the limit, update the request in the
// queue.
« no previous file with comments | « components/offline_pages/background/request_coordinator.h ('k') | components/offline_pages/background/request_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698