OLD | NEW |
---|---|
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 ValueHistogramCallback; | |
battre
2013/08/06 15:54:39
nit: LogHistogramValueCallback?
Ken Rockot(use gerrit already)
2013/08/06 20:18:32
Done.
| |
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_base, | |
62 const ValueHistogramCallback& callback); | |
63 | |
64 // Builds a map that associates domain name strings with histogram enum | |
65 // values, for prepopulated DSEs and select non-prepopulated ones. | |
66 void BuildDomainIdMap(); | |
67 | |
68 // Add a domain/id pair to the map. | |
69 void AddToDomainIdMap(const std::string& domain, int domain_id); | |
70 | |
71 // Generic callback to observe a synced pref change. | |
72 void OnPrefChanged(const std::string& histogram_base, | |
73 const ValueHistogramCallback& callback, | |
74 const std::string& path, | |
75 bool from_sync); | |
76 | |
77 // Callback for a boolean pref change histogram. | |
78 void LogBooleanPrefChange(const std::string& histogram_name, | |
79 const Value* value); | |
80 | |
81 // Callback for an integer pref change histogram. | |
82 void LogIntegerPrefChange(int boundary_value, | |
83 const std::string& histogram_name, | |
84 const Value* value); | |
85 | |
86 // Callback for a URL pref change histogram. | |
87 void LogUrlPrefChange(const std::string& histogram_name, const Value* value); | |
88 | |
89 // Callback for a list pref change. Each item in the list | |
90 // is logged using the given histogram callback. | |
91 void LogListPrefChange(const ValueHistogramCallback& item_callback, | |
92 const std::string& histogram_name, | |
93 const Value* value); | |
94 | |
95 // Maps a host name to a histogram enum value. The enum value '0' represents | |
96 // 'Unknown', i.e. an unrecognized host. | |
97 int MapHostToId(const std::string& host) const; | |
98 | |
41 Profile* profile_; | 99 Profile* profile_; |
100 DomainIdMap domain_id_map_; | |
101 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_; | |
42 }; | 102 }; |
43 | 103 |
44 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ | 104 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ |
OLD | NEW |