blob: f7b1287057204887421a8bad1b098127984cc4b3 [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]0f2f7792013-11-28 16:09:1459// Computes a SHA-1 hash of |data| and returns it as a hex string.
60std::string ComputeSHA1(const std::string& data) {
61 const std::string sha1 = base::SHA1HashString(data);
62 return base::HexEncode(sha1.data(), sha1.size());
63}
64
[email protected]0c8b7ad2012-11-06 07:08:1465void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:3466 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:1467 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:0368 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:3469 SystemProfileProto::FieldTrial* field_trial =
70 system_profile->add_field_trial();
71 field_trial->set_name_id(it->name);
72 field_trial->set_group_id(it->group);
73 }
74}
75
[email protected]86573d12013-07-11 19:48:3276// Round a timestamp measured in seconds since epoch to one with a granularity
77// of an hour. This can be used before uploaded potentially sensitive
78// timestamps.
79int64 RoundSecondsToHour(int64 time_in_seconds) {
80 return 3600 * (time_in_seconds / 3600);
81}
82
[email protected]1df44b72012-01-19 05:20:3483} // namespace
84
[email protected]9eae4032014-04-09 19:15:1985MetricsLog::MetricsLog(const std::string& client_id,
86 int session_id,
[email protected]09dee82d2014-05-22 14:00:5387 LogType log_type,
asvitkine4c1d1ef2014-09-29 20:57:3288 MetricsServiceClient* client,
[email protected]24f81ca2014-05-26 15:59:3489 PrefService* local_state)
[email protected]bfb77b52014-06-07 01:54:0190 : closed_(false),
91 log_type_(log_type),
[email protected]09dee82d2014-05-22 14:00:5392 client_(client),
[email protected]24f81ca2014-05-26 15:59:3493 creation_time_(base::TimeTicks::Now()),
94 local_state_(local_state) {
[email protected]bfb77b52014-06-07 01:54:0195 if (IsTestingID(client_id))
96 uma_proto_.set_client_id(0);
97 else
98 uma_proto_.set_client_id(Hash(client_id));
99
100 uma_proto_.set_session_id(session_id);
101
asvitkine4c1d1ef2014-09-29 20:57:32102 const int32 product = client_->GetProduct();
103 // Only set the product if it differs from the default value.
104 if (product != uma_proto_.product())
105 uma_proto_.set_product(product);
106
[email protected]bfb77b52014-06-07 01:54:01107 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile();
108 system_profile->set_build_timestamp(GetBuildTime());
109 system_profile->set_app_version(client_->GetVersionString());
110 system_profile->set_channel(client_->GetChannel());
vadimt690531262015-01-07 15:35:22111#if defined(SYZYASAN)
112 system_profile->set_is_asan_build(true);
113#endif
[email protected]afc03f02013-10-11 06:01:35114}
[email protected]5ed7d4572009-12-23 17:42:41115
[email protected]bfb77b52014-06-07 01:54:01116MetricsLog::~MetricsLog() {
117}
initial.commit09911bf2008-07-26 23:55:29118
[email protected]91b1d912014-06-05 10:52:08119// static
120void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
asvitkine4c1d1ef2014-09-29 20:57:32121 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
122 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0);
123 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0);
124 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]91b1d912014-06-05 10:52:08125 registry->RegisterIntegerPref(
asvitkine4c1d1ef2014-09-29 20:57:32126 prefs::kStabilityBreakpadRegistrationSuccess, 0);
127 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0);
128 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0);
129 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile,
[email protected]91b1d912014-06-05 10:52:08130 std::string());
asvitkine4c1d1ef2014-09-29 20:57:32131 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash,
[email protected]91b1d912014-06-05 10:52:08132 std::string());
133}
134
[email protected]bfb77b52014-06-07 01:54:01135// static
136uint64 MetricsLog::Hash(const std::string& value) {
asvitkine4c1d1ef2014-09-29 20:57:32137 uint64 hash = HashMetricName(value);
[email protected]bfb77b52014-06-07 01:54:01138
139 // The following log is VERY helpful when folks add some named histogram into
140 // the code, but forgot to update the descriptive list of histograms. When
141 // that happens, all we get to see (server side) is a hash of the histogram
142 // name. We can then use this logging to find out what histogram name was
143 // being hashed to a given MD5 value by just running the version of Chromium
144 // in question with --enable-logging.
145 DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]";
146
147 return hash;
148}
149
150// static
151int64 MetricsLog::GetBuildTime() {
152 static int64 integral_build_time = 0;
sebmarchand2f4ed502014-10-31 15:28:19153 if (!integral_build_time)
154 integral_build_time = static_cast<int64>(base::GetBuildTime().ToTimeT());
[email protected]bfb77b52014-06-07 01:54:01155 return integral_build_time;
156}
157
158// static
159int64 MetricsLog::GetCurrentTime() {
160 return (base::TimeTicks::Now() - base::TimeTicks()).InSeconds();
161}
162
163void MetricsLog::RecordUserAction(const std::string& key) {
164 DCHECK(!closed_);
165
166 UserActionEventProto* user_action = uma_proto_.add_user_action_event();
167 user_action->set_name_hash(Hash(key));
168 user_action->set_time(GetCurrentTime());
169}
170
171void MetricsLog::RecordHistogramDelta(const std::string& histogram_name,
172 const base::HistogramSamples& snapshot) {
173 DCHECK(!closed_);
rtenneti72546962014-12-15 21:41:59174 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_);
[email protected]bfb77b52014-06-07 01:54:01175}
176
[email protected]85791b0b2014-05-20 15:18:58177void MetricsLog::RecordStabilityMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32178 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]85791b0b2014-05-20 15:18:58179 base::TimeDelta incremental_uptime,
180 base::TimeDelta uptime) {
[email protected]bfb77b52014-06-07 01:54:01181 DCHECK(!closed_);
[email protected]0f2f7792013-11-28 16:09:14182 DCHECK(HasEnvironment());
183 DCHECK(!HasStabilityMetrics());
[email protected]0b33f80b2008-12-17 21:34:36184
[email protected]24f81ca2014-05-26 15:59:34185 PrefService* pref = local_state_;
[email protected]0b33f80b2008-12-17 21:34:36186 DCHECK(pref);
187
initial.commit09911bf2008-07-26 23:55:29188 // Get stability attributes out of Local State, zeroing out stored values.
189 // NOTE: This could lead to some data loss if this report isn't successfully
190 // sent, but that's true for all the metrics.
191
[email protected]147bbc0b2009-01-06 19:37:40192 WriteRequiredStabilityAttributes(pref);
[email protected]0edf8762013-11-21 18:33:30193
194 // Record recent delta for critical stability metrics. We can't wait for a
195 // restart to gather these, as that delay biases our observation away from
196 // users that run happily for a looooong time. We send increments with each
197 // uma log upload, just as we send histogram data.
[email protected]076961c2014-03-12 22:23:56198 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
initial.commit09911bf2008-07-26 23:55:29199
[email protected]48ff2c7f2014-05-23 09:57:45200 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
lpromeroca8cb6f2015-04-30 18:16:53201 for (size_t i = 0; i < metrics_providers.size(); ++i) {
202 if (log_type() == INITIAL_STABILITY_LOG)
203 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile);
[email protected]48ff2c7f2014-05-23 09:57:45204 metrics_providers[i]->ProvideStabilityMetrics(system_profile);
lpromeroca8cb6f2015-04-30 18:16:53205 }
[email protected]85791b0b2014-05-20 15:18:58206
[email protected]0edf8762013-11-21 18:33:30207 // Omit some stats unless this is the initial stability log.
[email protected]9eae4032014-04-09 19:15:19208 if (log_type() != INITIAL_STABILITY_LOG)
[email protected]0edf8762013-11-21 18:33:30209 return;
210
[email protected]fe58acc22012-02-29 01:29:58211 int incomplete_shutdown_count =
asvitkine4c1d1ef2014-09-29 20:57:32212 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
213 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58214 int breakpad_registration_success_count =
asvitkine4c1d1ef2014-09-29 20:57:32215 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
216 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58217 int breakpad_registration_failure_count =
asvitkine4c1d1ef2014-09-29 20:57:32218 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
219 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58220 int debugger_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32221 pref->GetInteger(prefs::kStabilityDebuggerPresent);
222 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58223 int debugger_not_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32224 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
225 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31226
[email protected]fe58acc22012-02-29 01:29:58227 // TODO(jar): The following are all optional, so we *could* optimize them for
228 // values of zero (and not include them).
[email protected]48ff2c7f2014-05-23 09:57:45229 SystemProfileProto::Stability* stability =
230 system_profile->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58231 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
232 stability->set_breakpad_registration_success_count(
233 breakpad_registration_success_count);
234 stability->set_breakpad_registration_failure_count(
235 breakpad_registration_failure_count);
236 stability->set_debugger_present_count(debugger_present_count);
237 stability->set_debugger_not_present_count(debugger_not_present_count);
[email protected]0edf8762013-11-21 18:33:30238}
[email protected]fe58acc22012-02-29 01:29:58239
[email protected]85791b0b2014-05-20 15:18:58240void MetricsLog::RecordGeneralMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32241 const std::vector<MetricsProvider*>& metrics_providers) {
[email protected]85791b0b2014-05-20 15:18:58242 for (size_t i = 0; i < metrics_providers.size(); ++i)
243 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
244}
245
[email protected]0edf8762013-11-21 18:33:30246void MetricsLog::GetFieldTrialIds(
247 std::vector<ActiveGroupId>* field_trial_ids) const {
[email protected]b3610d42014-05-19 18:07:23248 variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]147bbc0b2009-01-06 19:37:40249}
250
[email protected]0f2f7792013-11-28 16:09:14251bool MetricsLog::HasEnvironment() const {
252 return uma_proto()->system_profile().has_uma_enabled_date();
253}
254
255bool MetricsLog::HasStabilityMetrics() const {
256 return uma_proto()->system_profile().stability().has_launch_count();
257}
258
[email protected]fe58acc22012-02-29 01:29:58259// The server refuses data that doesn't have certain values. crashcount and
260// launchcount are currently "required" in the "stability" group.
261// TODO(isherman): Stop writing these attributes specially once the migration to
262// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40263void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
asvitkine4c1d1ef2014-09-29 20:57:32264 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
265 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
266 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
267 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58268
[email protected]fe58acc22012-02-29 01:29:58269 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34270 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58271 stability->set_launch_count(launch_count);
272 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36273}
274
[email protected]c68a2b9b2013-10-09 18:16:36275void MetricsLog::WriteRealtimeStabilityAttributes(
276 PrefService* pref,
[email protected]076961c2014-03-12 22:23:56277 base::TimeDelta incremental_uptime,
278 base::TimeDelta uptime) {
[email protected]0b33f80b2008-12-17 21:34:36279 // Update the stats which are critical for real-time stability monitoring.
280 // Since these are "optional," only list ones that are non-zero, as the counts
[email protected]250f7b662013-11-23 02:36:51281 // are aggregated (summed) server side.
[email protected]0b33f80b2008-12-17 21:34:36282
[email protected]fe58acc22012-02-29 01:29:58283 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34284 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36285
[email protected]076961c2014-03-12 22:23:56286 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds();
287 if (incremental_uptime_sec)
288 stability->set_incremental_uptime_sec(incremental_uptime_sec);
289 const uint64 uptime_sec = uptime.InSeconds();
[email protected]c68a2b9b2013-10-09 18:16:36290 if (uptime_sec)
291 stability->set_uptime_sec(uptime_sec);
[email protected]0b33f80b2008-12-17 21:34:36292}
293
initial.commit09911bf2008-07-26 23:55:29294void MetricsLog::RecordEnvironment(
asvitkine4c1d1ef2014-09-29 20:57:32295 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]65801452014-07-09 05:42:41296 const std::vector<variations::ActiveGroupId>& synthetic_trials,
olivierrobinc3dfc5b2015-04-07 19:12:00297 int64 install_date,
298 int64 metrics_reporting_enabled_date) {
[email protected]0f2f7792013-11-28 16:09:14299 DCHECK(!HasEnvironment());
300
[email protected]bc66d532012-03-23 01:57:05301 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29302
303 std::string brand_code;
[email protected]09dee82d2014-05-22 14:00:53304 if (client_->GetBrand(&brand_code))
[email protected]24b9bb392013-01-29 20:29:29305 system_profile->set_brand_code(brand_code);
306
[email protected]86573d12013-07-11 19:48:32307 // Reduce granularity of the enabled_date field to nearest hour.
olivierrobinc3dfc5b2015-04-07 19:12:00308 system_profile->set_uma_enabled_date(
309 RoundSecondsToHour(metrics_reporting_enabled_date));
[email protected]86573d12013-07-11 19:48:32310
[email protected]86573d12013-07-11 19:48:32311 // Reduce granularity of the install_date field to nearest hour.
312 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05313
[email protected]09dee82d2014-05-22 14:00:53314 system_profile->set_application_locale(client_->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05315
316 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]51994b22014-05-30 13:24:21317
jeremyba4eca92014-11-06 18:47:10318 // HardwareModelName() will return an empty string on platforms where it's
319 // not implemented or if an error occured.
320 hardware->set_hardware_class(base::SysInfo::HardwareModelName());
[email protected]51994b22014-05-30 13:24:21321
[email protected]0b6a4fb2012-10-16 01:58:21322 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05323 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
324#if defined(OS_WIN)
325 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
326#endif
327
328 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39329 std::string os_name = base::SysInfo::OperatingSystemName();
330#if defined(OS_WIN)
331 // TODO(mad): This only checks whether the main process is a Metro process at
332 // upload time; not whether the collected metrics were all gathered from
333 // Metro. This is ok as an approximation for now, since users will rarely be
334 // switching from Metro to Desktop mode; but we should re-evaluate whether we
335 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
336 if (base::win::IsMetroProcess())
337 os_name += " (Metro)";
338#endif
339 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05340 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44341#if defined(OS_ANDROID)
342 os->set_fingerprint(
343 base::android::BuildInfo::GetInstance()->android_build_fp());
344#endif
[email protected]bc66d532012-03-23 01:57:05345
[email protected]5c8f89f692013-07-18 11:13:28346 base::CPU cpu_info;
347 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
348 cpu->set_vendor_name(cpu_info.vendor_name());
349 cpu->set_signature(cpu_info.signature());
gayanef550f50f2015-03-11 00:44:59350 cpu->set_num_cores(base::SysInfo::NumberOfProcessors());
[email protected]5c8f89f692013-07-18 11:13:28351
[email protected]0c8b7ad2012-11-06 07:08:14352 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34353 GetFieldTrialIds(&field_trial_ids);
354 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]60677562013-11-17 15:52:55355 WriteFieldTrials(synthetic_trials, system_profile);
[email protected]f65859e2013-02-04 20:00:25356
[email protected]85791b0b2014-05-20 15:18:58357 for (size_t i = 0; i < metrics_providers.size(); ++i)
358 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
359
[email protected]0f2f7792013-11-28 16:09:14360 std::string serialied_system_profile;
361 std::string base64_system_profile;
[email protected]33fca122013-12-11 01:48:50362 if (system_profile->SerializeToString(&serialied_system_profile)) {
363 base::Base64Encode(serialied_system_profile, &base64_system_profile);
[email protected]24f81ca2014-05-26 15:59:34364 PrefService* local_state = local_state_;
asvitkine4c1d1ef2014-09-29 20:57:32365 local_state->SetString(prefs::kStabilitySavedSystemProfile,
[email protected]0f2f7792013-11-28 16:09:14366 base64_system_profile);
asvitkine4c1d1ef2014-09-29 20:57:32367 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
[email protected]0f2f7792013-11-28 16:09:14368 ComputeSHA1(serialied_system_profile));
369 }
370}
371
372bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
[email protected]24f81ca2014-05-26 15:59:34373 PrefService* local_state = local_state_;
[email protected]0f2f7792013-11-28 16:09:14374 const std::string base64_system_profile =
asvitkine4c1d1ef2014-09-29 20:57:32375 local_state->GetString(prefs::kStabilitySavedSystemProfile);
[email protected]0f2f7792013-11-28 16:09:14376 if (base64_system_profile.empty())
377 return false;
378
379 const std::string system_profile_hash =
asvitkine4c1d1ef2014-09-29 20:57:32380 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
381 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
382 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
[email protected]0f2f7792013-11-28 16:09:14383
384 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
385 std::string serialied_system_profile;
386 return base::Base64Decode(base64_system_profile, &serialied_system_profile) &&
387 ComputeSHA1(serialied_system_profile) == system_profile_hash &&
388 system_profile->ParseFromString(serialied_system_profile);
initial.commit09911bf2008-07-26 23:55:29389}
390
[email protected]bfb77b52014-06-07 01:54:01391void MetricsLog::CloseLog() {
392 DCHECK(!closed_);
393 closed_ = true;
394}
395
396void MetricsLog::GetEncodedLog(std::string* encoded_log) {
397 DCHECK(closed_);
398 uma_proto_.SerializeToString(encoded_log);
399}
asvitkinecbd420732014-08-26 22:15:40400
401} // namespace metrics