• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_METRICS_CHROMEOS_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_CHROMEOS_METRICS_PROVIDER_H_
7 
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/metrics/perf_provider_chromeos.h"
10 #include "components/metrics/metrics_provider.h"
11 
12 namespace device {
13 class BluetoothAdapter;
14 }
15 
16 namespace metrics {
17 class ChromeUserMetricsExtension;
18 }
19 
20 class PrefRegistrySimple;
21 class PrefService;
22 
23 // Performs ChromeOS specific metrics logging.
24 class ChromeOSMetricsProvider : public metrics::MetricsProvider {
25  public:
26   ChromeOSMetricsProvider();
27   virtual ~ChromeOSMetricsProvider();
28 
29   static void RegisterPrefs(PrefRegistrySimple* registry);
30 
31   // Records a crash.
32   static void LogCrash(const std::string& crash_type);
33 
34   // Loads hardware class information. When this task is complete, |callback|
35   // is run.
36   void InitTaskGetHardwareClass(const base::Closure& callback);
37 
38   // metrics::MetricsProvider:
39   virtual void OnDidCreateMetricsLog() OVERRIDE;
40   virtual void ProvideSystemProfileMetrics(
41       metrics::SystemProfileProto* system_profile_proto) OVERRIDE;
42   virtual void ProvideStabilityMetrics(
43       metrics::SystemProfileProto* system_profile_proto) OVERRIDE;
44   virtual void ProvideGeneralMetrics(
45       metrics::ChromeUserMetricsExtension* uma_proto) OVERRIDE;
46 
47  private:
48   // Called on the FILE thread to load hardware class information.
49   void InitTaskGetHardwareClassOnFileThread();
50 
51   // Update the number of users logged into a multi-profile session.
52   // If the number of users change while the log is open, the call invalidates
53   // the user count value.
54   void UpdateMultiProfileUserCount(
55       metrics::SystemProfileProto* system_profile_proto);
56 
57   // Sets the Bluetooth Adapter instance used for the WriteBluetoothProto()
58   // call.
59   void SetBluetoothAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
60 
61   // Writes info about paired Bluetooth devices on this system.
62   void WriteBluetoothProto(metrics::SystemProfileProto* system_profile_proto);
63 
64   metrics::PerfProvider perf_provider_;
65 
66   // Bluetooth Adapter instance for collecting information about paired devices.
67   scoped_refptr<device::BluetoothAdapter> adapter_;
68 
69   // Whether the user count was registered at the last log initialization.
70   bool registered_user_count_at_log_initialization_;
71 
72   // The user count at the time that a log was last initialized. Contains a
73   // valid value only if |registered_user_count_at_log_initialization_| is
74   // true.
75   uint64 user_count_at_log_initialization_;
76 
77   // Hardware class (e.g., hardware qualification ID). This class identifies
78   // the configured system components such as CPU, WiFi adapter, etc.
79   std::string hardware_class_;
80 
81   base::WeakPtrFactory<ChromeOSMetricsProvider> weak_ptr_factory_;
82 
83   DISALLOW_COPY_AND_ASSIGN(ChromeOSMetricsProvider);
84 };
85 
86 #endif  // CHROME_BROWSER_METRICS_CHROMEOS_METRICS_PROVIDER_H_
87