Chromium Code Reviews| 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/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 if (start_url.is_valid()) { | 155 if (start_url.is_valid()) { |
| 156 UMA_HISTOGRAM_ENUMERATION( | 156 UMA_HISTOGRAM_ENUMERATION( |
| 157 "Settings.StartupPageEngineTypes", | 157 "Settings.StartupPageEngineTypes", |
| 158 TemplateURLPrepopulateData::GetEngineType(start_url), | 158 TemplateURLPrepopulateData::GetEngineType(start_url), |
| 159 SEARCH_ENGINE_MAX); | 159 SEARCH_ENGINE_MAX); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 const ListValue* url_list = prefs_->GetList( | |
| 166 prefs::kURLsToRestoreOnStartupOld); | |
| 167 LogStartupURLsPrefChange("StartupURLsResetTime", url_list); | |
|
grt (UTC plus 2)
2013/09/27 13:24:45
to match when Log..() is called by the ChangeRegis
MAD
2013/09/27 14:54:20
I don't think I need that since this is not a sync
| |
| 168 | |
| 165 #if !defined(OS_ANDROID) | 169 #if !defined(OS_ANDROID) |
| 166 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); | 170 StartupTabs startup_tabs = PinnedTabCodec::ReadPinnedTabs(profile_); |
| 167 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", | 171 UMA_HISTOGRAM_CUSTOM_COUNTS("Settings.PinnedTabs", |
| 168 startup_tabs.size(), 1, 50, 20); | 172 startup_tabs.size(), 1, 50, 20); |
| 169 for (size_t i = 0; i < startup_tabs.size(); ++i) { | 173 for (size_t i = 0; i < startup_tabs.size(); ++i) { |
| 170 GURL start_url(startup_tabs.at(i).url); | 174 GURL start_url(startup_tabs.at(i).url); |
| 171 if (start_url.is_valid()) { | 175 if (start_url.is_valid()) { |
| 172 UMA_HISTOGRAM_ENUMERATION( | 176 UMA_HISTOGRAM_ENUMERATION( |
| 173 "Settings.PinnedTabEngineTypes", | 177 "Settings.PinnedTabEngineTypes", |
| 174 TemplateURLPrepopulateData::GetEngineType(start_url), | 178 TemplateURLPrepopulateData::GetEngineType(start_url), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 190 &PrefMetricsService::LogBooleanPrefChange, base::Unretained(this)); | 194 &PrefMetricsService::LogBooleanPrefChange, base::Unretained(this)); |
| 191 | 195 |
| 192 AddPrefObserver(prefs::kShowHomeButton, "ShowHomeButton", booleanHandler); | 196 AddPrefObserver(prefs::kShowHomeButton, "ShowHomeButton", booleanHandler); |
| 193 AddPrefObserver(prefs::kHomePageIsNewTabPage, "HomePageIsNewTabPage", | 197 AddPrefObserver(prefs::kHomePageIsNewTabPage, "HomePageIsNewTabPage", |
| 194 booleanHandler); | 198 booleanHandler); |
| 195 | 199 |
| 196 AddPrefObserver(prefs::kRestoreOnStartup, "StartupPageLoadSettings", | 200 AddPrefObserver(prefs::kRestoreOnStartup, "StartupPageLoadSettings", |
| 197 base::Bind(&PrefMetricsService::LogIntegerPrefChange, | 201 base::Bind(&PrefMetricsService::LogIntegerPrefChange, |
| 198 base::Unretained(this), | 202 base::Unretained(this), |
| 199 kSessionStartupPrefValueMax)); | 203 kSessionStartupPrefValueMax)); |
| 204 | |
| 205 AddPrefObserver(prefs::kURLsToRestoreOnStartupOld, "StartupURLsResetTime", | |
| 206 base::Bind(&PrefMetricsService::LogStartupURLsPrefChange, | |
| 207 base::Unretained(this))); | |
| 200 } | 208 } |
| 201 | 209 |
| 202 void PrefMetricsService::AddPrefObserver( | 210 void PrefMetricsService::AddPrefObserver( |
| 203 const std::string& path, | 211 const std::string& path, |
| 204 const std::string& histogram_name_prefix, | 212 const std::string& histogram_name_prefix, |
| 205 const LogHistogramValueCallback& callback) { | 213 const LogHistogramValueCallback& callback) { |
| 206 synced_pref_change_registrar_->Add(path.c_str(), | 214 synced_pref_change_registrar_->Add(path.c_str(), |
| 207 base::Bind(&PrefMetricsService::OnPrefChanged, | 215 base::Bind(&PrefMetricsService::OnPrefChanged, |
| 208 base::Unretained(this), | 216 base::Unretained(this), |
| 209 histogram_name_prefix, callback)); | 217 histogram_name_prefix, callback)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 return; | 249 return; |
| 242 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 250 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
| 243 histogram_name, | 251 histogram_name, |
| 244 1, | 252 1, |
| 245 boundary_value, | 253 boundary_value, |
| 246 boundary_value + 1, | 254 boundary_value + 1, |
| 247 base::HistogramBase::kUmaTargetedHistogramFlag); | 255 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 248 histogram->Add(integer_value); | 256 histogram->Add(integer_value); |
| 249 } | 257 } |
| 250 | 258 |
| 251 void PrefMetricsService::LogListPrefChange( | 259 void PrefMetricsService::LogStartupURLsPrefChange( |
| 252 const LogHistogramValueCallback& item_callback, | |
| 253 const std::string& histogram_name, | 260 const std::string& histogram_name, |
|
grt (UTC plus 2)
2013/09/27 13:24:45
why not use this on line 273 (it should be "Settin
MAD
2013/09/27 14:54:20
Because this is not a sync'able pref.
grt (UTC plus 2)
2013/09/27 15:50:21
This code is confusing as-is. There are two ways t
MAD
2013/09/27 17:35:39
OK, you convinced me, I'll work something up...
| |
| 254 const Value* value) { | 261 const Value* value) { |
| 255 const ListValue* items = NULL; | 262 const ListValue* items = NULL; |
| 256 if (!value->GetAsList(&items)) | 263 if (!value->GetAsList(&items) || !items->GetSize()) |
| 257 return; | 264 return; |
| 258 for (size_t i = 0; i < items->GetSize(); ++i) { | 265 |
| 259 const Value *item_value = NULL; | 266 // Empty migration time delta will identify initial migration. |
|
grt (UTC plus 2)
2013/09/27 13:24:45
do you want to log initial migration?
MAD
2013/09/27 14:54:20
It is logged with a value of 0.0.
grt (UTC plus 2)
2013/09/27 15:50:21
If I understand the use of histograms here, there
MAD
2013/09/27 17:35:39
D'Ho! Of course... I didn't realize that because a
| |
| 260 if (items->Get(i, &item_value)) | 267 base::TimeDelta migration_time; |
| 261 item_callback.Run(histogram_name, item_value); | 268 base::Time now(base::Time::Now()); |
| 269 if (prefs_->GetUserPrefValue(prefs::kRestoreStartupURLsMigrated)) { | |
| 270 migration_time = now - base::Time::FromDoubleT( | |
| 271 prefs_->GetDouble(prefs::kRestoreStartupURLsMigrated)); | |
| 262 } | 272 } |
| 273 HISTOGRAM_CUSTOM_TIMES("Settings.StartupURLsResetTime", | |
| 274 migration_time, | |
| 275 base::TimeDelta::FromMinutes(1), | |
| 276 base::TimeDelta::FromDays(7), | |
| 277 50); | |
| 278 prefs_->Set(prefs::kURLsToRestoreOnStartupOld, base::ListValue()); | |
| 279 prefs_->SetDouble(prefs::kRestoreStartupURLsMigrated, now.ToDoubleT()); | |
| 263 } | 280 } |
| 264 | 281 |
| 265 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { | 282 void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { |
| 266 device_id_ = device_id; | 283 device_id_ = device_id; |
| 267 // On Aura, this seems to be called twice. | 284 // On Aura, this seems to be called twice. |
| 268 if (!checked_tracked_prefs_) | 285 if (!checked_tracked_prefs_) |
| 269 CheckTrackedPreferences(); | 286 CheckTrackedPreferences(); |
| 270 } | 287 } |
| 271 | 288 |
| 272 // To detect changes to Preferences that happen outside of Chrome, we hash | 289 // To detect changes to Preferences that happen outside of Chrome, we hash |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } | 469 } |
| 453 | 470 |
| 454 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 471 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
| 455 return false; | 472 return false; |
| 456 } | 473 } |
| 457 | 474 |
| 458 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 475 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
| 459 content::BrowserContext* context) const { | 476 content::BrowserContext* context) const { |
| 460 return chrome::GetBrowserContextRedirectedInIncognito(context); | 477 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 461 } | 478 } |
| OLD | NEW |