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

Side by Side Diff: components/metrics/metrics_log.cc

Issue 1030503003: Metrics log modification to handle external components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add version_utils Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/metrics_log.h" 5 #include "components/metrics/metrics_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 namespace metrics { 50 namespace metrics {
51 51
52 namespace { 52 namespace {
53 53
54 // Any id less than 16 bytes is considered to be a testing id. 54 // Any id less than 16 bytes is considered to be a testing id.
55 bool IsTestingID(const std::string& id) { 55 bool IsTestingID(const std::string& id) {
56 return id.size() < 16; 56 return id.size() < 16;
57 } 57 }
58 58
59 // Returns the date at which the current metrics client ID was created as
60 // a string containing seconds since the epoch, or "0" if none was found.
61 std::string GetMetricsEnabledDate(PrefService* pref) {
62 if (!pref) {
63 NOTREACHED();
64 return "0";
65 }
66
67 return pref->GetString(prefs::kMetricsReportingEnabledTimestamp);
68 }
69
70 // Computes a SHA-1 hash of |data| and returns it as a hex string. 59 // Computes a SHA-1 hash of |data| and returns it as a hex string.
71 std::string ComputeSHA1(const std::string& data) { 60 std::string ComputeSHA1(const std::string& data) {
72 const std::string sha1 = base::SHA1HashString(data); 61 const std::string sha1 = base::SHA1HashString(data);
73 return base::HexEncode(sha1.data(), sha1.size()); 62 return base::HexEncode(sha1.data(), sha1.size());
74 } 63 }
75 64
76 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, 65 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
77 SystemProfileProto* system_profile) { 66 SystemProfileProto* system_profile) {
78 for (std::vector<ActiveGroupId>::const_iterator it = 67 for (std::vector<ActiveGroupId>::const_iterator it =
79 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { 68 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (incremental_uptime_sec) 284 if (incremental_uptime_sec)
296 stability->set_incremental_uptime_sec(incremental_uptime_sec); 285 stability->set_incremental_uptime_sec(incremental_uptime_sec);
297 const uint64 uptime_sec = uptime.InSeconds(); 286 const uint64 uptime_sec = uptime.InSeconds();
298 if (uptime_sec) 287 if (uptime_sec)
299 stability->set_uptime_sec(uptime_sec); 288 stability->set_uptime_sec(uptime_sec);
300 } 289 }
301 290
302 void MetricsLog::RecordEnvironment( 291 void MetricsLog::RecordEnvironment(
303 const std::vector<MetricsProvider*>& metrics_providers, 292 const std::vector<MetricsProvider*>& metrics_providers,
304 const std::vector<variations::ActiveGroupId>& synthetic_trials, 293 const std::vector<variations::ActiveGroupId>& synthetic_trials,
305 int64 install_date) { 294 int64 install_date,
295 int64 metrics_reporting_enabled_date) {
306 DCHECK(!HasEnvironment()); 296 DCHECK(!HasEnvironment());
307 297
308 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 298 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
309 299
310 std::string brand_code; 300 std::string brand_code;
311 if (client_->GetBrand(&brand_code)) 301 if (client_->GetBrand(&brand_code))
312 system_profile->set_brand_code(brand_code); 302 system_profile->set_brand_code(brand_code);
313 303
314 int enabled_date;
315 bool success =
316 base::StringToInt(GetMetricsEnabledDate(local_state_), &enabled_date);
317 DCHECK(success);
318
319 // Reduce granularity of the enabled_date field to nearest hour. 304 // Reduce granularity of the enabled_date field to nearest hour.
320 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); 305 system_profile->set_uma_enabled_date(
306 RoundSecondsToHour(metrics_reporting_enabled_date));
321 307
322 // Reduce granularity of the install_date field to nearest hour. 308 // Reduce granularity of the install_date field to nearest hour.
323 system_profile->set_install_date(RoundSecondsToHour(install_date)); 309 system_profile->set_install_date(RoundSecondsToHour(install_date));
324 310
325 system_profile->set_application_locale(client_->GetApplicationLocale()); 311 system_profile->set_application_locale(client_->GetApplicationLocale());
326 312
327 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); 313 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
328 314
329 // HardwareModelName() will return an empty string on platforms where it's 315 // HardwareModelName() will return an empty string on platforms where it's
330 // not implemented or if an error occured. 316 // not implemented or if an error occured.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 DCHECK(!closed_); 389 DCHECK(!closed_);
404 closed_ = true; 390 closed_ = true;
405 } 391 }
406 392
407 void MetricsLog::GetEncodedLog(std::string* encoded_log) { 393 void MetricsLog::GetEncodedLog(std::string* encoded_log) {
408 DCHECK(closed_); 394 DCHECK(closed_);
409 uma_proto_.SerializeToString(encoded_log); 395 uma_proto_.SerializeToString(encoded_log);
410 } 396 }
411 397
412 } // namespace metrics 398 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698