Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/prefs/pref_metrics_service.h

Issue 21580002: Add histograms to track synced pref changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix dynamic histograms and test cleanup Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/prefs/pref_metrics_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
6 #define CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ 6 #define CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
7 7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "chrome/browser/prefs/synced_pref_change_registrar.h"
9 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
10 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
11 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 16 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
12 17
13 // PrefMetricsService is responsible for recording prefs-related UMA stats. 18 // PrefMetricsService is responsible for recording prefs-related UMA stats.
14 class PrefMetricsService : public BrowserContextKeyedService { 19 class PrefMetricsService : public BrowserContextKeyedService {
15 public: 20 public:
16 explicit PrefMetricsService(Profile* profile); 21 explicit PrefMetricsService(Profile* profile);
17 virtual ~PrefMetricsService(); 22 virtual ~PrefMetricsService();
18 23
19 class Factory : public BrowserContextKeyedServiceFactory { 24 class Factory : public BrowserContextKeyedServiceFactory {
20 public: 25 public:
21 static Factory* GetInstance(); 26 static Factory* GetInstance();
22 static PrefMetricsService* GetForProfile(Profile* profile); 27 static PrefMetricsService* GetForProfile(Profile* profile);
23 private: 28 private:
24 friend struct DefaultSingletonTraits<Factory>; 29 friend struct DefaultSingletonTraits<Factory>;
25 30
26 Factory(); 31 Factory();
27 virtual ~Factory(); 32 virtual ~Factory();
28 33
29 // BrowserContextKeyedServiceFactory implementation 34 // BrowserContextKeyedServiceFactory implementation
30 virtual BrowserContextKeyedService* BuildServiceInstanceFor( 35 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
31 content::BrowserContext* profile) const OVERRIDE; 36 content::BrowserContext* profile) const OVERRIDE;
32 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; 37 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
33 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; 38 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
34 virtual content::BrowserContext* GetBrowserContextToUse( 39 virtual content::BrowserContext* GetBrowserContextToUse(
35 content::BrowserContext* context) const OVERRIDE; 40 content::BrowserContext* context) const OVERRIDE;
36 }; 41 };
42
37 private: 43 private:
44 // Use a map to convert domains to their histogram identifiers. Ids are
45 // defined in tools/metrics/histograms/histograms.xml and (usually) also in
46 // chrome/browser/search_engines/prepopulated_engines.json.
47 typedef std::map<std::string, int> DomainIdMap;
48
49 // Function to log a Value to a histogram
50 typedef base::Callback<void(const std::string&, const Value*)>
51 LogHistogramValueCallback;
52
38 // Record prefs state on browser context creation. 53 // Record prefs state on browser context creation.
39 void RecordLaunchPrefs(); 54 void RecordLaunchPrefs();
40 55
56 // Register callbacks for synced pref changes.
57 void RegisterSyncedPrefObservers();
58
59 // Registers a histogram logging callback for a synced pref change.
60 void AddPrefObserver(const std::string& path,
61 const std::string& histogram_name_prefix,
62 const LogHistogramValueCallback& callback);
63
64 // Generic callback to observe a synced pref change.
65 void OnPrefChanged(const std::string& histogram_name_prefix,
66 const LogHistogramValueCallback& callback,
67 const std::string& path,
68 bool from_sync);
69
70 // Callback for a boolean pref change histogram.
71 void LogBooleanPrefChange(const std::string& histogram_name,
72 const Value* value);
73
74 // Callback for an integer pref change histogram.
75 void LogIntegerPrefChange(int boundary_value,
76 const std::string& histogram_name,
77 const Value* value);
78
79 // Callback for a list pref change. Each item in the list
80 // is logged using the given histogram callback.
81 void LogListPrefChange(const LogHistogramValueCallback& item_callback,
82 const std::string& histogram_name,
83 const Value* value);
84
41 Profile* profile_; 85 Profile* profile_;
86 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_;
42 }; 87 };
43 88
44 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ 89 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prefs/pref_metrics_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698