Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / prefs / pref_metrics_service.h
blobf7f7ff447b18ad386f1ba9e4cb6dd2ce8ef300c5
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
6 #define CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/singleton.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/prefs/synced_pref_change_registrar.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
17 #include "components/keyed_service/core/keyed_service.h"
19 class PrefRegistrySimple;
21 // PrefMetricsService is responsible for recording prefs-related UMA stats.
22 class PrefMetricsService : public KeyedService {
23 public:
24 explicit PrefMetricsService(Profile* profile);
25 ~PrefMetricsService() override;
27 class Factory : public BrowserContextKeyedServiceFactory {
28 public:
29 static Factory* GetInstance();
30 static PrefMetricsService* GetForProfile(Profile* profile);
31 private:
32 friend struct DefaultSingletonTraits<Factory>;
34 Factory();
35 ~Factory() override;
37 // BrowserContextKeyedServiceFactory implementation
38 KeyedService* BuildServiceInstanceFor(
39 content::BrowserContext* profile) const override;
40 bool ServiceIsCreatedWithBrowserContext() const override;
41 bool ServiceIsNULLWhileTesting() const override;
42 content::BrowserContext* GetBrowserContextToUse(
43 content::BrowserContext* context) const override;
46 private:
47 friend class PrefMetricsServiceTest;
49 // Function to log a Value to a histogram
50 typedef base::Callback<void(const std::string&, const base::Value*)>
51 LogHistogramValueCallback;
53 // For unit testing only.
54 PrefMetricsService(Profile* profile, PrefService* local_settings);
56 // Record prefs state on browser context creation.
57 void RecordLaunchPrefs();
59 // Register callbacks for synced pref changes.
60 void RegisterSyncedPrefObservers();
62 // Registers a histogram logging callback for a synced pref change.
63 void AddPrefObserver(const std::string& path,
64 const std::string& histogram_name_prefix,
65 const LogHistogramValueCallback& callback);
67 // Generic callback to observe a synced pref change.
68 void OnPrefChanged(const std::string& histogram_name_prefix,
69 const LogHistogramValueCallback& callback,
70 const std::string& path,
71 bool from_sync);
73 // Callback for a boolean pref change histogram.
74 void LogBooleanPrefChange(const std::string& histogram_name,
75 const base::Value* value);
77 // Callback for an integer pref change histogram.
78 void LogIntegerPrefChange(int boundary_value,
79 const std::string& histogram_name,
80 const base::Value* value);
82 Profile* profile_;
83 PrefService* prefs_;
84 PrefService* local_state_;
86 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_;
88 base::WeakPtrFactory<PrefMetricsService> weak_factory_;
90 DISALLOW_COPY_AND_ASSIGN(PrefMetricsService);
93 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_