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> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/prefs/pref_change_registrar.h" | |
13 #include "chrome/browser/prefs/synced_pref_change_registrar.h" | 15 #include "chrome/browser/prefs/synced_pref_change_registrar.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
16 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" |
17 | 19 |
20 class PrefRegistrySimple; | |
21 | |
18 // PrefMetricsService is responsible for recording prefs-related UMA stats. | 22 // PrefMetricsService is responsible for recording prefs-related UMA stats. |
19 class PrefMetricsService : public BrowserContextKeyedService { | 23 class PrefMetricsService : public BrowserContextKeyedService { |
20 public: | 24 public: |
21 explicit PrefMetricsService(Profile* profile); | 25 explicit PrefMetricsService(Profile* profile); |
22 virtual ~PrefMetricsService(); | 26 virtual ~PrefMetricsService(); |
23 | 27 |
24 class Factory : public BrowserContextKeyedServiceFactory { | 28 class Factory : public BrowserContextKeyedServiceFactory { |
25 public: | 29 public: |
26 static Factory* GetInstance(); | 30 static Factory* GetInstance(); |
27 static PrefMetricsService* GetForProfile(Profile* profile); | 31 static PrefMetricsService* GetForProfile(Profile* profile); |
28 private: | 32 private: |
29 friend struct DefaultSingletonTraits<Factory>; | 33 friend struct DefaultSingletonTraits<Factory>; |
30 | 34 |
31 Factory(); | 35 Factory(); |
32 virtual ~Factory(); | 36 virtual ~Factory(); |
33 | 37 |
34 // BrowserContextKeyedServiceFactory implementation | 38 // BrowserContextKeyedServiceFactory implementation |
35 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 39 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
36 content::BrowserContext* profile) const OVERRIDE; | 40 content::BrowserContext* profile) const OVERRIDE; |
37 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; | 41 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; |
38 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 42 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
39 virtual content::BrowserContext* GetBrowserContextToUse( | 43 virtual content::BrowserContext* GetBrowserContextToUse( |
40 content::BrowserContext* context) const OVERRIDE; | 44 content::BrowserContext* context) const OVERRIDE; |
41 }; | 45 }; |
42 | 46 |
47 // Registers preferences in local settings. | |
Mattias Nissler (ping if slow)
2013/08/15 10:14:51
nit: s/local settings/local state/ for consistency
bbudge
2013/08/15 17:33:49
Done.
| |
48 static void RegisterPrefs(PrefRegistrySimple* registry); | |
49 | |
43 private: | 50 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 | 51 // Function to log a Value to a histogram |
50 typedef base::Callback<void(const std::string&, const Value*)> | 52 typedef base::Callback<void(const std::string&, const Value*)> |
51 LogHistogramValueCallback; | 53 LogHistogramValueCallback; |
52 | 54 |
53 // Record prefs state on browser context creation. | 55 // Record prefs state on browser context creation. |
54 void RecordLaunchPrefs(); | 56 void RecordLaunchPrefs(); |
55 | 57 |
56 // Register callbacks for synced pref changes. | 58 // Register callbacks for synced pref changes. |
57 void RegisterSyncedPrefObservers(); | 59 void RegisterSyncedPrefObservers(); |
58 | 60 |
(...skipping 16 matching lines...) Expand all Loading... | |
75 void LogIntegerPrefChange(int boundary_value, | 77 void LogIntegerPrefChange(int boundary_value, |
76 const std::string& histogram_name, | 78 const std::string& histogram_name, |
77 const Value* value); | 79 const Value* value); |
78 | 80 |
79 // Callback for a list pref change. Each item in the list | 81 // Callback for a list pref change. Each item in the list |
80 // is logged using the given histogram callback. | 82 // is logged using the given histogram callback. |
81 void LogListPrefChange(const LogHistogramValueCallback& item_callback, | 83 void LogListPrefChange(const LogHistogramValueCallback& item_callback, |
82 const std::string& histogram_name, | 84 const std::string& histogram_name, |
83 const Value* value); | 85 const Value* value); |
84 | 86 |
87 // Callback to receive a unique device_id. This is used to make it harder to | |
88 // spoof the preference value checks. | |
89 void GetDeviceIdCallback(const std::string& device_id); | |
90 | |
91 // Checks the tracked preferences against their last known values and reports | |
92 // any discrepancies. This must be called after |device_id| has been set by | |
93 // GetDeviceIdCallback. | |
94 void CheckTrackedPreferences(); | |
95 | |
96 // Updates the hash of the tracked preference in local settings. This must be | |
Mattias Nissler (ping if slow)
2013/08/15 10:14:51
local state
bbudge
2013/08/15 17:33:49
Done.
| |
97 // called after |device_id| has been set by GetDeviceIdCallback. | |
98 void UpdateTrackedPreference(const char* path); | |
99 | |
100 // Removes the tracked preference from local settings. Returns 'true' iff. the | |
Mattias Nissler (ping if slow)
2013/08/15 10:14:51
local state
bbudge
2013/08/15 17:33:49
Done.
| |
101 // value was present. | |
102 bool RemoveTrackedPreference(const char* path); | |
103 | |
104 // Gets the path to the preference value hash in local settings. | |
Mattias Nissler (ping if slow)
2013/08/15 10:14:51
local state
bbudge
2013/08/15 17:33:49
Done.
| |
105 std::string GetHashedPrefPath(const char* path); | |
106 | |
107 // Computes an MD5 hash for the given preference value. Salts the hash with | |
108 // the pref name and the device id to make it harder to spoof. | |
109 std::string GetHashedPrefValue(const char* path, const base::Value* value); | |
110 | |
111 base::WeakPtrFactory<PrefMetricsService> weak_factory_; | |
112 | |
85 Profile* profile_; | 113 Profile* profile_; |
114 std::string device_id_; | |
115 PrefChangeRegistrar pref_registrar_; | |
86 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_; | 116 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_; |
87 }; | 117 }; |
88 | 118 |
89 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ | 119 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ |
OLD | NEW |