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

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

Issue 23788010: Revert 221966 "Revert 221944 "Add UMA to report Preferences File..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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> 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 state.
48 static void RegisterPrefs(PrefRegistrySimple* registry);
49
43 private: 50 private:
44 // Use a map to convert domains to their histogram identifiers. Ids are 51 friend class PrefMetricsServiceTest;
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 52
49 // Function to log a Value to a histogram 53 // Function to log a Value to a histogram
50 typedef base::Callback<void(const std::string&, const Value*)> 54 typedef base::Callback<void(const std::string&, const Value*)>
51 LogHistogramValueCallback; 55 LogHistogramValueCallback;
52 56
57 // For unit testing only.
58 PrefMetricsService(Profile* profile,
59 PrefService* local_settings,
60 const std::string& device_id,
61 const char** tracked_pref_paths,
62 int tracked_pref_path_count);
63
53 // Record prefs state on browser context creation. 64 // Record prefs state on browser context creation.
54 void RecordLaunchPrefs(); 65 void RecordLaunchPrefs();
55 66
56 // Register callbacks for synced pref changes. 67 // Register callbacks for synced pref changes.
57 void RegisterSyncedPrefObservers(); 68 void RegisterSyncedPrefObservers();
58 69
59 // Registers a histogram logging callback for a synced pref change. 70 // Registers a histogram logging callback for a synced pref change.
60 void AddPrefObserver(const std::string& path, 71 void AddPrefObserver(const std::string& path,
61 const std::string& histogram_name_prefix, 72 const std::string& histogram_name_prefix,
62 const LogHistogramValueCallback& callback); 73 const LogHistogramValueCallback& callback);
(...skipping 12 matching lines...) Expand all
75 void LogIntegerPrefChange(int boundary_value, 86 void LogIntegerPrefChange(int boundary_value,
76 const std::string& histogram_name, 87 const std::string& histogram_name,
77 const Value* value); 88 const Value* value);
78 89
79 // Callback for a list pref change. Each item in the list 90 // Callback for a list pref change. Each item in the list
80 // is logged using the given histogram callback. 91 // is logged using the given histogram callback.
81 void LogListPrefChange(const LogHistogramValueCallback& item_callback, 92 void LogListPrefChange(const LogHistogramValueCallback& item_callback,
82 const std::string& histogram_name, 93 const std::string& histogram_name,
83 const Value* value); 94 const Value* value);
84 95
96 // Callback to receive a unique device_id.
97 void GetDeviceIdCallback(const std::string& device_id);
98
99 // Checks the tracked preferences against their last known values and reports
100 // any discrepancies. This must be called after |device_id| has been set.
101 void CheckTrackedPreferences();
102
103 // Updates the hash of the tracked preference in local state. This must be
104 // called after |device_id| has been set.
105 void UpdateTrackedPreference(const char* path);
106
107 // Removes the tracked preference from local state. Returns 'true' iff. the
108 // value was present.
109 bool RemoveTrackedPreference(const char* path);
110
111 // Gets the path to the preference value hash in local state.
112 std::string GetHashedPrefPath(const char* path);
113
114 // Computes an MD5 hash for the given preference value.
115 std::string GetHashedPrefValue(const char* path, const base::Value* value);
116
117 void InitializePrefObservers();
118
85 Profile* profile_; 119 Profile* profile_;
120 PrefService* prefs_;
121 PrefService* local_state_;
122 std::string profile_name_;
123 std::string pref_hash_seed_;
124 std::string device_id_;
125 const char** tracked_pref_paths_;
126 const int tracked_pref_path_count_;
127 bool checked_tracked_prefs_;
128
129 PrefChangeRegistrar pref_registrar_;
86 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_; 130 scoped_ptr<SyncedPrefChangeRegistrar> synced_pref_change_registrar_;
131
132 base::WeakPtrFactory<PrefMetricsService> weak_factory_;
133
134 DISALLOW_COPY_AND_ASSIGN(PrefMetricsService);
87 }; 135 };
88 136
89 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_ 137 #endif // CHROME_BROWSER_PREFS_PREF_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698