Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / prefs / pref_metrics_service.h
blobdb7fea3759da7bd9cd5d825c16c26cb475ce4b68
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/profiles/profile.h"
15 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/syncable_prefs/synced_pref_change_registrar.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 base::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<syncable_prefs::SyncedPrefChangeRegistrar>
87 synced_pref_change_registrar_;
89 base::WeakPtrFactory<PrefMetricsService> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(PrefMetricsService);
94 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_