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

Unified Diff: components/network_time/network_time_tracker.cc

Issue 2176373003: Add NetworkTimeTracker UMA histograms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a comment about net::OK in the unit test Created 4 years, 5 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/network_time/network_time_tracker.cc
diff --git a/components/network_time/network_time_tracker.cc b/components/network_time/network_time_tracker.cc
index dc4ccbb56d3f498294705195257f675a74afbcde..c51937fe700a5933b62a9382274ac58322d4894a 100644
--- a/components/network_time/network_time_tracker.cc
+++ b/components/network_time/network_time_tracker.cc
@@ -13,6 +13,8 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/metrics/sparse_histogram.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
@@ -367,6 +369,9 @@ void NetworkTimeTracker::CheckTime() {
net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SEND_AUTH_DATA);
+
+ UMA_HISTOGRAM_BOOLEAN("NetworkTimeTracker.UpdateTimeFetchAttempted", true);
+
time_fetcher_->Start();
fetch_started_ = tick_clock_->NowTicks();
@@ -374,40 +379,54 @@ void NetworkTimeTracker::CheckTime() {
}
bool NetworkTimeTracker::UpdateTimeFromResponse() {
- if (time_fetcher_->GetStatus().status() != net::URLRequestStatus::SUCCESS &&
+ if (time_fetcher_->GetStatus().status() != net::URLRequestStatus::SUCCESS ||
time_fetcher_->GetResponseCode() != 200) {
DVLOG(1) << "fetch failed, status=" << time_fetcher_->GetStatus().status()
<< ",code=" << time_fetcher_->GetResponseCode();
+ // The error code is negated because net errors are negative, but
+ // the corresponding histogram enum is positive.
+ UMA_HISTOGRAM_SPARSE_SLOWLY("NetworkTimeTracker.UpdateTimeFetchFailed",
+ -time_fetcher_->GetStatus().error());
return false;
}
+ const char kHistogramName[] = "NetworkTimeTracker.UpdateTimeFetchValid";
+
std::string response_body;
if (!time_fetcher_->GetResponseAsString(&response_body)) {
DVLOG(1) << "failed to get response";
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, false);
Steven Holte 2016/07/28 19:22:46 This macro uses a static pointer to the underlying
estark 2016/07/28 20:30:49 Done.
return false;
}
DCHECK(query_signer_);
if (!query_signer_->ValidateResponse(response_body,
GetServerProof(time_fetcher_.get()))) {
DVLOG(1) << "invalid signature";
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, false);
return false;
}
response_body = response_body.substr(5); // Skips leading )]}'\n
std::unique_ptr<base::Value> value = base::JSONReader::Read(response_body);
if (!value) {
DVLOG(1) << "bad JSON";
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, false);
return false;
}
const base::DictionaryValue* dict;
if (!value->GetAsDictionary(&dict)) {
DVLOG(1) << "not a dictionary";
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, false);
return false;
}
double current_time_millis;
if (!dict->GetDouble("current_time_millis", &current_time_millis)) {
DVLOG(1) << "no current_time_millis";
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, false);
return false;
}
+
+ UMA_HISTOGRAM_BOOLEAN(kHistogramName, true);
+
// There is a "server_nonce" key here too, but it serves no purpose other than
// to make the server's response unpredictable.
base::Time current_time = base::Time::FromJsTime(current_time_millis);
« no previous file with comments | « no previous file | components/network_time/network_time_tracker_unittest.cc » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698