metrics_cros_settings_provider.cc revision 4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7
1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/metrics_cros_settings_provider.h"
6
7#include "base/string_util.h"
8#include "base/values.h"
9#include "chrome/browser/chromeos/cros_settings.h"
10#include "chrome/browser/chromeos/cros_settings_names.h"
11#include "chrome/browser/options_util.h"
12#include "chrome/installer/util/google_update_settings.h"
13
14#if defined(USE_LINUX_BREAKPAD)
15#include "chrome/app/breakpad_linux.h"
16#endif
17
18namespace chromeos {
19
20void MetricsCrosSettingsProvider::DoSet(const std::string& path,
21                                        Value* value) {
22  DCHECK(path == kStatsReportingPref);
23  bool enabled = false;
24  CHECK(value->GetAsBoolean(&enabled));
25  if (SetMetricsStatus(enabled)) {
26    CrosSettings::Get()->FireObservers(path.c_str());
27  }
28}
29
30bool MetricsCrosSettingsProvider::Get(const std::string& path,
31                                      Value** value) const {
32  DCHECK(path == kStatsReportingPref);
33  *value = Value::CreateBooleanValue(GetMetricsStatus());
34  return true;
35}
36
37// static
38bool MetricsCrosSettingsProvider::SetMetricsStatus(bool enabled) {
39  VLOG(1) << "Setting cros stats/crash metric reporting to " << enabled;
40  if (enabled != GoogleUpdateSettings::GetCollectStatsConsent()) {
41    bool new_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled);
42#if defined(USE_LINUX_BREAKPAD)
43    if (new_enabled)
44      InitCrashReporter();
45    // Else, if (!new_enabled), we should have turned crash reporting off
46    // here, but there is no API for that currently (while we use
47    // BreakPad). But this is not a big deal: crash reporting will be off
48    // after reboot for the current process while other Chrome processes
49    // will start when the setting is already set up. Other ChromeOS
50    // processes does not use BreakPad.
51#endif
52    return new_enabled == enabled;
53  }
54  return false;
55}
56
57// static
58bool MetricsCrosSettingsProvider::GetMetricsStatus() {
59  return GoogleUpdateSettings::GetCollectStatsConsent();
60}
61
62bool MetricsCrosSettingsProvider::HandlesSetting(const std::string& path) {
63  return ::StartsWithASCII(path, kStatsReportingPref, true);
64}
65
66};  // namespace chromeos
67