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 #include "chrome/browser/prefs/pref_metrics_service.h" | 5 #include "chrome/browser/prefs/pref_metrics_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/prefs/pref_service_syncable.h" | 14 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 15 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
15 #include "chrome/browser/prefs/session_startup_pref.h" | 16 #include "chrome/browser/prefs/session_startup_pref.h" |
16 #include "chrome/browser/prefs/synced_pref_change_registrar.h" | 17 #include "chrome/browser/prefs/synced_pref_change_registrar.h" |
17 #include "chrome/browser/profiles/incognito_helpers.h" | 18 #include "chrome/browser/profiles/incognito_helpers.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
20 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 21 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
24 #include "components/rappor/rappor_utils.h" | 25 #include "components/rappor/rappor_utils.h" |
(...skipping 22 matching lines...) Expand all Loading... |
47 | 48 |
48 } // namespace | 49 } // namespace |
49 | 50 |
50 PrefMetricsService::PrefMetricsService(Profile* profile) | 51 PrefMetricsService::PrefMetricsService(Profile* profile) |
51 : profile_(profile), | 52 : profile_(profile), |
52 prefs_(profile_->GetPrefs()), | 53 prefs_(profile_->GetPrefs()), |
53 local_state_(g_browser_process->local_state()), | 54 local_state_(g_browser_process->local_state()), |
54 weak_factory_(this) { | 55 weak_factory_(this) { |
55 RecordLaunchPrefs(); | 56 RecordLaunchPrefs(); |
56 | 57 |
57 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 58 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile_); |
58 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs)); | 59 synced_pref_change_registrar_.reset(new SyncedPrefChangeRegistrar(prefs)); |
59 | 60 |
60 RegisterSyncedPrefObservers(); | 61 RegisterSyncedPrefObservers(); |
61 } | 62 } |
62 | 63 |
63 // For unit testing only. | 64 // For unit testing only. |
64 PrefMetricsService::PrefMetricsService(Profile* profile, | 65 PrefMetricsService::PrefMetricsService(Profile* profile, |
65 PrefService* local_state) | 66 PrefService* local_state) |
66 : profile_(profile), | 67 : profile_(profile), |
67 prefs_(profile->GetPrefs()), | 68 prefs_(profile->GetPrefs()), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 base::Bind(&PrefMetricsService::OnPrefChanged, | 170 base::Bind(&PrefMetricsService::OnPrefChanged, |
170 base::Unretained(this), | 171 base::Unretained(this), |
171 histogram_name_prefix, callback)); | 172 histogram_name_prefix, callback)); |
172 } | 173 } |
173 | 174 |
174 void PrefMetricsService::OnPrefChanged( | 175 void PrefMetricsService::OnPrefChanged( |
175 const std::string& histogram_name_prefix, | 176 const std::string& histogram_name_prefix, |
176 const LogHistogramValueCallback& callback, | 177 const LogHistogramValueCallback& callback, |
177 const std::string& path, | 178 const std::string& path, |
178 bool from_sync) { | 179 bool from_sync) { |
179 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 180 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile_); |
180 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); | 181 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); |
181 DCHECK(pref); | 182 DCHECK(pref); |
182 std::string source_name( | 183 std::string source_name( |
183 from_sync ? ".PulledFromSync" : ".PushedToSync"); | 184 from_sync ? ".PulledFromSync" : ".PushedToSync"); |
184 std::string histogram_name("Settings." + histogram_name_prefix + source_name); | 185 std::string histogram_name("Settings." + histogram_name_prefix + source_name); |
185 callback.Run(histogram_name, pref->GetValue()); | 186 callback.Run(histogram_name, pref->GetValue()); |
186 } | 187 } |
187 | 188 |
188 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, | 189 void PrefMetricsService::LogBooleanPrefChange(const std::string& histogram_name, |
189 const base::Value* value) { | 190 const base::Value* value) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 243 } |
243 | 244 |
244 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 245 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
245 return false; | 246 return false; |
246 } | 247 } |
247 | 248 |
248 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 249 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
249 content::BrowserContext* context) const { | 250 content::BrowserContext* context) const { |
250 return chrome::GetBrowserContextRedirectedInIncognito(context); | 251 return chrome::GetBrowserContextRedirectedInIncognito(context); |
251 } | 252 } |
OLD | NEW |