blob: 3fadfb97b8da34b502613e0d2f38ca316ed93f9c [file] [log] [blame]
[email protected]91b1d912014-06-05 10:52:081// Copyright 2014 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]91b1d912014-06-05 10:52:085#include "components/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]76869ff2013-01-15 16:13:477#include <algorithm>
[email protected]1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
[email protected]0f2f7792013-11-28 16:09:1411#include "base/base64.h"
[email protected]d1be67b2008-11-19 20:28:3812#include "base/basictypes.h"
sebmarchand2f4ed502014-10-31 15:28:1913#include "base/build_time.h"
[email protected]5c8f89f692013-07-18 11:13:2814#include "base/cpu.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]bfb77b52014-06-07 01:54:0116#include "base/metrics/histogram.h"
17#include "base/metrics/histogram_samples.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_registry_simple.h"
19#include "base/prefs/pref_service.h"
[email protected]0f2f7792013-11-28 16:09:1420#include "base/sha1.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3122#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1424#include "base/sys_info.h"
[email protected]84813472013-06-28 00:25:1925#include "base/time/time.h"
rtenneti72546962014-12-15 21:41:5926#include "components/metrics/histogram_encoder.h"
[email protected]bfb77b52014-06-07 01:54:0127#include "components/metrics/metrics_hashes.h"
[email protected]91b1d912014-06-05 10:52:0828#include "components/metrics/metrics_pref_names.h"
[email protected]85791b0b2014-05-20 15:18:5829#include "components/metrics/metrics_provider.h"
[email protected]09dee82d2014-05-22 14:00:5330#include "components/metrics/metrics_service_client.h"
[email protected]bfb77b52014-06-07 01:54:0131#include "components/metrics/proto/histogram_event.pb.h"
[email protected]064107e2014-05-02 00:59:0632#include "components/metrics/proto/system_profile.pb.h"
[email protected]bfb77b52014-06-07 01:54:0133#include "components/metrics/proto/user_action_event.pb.h"
[email protected]b3610d42014-05-19 18:07:2334#include "components/variations/active_field_trials.h"
initial.commit09911bf2008-07-26 23:55:2935
[email protected]5106b3a2012-10-03 20:10:4436#if defined(OS_ANDROID)
37#include "base/android/build_info.h"
38#endif
39
[email protected]d1be67b2008-11-19 20:28:3840#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3941#include "base/win/metro.h"
42
43// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3844extern "C" IMAGE_DOS_HEADER __ImageBase;
45#endif
46
[email protected]bfb77b52014-06-07 01:54:0147using base::SampleCountIterator;
[email protected]b3610d42014-05-19 18:07:2348typedef variations::ActiveGroupId ActiveGroupId;
[email protected]79078df2012-02-16 01:22:3249
asvitkinecbd420732014-08-26 22:15:4050namespace metrics {
51
[email protected]1df44b72012-01-19 05:20:3452namespace {
53
[email protected]bfb77b52014-06-07 01:54:0154// Any id less than 16 bytes is considered to be a testing id.
55bool IsTestingID(const std::string& id) {
56 return id.size() < 16;
57}
58
[email protected]1df44b72012-01-19 05:20:3459// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4060// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0961std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3462 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3463 NOTREACHED();
64 return "0";
65 }
[email protected]767c9d92012-03-02 16:04:3466
asvitkine4c1d1ef2014-09-29 20:57:3267 return pref->GetString(prefs::kMetricsReportingEnabledTimestamp);
[email protected]1df44b72012-01-19 05:20:3468}
69
[email protected]0f2f7792013-11-28 16:09:1470// Computes a SHA-1 hash of |data| and returns it as a hex string.
71std::string ComputeSHA1(const std::string& data) {
72 const std::string sha1 = base::SHA1HashString(data);
73 return base::HexEncode(sha1.data(), sha1.size());
74}
75
[email protected]0c8b7ad2012-11-06 07:08:1476void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:3477 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:1478 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:0379 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:3480 SystemProfileProto::FieldTrial* field_trial =
81 system_profile->add_field_trial();
82 field_trial->set_name_id(it->name);
83 field_trial->set_group_id(it->group);
84 }
85}
86
[email protected]86573d12013-07-11 19:48:3287// Round a timestamp measured in seconds since epoch to one with a granularity
88// of an hour. This can be used before uploaded potentially sensitive
89// timestamps.
90int64 RoundSecondsToHour(int64 time_in_seconds) {
91 return 3600 * (time_in_seconds / 3600);
92}
93
[email protected]1df44b72012-01-19 05:20:3494} // namespace
95
[email protected]9eae4032014-04-09 19:15:1996MetricsLog::MetricsLog(const std::string& client_id,
97 int session_id,
[email protected]09dee82d2014-05-22 14:00:5398 LogType log_type,
asvitkine4c1d1ef2014-09-29 20:57:3299 MetricsServiceClient* client,
[email protected]24f81ca2014-05-26 15:59:34100 PrefService* local_state)
[email protected]bfb77b52014-06-07 01:54:01101 : closed_(false),
102 log_type_(log_type),
[email protected]09dee82d2014-05-22 14:00:53103 client_(client),
[email protected]24f81ca2014-05-26 15:59:34104 creation_time_(base::TimeTicks::Now()),
105 local_state_(local_state) {
[email protected]bfb77b52014-06-07 01:54:01106 if (IsTestingID(client_id))
107 uma_proto_.set_client_id(0);
108 else
109 uma_proto_.set_client_id(Hash(client_id));
110
111 uma_proto_.set_session_id(session_id);
112
asvitkine4c1d1ef2014-09-29 20:57:32113 const int32 product = client_->GetProduct();
114 // Only set the product if it differs from the default value.
115 if (product != uma_proto_.product())
116 uma_proto_.set_product(product);
117
[email protected]bfb77b52014-06-07 01:54:01118 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile();
119 system_profile->set_build_timestamp(GetBuildTime());
120 system_profile->set_app_version(client_->GetVersionString());
121 system_profile->set_channel(client_->GetChannel());
vadimt690531262015-01-07 15:35:22122#if defined(SYZYASAN)
123 system_profile->set_is_asan_build(true);
124#endif
[email protected]afc03f02013-10-11 06:01:35125}
[email protected]5ed7d4572009-12-23 17:42:41126
[email protected]bfb77b52014-06-07 01:54:01127MetricsLog::~MetricsLog() {
128}
initial.commit09911bf2008-07-26 23:55:29129
[email protected]91b1d912014-06-05 10:52:08130// static
131void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
asvitkine4c1d1ef2014-09-29 20:57:32132 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
133 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0);
134 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0);
135 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]91b1d912014-06-05 10:52:08136 registry->RegisterIntegerPref(
asvitkine4c1d1ef2014-09-29 20:57:32137 prefs::kStabilityBreakpadRegistrationSuccess, 0);
138 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0);
139 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0);
140 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile,
[email protected]91b1d912014-06-05 10:52:08141 std::string());
asvitkine4c1d1ef2014-09-29 20:57:32142 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash,
[email protected]91b1d912014-06-05 10:52:08143 std::string());
144}
145
[email protected]bfb77b52014-06-07 01:54:01146// static
147uint64 MetricsLog::Hash(const std::string& value) {
asvitkine4c1d1ef2014-09-29 20:57:32148 uint64 hash = HashMetricName(value);
[email protected]bfb77b52014-06-07 01:54:01149
150 // The following log is VERY helpful when folks add some named histogram into
151 // the code, but forgot to update the descriptive list of histograms. When
152 // that happens, all we get to see (server side) is a hash of the histogram
153 // name. We can then use this logging to find out what histogram name was
154 // being hashed to a given MD5 value by just running the version of Chromium
155 // in question with --enable-logging.
156 DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]";
157
158 return hash;
159}
160
161// static
162int64 MetricsLog::GetBuildTime() {
163 static int64 integral_build_time = 0;
sebmarchand2f4ed502014-10-31 15:28:19164 if (!integral_build_time)
165 integral_build_time = static_cast<int64>(base::GetBuildTime().ToTimeT());
[email protected]bfb77b52014-06-07 01:54:01166 return integral_build_time;
167}
168
169// static
170int64 MetricsLog::GetCurrentTime() {
171 return (base::TimeTicks::Now() - base::TimeTicks()).InSeconds();
172}
173
174void MetricsLog::RecordUserAction(const std::string& key) {
175 DCHECK(!closed_);
176
177 UserActionEventProto* user_action = uma_proto_.add_user_action_event();
178 user_action->set_name_hash(Hash(key));
179 user_action->set_time(GetCurrentTime());
180}
181
182void MetricsLog::RecordHistogramDelta(const std::string& histogram_name,
183 const base::HistogramSamples& snapshot) {
184 DCHECK(!closed_);
rtenneti72546962014-12-15 21:41:59185 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_);
[email protected]bfb77b52014-06-07 01:54:01186}
187
[email protected]85791b0b2014-05-20 15:18:58188void MetricsLog::RecordStabilityMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32189 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]85791b0b2014-05-20 15:18:58190 base::TimeDelta incremental_uptime,
191 base::TimeDelta uptime) {
[email protected]bfb77b52014-06-07 01:54:01192 DCHECK(!closed_);
[email protected]0f2f7792013-11-28 16:09:14193 DCHECK(HasEnvironment());
194 DCHECK(!HasStabilityMetrics());
[email protected]0b33f80b2008-12-17 21:34:36195
[email protected]24f81ca2014-05-26 15:59:34196 PrefService* pref = local_state_;
[email protected]0b33f80b2008-12-17 21:34:36197 DCHECK(pref);
198
initial.commit09911bf2008-07-26 23:55:29199 // Get stability attributes out of Local State, zeroing out stored values.
200 // NOTE: This could lead to some data loss if this report isn't successfully
201 // sent, but that's true for all the metrics.
202
[email protected]147bbc0b2009-01-06 19:37:40203 WriteRequiredStabilityAttributes(pref);
[email protected]0edf8762013-11-21 18:33:30204
205 // Record recent delta for critical stability metrics. We can't wait for a
206 // restart to gather these, as that delay biases our observation away from
207 // users that run happily for a looooong time. We send increments with each
208 // uma log upload, just as we send histogram data.
[email protected]076961c2014-03-12 22:23:56209 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
initial.commit09911bf2008-07-26 23:55:29210
[email protected]48ff2c7f2014-05-23 09:57:45211 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]85791b0b2014-05-20 15:18:58212 for (size_t i = 0; i < metrics_providers.size(); ++i)
[email protected]48ff2c7f2014-05-23 09:57:45213 metrics_providers[i]->ProvideStabilityMetrics(system_profile);
[email protected]85791b0b2014-05-20 15:18:58214
[email protected]0edf8762013-11-21 18:33:30215 // Omit some stats unless this is the initial stability log.
[email protected]9eae4032014-04-09 19:15:19216 if (log_type() != INITIAL_STABILITY_LOG)
[email protected]0edf8762013-11-21 18:33:30217 return;
218
[email protected]fe58acc22012-02-29 01:29:58219 int incomplete_shutdown_count =
asvitkine4c1d1ef2014-09-29 20:57:32220 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
221 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58222 int breakpad_registration_success_count =
asvitkine4c1d1ef2014-09-29 20:57:32223 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
224 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58225 int breakpad_registration_failure_count =
asvitkine4c1d1ef2014-09-29 20:57:32226 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
227 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58228 int debugger_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32229 pref->GetInteger(prefs::kStabilityDebuggerPresent);
230 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58231 int debugger_not_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32232 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
233 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31234
[email protected]fe58acc22012-02-29 01:29:58235 // TODO(jar): The following are all optional, so we *could* optimize them for
236 // values of zero (and not include them).
[email protected]48ff2c7f2014-05-23 09:57:45237 SystemProfileProto::Stability* stability =
238 system_profile->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58239 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
240 stability->set_breakpad_registration_success_count(
241 breakpad_registration_success_count);
242 stability->set_breakpad_registration_failure_count(
243 breakpad_registration_failure_count);
244 stability->set_debugger_present_count(debugger_present_count);
245 stability->set_debugger_not_present_count(debugger_not_present_count);
[email protected]0edf8762013-11-21 18:33:30246}
[email protected]fe58acc22012-02-29 01:29:58247
[email protected]85791b0b2014-05-20 15:18:58248void MetricsLog::RecordGeneralMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32249 const std::vector<MetricsProvider*>& metrics_providers) {
[email protected]85791b0b2014-05-20 15:18:58250 for (size_t i = 0; i < metrics_providers.size(); ++i)
251 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
252}
253
[email protected]0edf8762013-11-21 18:33:30254void MetricsLog::GetFieldTrialIds(
255 std::vector<ActiveGroupId>* field_trial_ids) const {
[email protected]b3610d42014-05-19 18:07:23256 variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]147bbc0b2009-01-06 19:37:40257}
258
[email protected]0f2f7792013-11-28 16:09:14259bool MetricsLog::HasEnvironment() const {
260 return uma_proto()->system_profile().has_uma_enabled_date();
261}
262
263bool MetricsLog::HasStabilityMetrics() const {
264 return uma_proto()->system_profile().stability().has_launch_count();
265}
266
[email protected]fe58acc22012-02-29 01:29:58267// The server refuses data that doesn't have certain values. crashcount and
268// launchcount are currently "required" in the "stability" group.
269// TODO(isherman): Stop writing these attributes specially once the migration to
270// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40271void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
asvitkine4c1d1ef2014-09-29 20:57:32272 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
273 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
274 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
275 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58276
[email protected]fe58acc22012-02-29 01:29:58277 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34278 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58279 stability->set_launch_count(launch_count);
280 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36281}
282
[email protected]c68a2b9b2013-10-09 18:16:36283void MetricsLog::WriteRealtimeStabilityAttributes(
284 PrefService* pref,
[email protected]076961c2014-03-12 22:23:56285 base::TimeDelta incremental_uptime,
286 base::TimeDelta uptime) {
[email protected]0b33f80b2008-12-17 21:34:36287 // Update the stats which are critical for real-time stability monitoring.
288 // Since these are "optional," only list ones that are non-zero, as the counts
[email protected]250f7b662013-11-23 02:36:51289 // are aggregated (summed) server side.
[email protected]0b33f80b2008-12-17 21:34:36290
[email protected]fe58acc22012-02-29 01:29:58291 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34292 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36293
[email protected]076961c2014-03-12 22:23:56294 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds();
295 if (incremental_uptime_sec)
296 stability->set_incremental_uptime_sec(incremental_uptime_sec);
297 const uint64 uptime_sec = uptime.InSeconds();
[email protected]c68a2b9b2013-10-09 18:16:36298 if (uptime_sec)
299 stability->set_uptime_sec(uptime_sec);
[email protected]0b33f80b2008-12-17 21:34:36300}
301
initial.commit09911bf2008-07-26 23:55:29302void MetricsLog::RecordEnvironment(
asvitkine4c1d1ef2014-09-29 20:57:32303 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]65801452014-07-09 05:42:41304 const std::vector<variations::ActiveGroupId>& synthetic_trials,
305 int64 install_date) {
[email protected]0f2f7792013-11-28 16:09:14306 DCHECK(!HasEnvironment());
307
[email protected]bc66d532012-03-23 01:57:05308 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29309
310 std::string brand_code;
[email protected]09dee82d2014-05-22 14:00:53311 if (client_->GetBrand(&brand_code))
[email protected]24b9bb392013-01-29 20:29:29312 system_profile->set_brand_code(brand_code);
313
[email protected]cc5d7f42012-10-30 00:30:09314 int enabled_date;
[email protected]24f81ca2014-05-26 15:59:34315 bool success =
316 base::StringToInt(GetMetricsEnabledDate(local_state_), &enabled_date);
[email protected]bc66d532012-03-23 01:57:05317 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32318
319 // Reduce granularity of the enabled_date field to nearest hour.
320 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
321
[email protected]86573d12013-07-11 19:48:32322 // Reduce granularity of the install_date field to nearest hour.
323 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05324
[email protected]09dee82d2014-05-22 14:00:53325 system_profile->set_application_locale(client_->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05326
327 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]51994b22014-05-30 13:24:21328
jeremyba4eca92014-11-06 18:47:10329 // HardwareModelName() will return an empty string on platforms where it's
330 // not implemented or if an error occured.
331 hardware->set_hardware_class(base::SysInfo::HardwareModelName());
[email protected]51994b22014-05-30 13:24:21332
[email protected]0b6a4fb2012-10-16 01:58:21333 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05334 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
335#if defined(OS_WIN)
336 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
337#endif
338
339 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39340 std::string os_name = base::SysInfo::OperatingSystemName();
341#if defined(OS_WIN)
342 // TODO(mad): This only checks whether the main process is a Metro process at
343 // upload time; not whether the collected metrics were all gathered from
344 // Metro. This is ok as an approximation for now, since users will rarely be
345 // switching from Metro to Desktop mode; but we should re-evaluate whether we
346 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
347 if (base::win::IsMetroProcess())
348 os_name += " (Metro)";
349#endif
350 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05351 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44352#if defined(OS_ANDROID)
353 os->set_fingerprint(
354 base::android::BuildInfo::GetInstance()->android_build_fp());
355#endif
[email protected]bc66d532012-03-23 01:57:05356
[email protected]5c8f89f692013-07-18 11:13:28357 base::CPU cpu_info;
358 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
359 cpu->set_vendor_name(cpu_info.vendor_name());
360 cpu->set_signature(cpu_info.signature());
361
[email protected]0c8b7ad2012-11-06 07:08:14362 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34363 GetFieldTrialIds(&field_trial_ids);
364 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]60677562013-11-17 15:52:55365 WriteFieldTrials(synthetic_trials, system_profile);
[email protected]f65859e2013-02-04 20:00:25366
[email protected]85791b0b2014-05-20 15:18:58367 for (size_t i = 0; i < metrics_providers.size(); ++i)
368 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
369
[email protected]0f2f7792013-11-28 16:09:14370 std::string serialied_system_profile;
371 std::string base64_system_profile;
[email protected]33fca122013-12-11 01:48:50372 if (system_profile->SerializeToString(&serialied_system_profile)) {
373 base::Base64Encode(serialied_system_profile, &base64_system_profile);
[email protected]24f81ca2014-05-26 15:59:34374 PrefService* local_state = local_state_;
asvitkine4c1d1ef2014-09-29 20:57:32375 local_state->SetString(prefs::kStabilitySavedSystemProfile,
[email protected]0f2f7792013-11-28 16:09:14376 base64_system_profile);
asvitkine4c1d1ef2014-09-29 20:57:32377 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
[email protected]0f2f7792013-11-28 16:09:14378 ComputeSHA1(serialied_system_profile));
379 }
380}
381
382bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
[email protected]24f81ca2014-05-26 15:59:34383 PrefService* local_state = local_state_;
[email protected]0f2f7792013-11-28 16:09:14384 const std::string base64_system_profile =
asvitkine4c1d1ef2014-09-29 20:57:32385 local_state->GetString(prefs::kStabilitySavedSystemProfile);
[email protected]0f2f7792013-11-28 16:09:14386 if (base64_system_profile.empty())
387 return false;
388
389 const std::string system_profile_hash =
asvitkine4c1d1ef2014-09-29 20:57:32390 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
391 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
392 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
[email protected]0f2f7792013-11-28 16:09:14393
394 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
395 std::string serialied_system_profile;
396 return base::Base64Decode(base64_system_profile, &serialied_system_profile) &&
397 ComputeSHA1(serialied_system_profile) == system_profile_hash &&
398 system_profile->ParseFromString(serialied_system_profile);
initial.commit09911bf2008-07-26 23:55:29399}
400
[email protected]bfb77b52014-06-07 01:54:01401void MetricsLog::CloseLog() {
402 DCHECK(!closed_);
403 closed_ = true;
404}
405
406void MetricsLog::GetEncodedLog(std::string* encoded_log) {
407 DCHECK(closed_);
408 uma_proto_.SerializeToString(encoded_log);
409}
asvitkinecbd420732014-08-26 22:15:40410
411} // namespace metrics