1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file.
4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <stdint.h>
95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <string>
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/gtest_prod_util.h"
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/macros.h"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/metrics/metrics_reporting_state.h"
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/metrics/metrics_service_accessor.h"
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ChromeExtensionDownloaderFactory;
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass PrefService;
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class Profile;
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace {
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class CrashesDOMHandler;
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class FlashDOMHandler;
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace component_updater {
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ComponentUpdateService;
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RegisterSwReporterComponent(ComponentUpdateService* cus,
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 PrefService* prefs);
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace extensions {
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class MetricsPrivateGetIsCrashReportingEnabledFunction;
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace prerender {
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool IsOmniboxEnabled(Profile* profile);
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace system_logs {
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ChromeInternalLogSource;
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace options {
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass BrowserOptionsHandler;
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// This class limits and documents access to metrics service helper methods.
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Since these methods are private, each user has to be explicitly declared
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// as a 'friend' below.
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend void component_updater::RegisterSwReporterComponent(
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      component_updater::ComponentUpdateService* cus,
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      PrefService* prefs);
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend bool prerender::IsOmniboxEnabled(Profile* profile);
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend class ChromeExtensionDownloaderFactory;
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ChromeRenderMessageFilter;
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::CrashesDOMHandler;
595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  friend class DataReductionProxyChromeSettings;
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::FlashDOMHandler;
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class system_logs::ChromeInternalLogSource;
635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  friend class UmaSessionStats;
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend class options::BrowserOptionsHandler;
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  friend void InitiateMetricsReportingChange(
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      bool, const OnMetricsReportingCallbackType&);
67cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                           MetricsReportingEnabled);
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                           CrashReportingEnabled);
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
73cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if prefs::kMetricsReportingEnabled is set.
74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // TODO(asvitkine): Consolidate the method in MetricsStateManager.
75cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // TODO(asvitkine): This function does not report the correct value on
76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Android and ChromeOS, see http://crbug.com/362192.
77cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool IsMetricsReportingEnabled();
78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if crash reporting is enabled.  This is set at the platform
80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // level for Android and ChromeOS, and otherwise is the same as
81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // IsMetricsReportingEnabled for desktop Chrome.
82cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool IsCrashReportingEnabled();
83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Registers a field trial name and group to be used to annotate a UMA report
855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // with a particular Chrome configuration state. A UMA report will be
865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // annotated with this trial group if and only if all events in the report
875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // were created after the trial is registered. Only one group name may be
885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // registered at a time for a given trial name. Only the last group name that
895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // is registered for a given trial name will be recorded. The values passed
905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // in must not correspond to any real field trial in the code.
915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  static bool RegisterSyntheticFieldTrial(const std::string& trial_name,
925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                          const std::string& group_name);
935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Same as RegisterSyntheticFieldTrial above, but takes a hash for the trial
955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // name, rather than computing it from the string.
965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  static bool RegisterSyntheticFieldTrialWithNameHash(
975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      uint32_t trial_name_hash,
985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const std::string& group_name);
995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeMetricsServiceAccessor);
101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
103cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif  // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
104