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

Unified Diff: content/browser/geolocation/network_location_request.cc

Issue 25262003: Geolocation: add UMA histograms for events and response codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/geolocation/network_location_request.cc
diff --git a/content/browser/geolocation/network_location_request.cc b/content/browser/geolocation/network_location_request.cc
index 94074be561d9c7b4acde2e456099f9ede99d04d0..9418a3f537d0917640606af8dec7989b25ff1592 100644
--- a/content/browser/geolocation/network_location_request.cc
+++ b/content/browser/geolocation/network_location_request.cc
@@ -10,6 +10,7 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/sparse_histogram.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@@ -31,6 +32,32 @@ const char kLatitudeString[] = "lat";
const char kLongitudeString[] = "lng";
const char kAccuracyString[] = "accuracy";
+enum NetworkLocationRequestEvent {
+ // NOTE: Do not renumber these as that would confuse interpretation of
+ // previously logged data. When making changes, also update the enum list
+ // in tools/metrics/histograms/histograms.xml to keep it in sync.
+ NETWORK_LOCATION_REQUEST_EVENT_REQUEST_START = 0,
+ NETWORK_LOCATION_REQUEST_EVENT_REQUEST_CANCEL = 1,
+ NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_SUCCESS = 2,
+ NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_NOT_OK = 3,
+ NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_EMPTY = 4,
+ NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_MALFORMED = 5,
+ NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_INVALID_FIX = 6,
+
+ // NOTE: Add entries only immediately above this line.
+ NETWORK_LOCATION_REQUEST_EVENT_COUNT = 7
+};
+
+void RecordUmaEvent(NetworkLocationRequestEvent event) {
+ UMA_HISTOGRAM_ENUMERATION("Geolocation.NetworkLocationRequest.Event",
+ event, NETWORK_LOCATION_REQUEST_EVENT_COUNT);
+}
+
+void RecordUmaResponseCode(int code) {
+ UMA_HISTOGRAM_SPARSE_SLOWLY("Geolocation.NetworkLocationRequest.ResponseCode",
+ code);
+}
+
// Local functions
// Creates the request url to send to the server.
GURL FormRequestURL(const GURL& url);
@@ -40,7 +67,8 @@ void FormUploadData(const WifiData& wifi_data,
const string16& access_token,
std::string* upload_data);
-// Parsers the server response.
+// Attempts to extract a position from the response. Detects and indicates
+// various failure cases.
void GetLocationFromResponse(bool http_post_result,
int status_code,
const std::string& response_body,
@@ -78,8 +106,10 @@ NetworkLocationRequest::~NetworkLocationRequest() {
bool NetworkLocationRequest::MakeRequest(const string16& access_token,
const WifiData& wifi_data,
const base::Time& timestamp) {
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_START);
if (url_fetcher_ != NULL) {
DVLOG(1) << "NetworkLocationRequest : Cancelling pending request";
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_REQUEST_CANCEL);
url_fetcher_.reset();
}
wifi_data_ = wifi_data;
@@ -108,6 +138,7 @@ void NetworkLocationRequest::OnURLFetchComplete(
net::URLRequestStatus status = source->GetStatus();
int response_code = source->GetResponseCode();
+ RecordUmaResponseCode(response_code);
Geoposition position;
string16 access_token;
@@ -259,12 +290,14 @@ void GetLocationFromResponse(bool http_post_result,
// we're offline, or there was no response.
if (!http_post_result) {
FormatPositionError(server_url, "No response received", position);
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_EMPTY);
return;
}
if (status_code != 200) { // HTTP OK.
std::string message = "Returned error code ";
message += base::IntToString(status_code);
FormatPositionError(server_url, message, position);
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_NOT_OK);
return;
}
// We use the timestamp from the wifi data that was used to generate
@@ -272,6 +305,7 @@ void GetLocationFromResponse(bool http_post_result,
if (!ParseServerResponse(response_body, timestamp, position, access_token)) {
// We failed to parse the repsonse.
FormatPositionError(server_url, "Response was malformed", position);
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_MALFORMED);
return;
}
// The response was successfully parsed, but it may not be a valid
@@ -279,8 +313,10 @@ void GetLocationFromResponse(bool http_post_result,
if (!position->Validate()) {
FormatPositionError(server_url,
"Did not provide a good position fix", position);
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_INVALID_FIX);
return;
}
+ RecordUmaEvent(NETWORK_LOCATION_REQUEST_EVENT_RESPONSE_SUCCESS);
}
// Numeric values without a decimal point have type integer and IsDouble() will
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698