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

Unified Diff: google_apis/gcm/engine/checkin_request.cc

Issue 261573002: Add checkin activity recording to gcm recorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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: google_apis/gcm/engine/checkin_request.cc
diff --git a/google_apis/gcm/engine/checkin_request.cc b/google_apis/gcm/engine/checkin_request.cc
index 7addbebcad04b8ebe81bf7e6ec0e5ed2274335cb..2999c6f066a82d8ce261f15f8c8b389bfc964a9f 100644
--- a/google_apis/gcm/engine/checkin_request.cc
+++ b/google_apis/gcm/engine/checkin_request.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
+#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
#include "google_apis/gcm/protocol/checkin.pb.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
@@ -24,7 +25,7 @@ const int kDefaultUserSerialNumber = 0;
// This enum is also used in an UMA histogram (GCMCheckinRequestStatus
// enum defined in tools/metrics/histograms/histogram.xml). Hence the entries
// here shouldn't be deleted or re-ordered and new ones should be added to
-// the end.
+// the end, and update the GetCheckinRequestStatusString(...) below.
enum CheckinRequestStatus {
SUCCESS, // Checkin completed successfully.
URL_FETCHING_FAILED, // URL fetching failed.
@@ -40,6 +41,29 @@ enum CheckinRequestStatus {
STATUS_COUNT
};
+// Returns string representation of enum CheckinRequestStatus.
+std::string GetCheckinRequestStatusString(CheckinRequestStatus status) {
+ switch (status) {
+ case SUCCESS:
+ return "SUCCESS";
+ case URL_FETCHING_FAILED:
+ return "URL_FETCHING_FAILED";
+ case HTTP_BAD_REQUEST:
+ return "HTTP_BAD_REQUEST";
+ case HTTP_UNAUTHORIZED:
+ return "HTTP_UNAUTHORIZED";
+ case HTTP_NOT_OK:
+ return "HTTP_NOT_OK";
+ case RESPONSE_PARSING_FAILED:
+ return "RESPONSE_PARSING_FAILED";
+ case ZERO_ID_OR_TOKEN:
+ return "ZERO_ID_OR_TOKEN";
+ default:
+ NOTREACHED();
+ return "UNKNOWN_STATUS";
+ }
+}
+
void RecordCheckinStatusToUMA(CheckinRequestStatus status) {
UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus", status, STATUS_COUNT);
}
@@ -65,11 +89,13 @@ CheckinRequest::CheckinRequest(
const RequestInfo& request_info,
const net::BackoffEntry::Policy& backoff_policy,
const CheckinRequestCallback& callback,
- net::URLRequestContextGetter* request_context_getter)
+ net::URLRequestContextGetter* request_context_getter,
+ GCMStatsRecorder* recorder)
: request_context_getter_(request_context_getter),
callback_(callback),
backoff_entry_(&backoff_policy),
request_info_(request_info),
+ recorder_(recorder),
weak_ptr_factory_(this) {
}
@@ -108,6 +134,7 @@ void CheckinRequest::Start() {
net::URLFetcher::Create(GURL(kCheckinURL), net::URLFetcher::POST, this));
url_fetcher_->SetRequestContext(request_context_getter_);
url_fetcher_->SetUploadData(kRequestContentType, upload_data);
+ recorder_->RecordCheckinInitiated(request_info_.android_id);
url_fetcher_->Start();
}
@@ -121,6 +148,8 @@ void CheckinRequest::RetryWithBackoff(bool update_backoff) {
DVLOG(1) << "Delay GCM checkin for: "
<< backoff_entry_.GetTimeUntilRelease().InMilliseconds()
<< " milliseconds.";
+ recorder_->RecordCheckinDelayedDueToBackoff(
+ backoff_entry_.GetTimeUntilRelease().InMilliseconds());
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&CheckinRequest::RetryWithBackoff,
@@ -139,6 +168,8 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
if (!source->GetStatus().is_success()) {
LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying.";
RecordCheckinStatusToUMA(URL_FETCHING_FAILED);
+ recorder_->RecordCheckinFailure(
jianli 2014/05/01 00:22:35 Can this be merged with RecordCheckinStatusToUMA?
juyik 2014/05/01 01:03:35 Done.
+ GetCheckinRequestStatusString(URL_FETCHING_FAILED), true);
RetryWithBackoff(true);
return;
}
@@ -151,8 +182,11 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
// UNAUTHORIZED indicates that security token didn't match the android id.
LOG(ERROR) << "No point retrying the checkin with status: "
<< response_status << ". Checkin failed.";
- RecordCheckinStatusToUMA(response_status == net::HTTP_BAD_REQUEST ?
- HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED);
+ CheckinRequestStatus status = response_status == net::HTTP_BAD_REQUEST ?
+ HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED;
+ RecordCheckinStatusToUMA(status);
+ recorder_->RecordCheckinFailure(
+ GetCheckinRequestStatusString(status), false);
callback_.Run(response_proto);
return;
}
@@ -162,8 +196,11 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
!response_proto.ParseFromString(response_string)) {
LOG(ERROR) << "Failed to get checkin response. HTTP Status: "
<< response_status << ". Retrying.";
- RecordCheckinStatusToUMA(response_status != net::HTTP_OK ?
- HTTP_NOT_OK : RESPONSE_PARSING_FAILED);
+ CheckinRequestStatus status = response_status != net::HTTP_OK ?
+ HTTP_NOT_OK : RESPONSE_PARSING_FAILED;
+ RecordCheckinStatusToUMA(status);
+ recorder_->RecordCheckinFailure(
+ GetCheckinRequestStatusString(status), true);
RetryWithBackoff(true);
return;
}
@@ -174,11 +211,14 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
response_proto.security_token() == 0) {
LOG(ERROR) << "Android ID or security token is 0. Retrying.";
RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN);
+ recorder_->RecordCheckinFailure(
+ GetCheckinRequestStatusString(ZERO_ID_OR_TOKEN), true);
RetryWithBackoff(true);
return;
}
RecordCheckinStatusToUMA(SUCCESS);
+ recorder_->RecordCheckinSuccess();
callback_.Run(response_proto);
}

Powered by Google App Engine
This is Rietveld 408576698