Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
| 6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
| 7 // | 7 // |
| 8 // OVERVIEW | 8 // OVERVIEW |
| 9 // | 9 // |
| 10 // A MetricsService instance is typically created at application startup. It is | 10 // A MetricsService instance is typically created at application startup. It is |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1113 void MetricsService::ReceivedProfilerData( | 1113 void MetricsService::ReceivedProfilerData( |
| 1114 const tracked_objects::ProcessDataSnapshot& process_data, | 1114 const tracked_objects::ProcessDataSnapshot& process_data, |
| 1115 int process_type) { | 1115 int process_type) { |
| 1116 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1116 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
| 1117 | 1117 |
| 1118 // Upon the first callback, create the initial log so that we can immediately | 1118 // Upon the first callback, create the initial log so that we can immediately |
| 1119 // save the profiler data. | 1119 // save the profiler data. |
| 1120 if (!initial_metrics_log_.get()) { | 1120 if (!initial_metrics_log_.get()) { |
| 1121 initial_metrics_log_.reset( | 1121 initial_metrics_log_.reset( |
| 1122 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); | 1122 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); |
| 1123 NotifyOnNewMetricsLog(); | |
| 1123 } | 1124 } |
| 1124 | 1125 |
| 1125 initial_metrics_log_->RecordProfilerData(process_data, process_type); | 1126 initial_metrics_log_->RecordProfilerData(process_data, process_type); |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 void MetricsService::FinishedReceivingProfilerData() { | 1129 void MetricsService::FinishedReceivingProfilerData() { |
| 1129 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1130 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
| 1130 state_ = INIT_TASK_DONE; | 1131 state_ = INIT_TASK_DONE; |
| 1131 scheduler_->InitTaskComplete(); | 1132 scheduler_->InitTaskComplete(); |
| 1132 } | 1133 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 | 1200 |
| 1200 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | 1201 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |
| 1201 low_entropy_source_ = GenerateLowEntropySource(); | 1202 low_entropy_source_ = GenerateLowEntropySource(); |
| 1202 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); | 1203 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); |
| 1203 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); | 1204 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); |
| 1204 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); | 1205 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); |
| 1205 | 1206 |
| 1206 return low_entropy_source_; | 1207 return low_entropy_source_; |
| 1207 } | 1208 } |
| 1208 | 1209 |
| 1210 void MetricsService::AddMetricsLogObserver(MetricsLogObserver* observer) { | |
| 1211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1212 metrics_log_observers_.AddObserver(observer); | |
| 1213 } | |
| 1214 | |
| 1215 void MetricsService::RemoveMetricsLogObserver(MetricsLogObserver* observer) { | |
| 1216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1217 metrics_log_observers_.RemoveObserver(observer); | |
|
bengr
2014/05/06 17:14:39
Are the observers guaranteed to outlive the Metric
bolian
2014/05/06 18:00:08
For the current usage, Yes.
If not in the future,
| |
| 1218 } | |
| 1219 | |
| 1220 void MetricsService::NotifyOnNewMetricsLog() { | |
| 1221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1222 FOR_EACH_OBSERVER( | |
| 1223 MetricsLogObserver, metrics_log_observers_, OnNewMetricsLog()); | |
| 1224 } | |
| 1225 | |
| 1209 // static | 1226 // static |
| 1210 std::string MetricsService::GenerateClientID() { | 1227 std::string MetricsService::GenerateClientID() { |
| 1211 return base::GenerateGUID(); | 1228 return base::GenerateGUID(); |
| 1212 } | 1229 } |
| 1213 | 1230 |
| 1214 //------------------------------------------------------------------------------ | 1231 //------------------------------------------------------------------------------ |
| 1215 // State save methods | 1232 // State save methods |
| 1216 | 1233 |
| 1217 void MetricsService::ScheduleNextStateSave() { | 1234 void MetricsService::ScheduleNextStateSave() { |
| 1218 state_saver_factory_.InvalidateWeakPtrs(); | 1235 state_saver_factory_.InvalidateWeakPtrs(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1238 | 1255 |
| 1239 | 1256 |
| 1240 //------------------------------------------------------------------------------ | 1257 //------------------------------------------------------------------------------ |
| 1241 // Recording control methods | 1258 // Recording control methods |
| 1242 | 1259 |
| 1243 void MetricsService::OpenNewLog() { | 1260 void MetricsService::OpenNewLog() { |
| 1244 DCHECK(!log_manager_.current_log()); | 1261 DCHECK(!log_manager_.current_log()); |
| 1245 | 1262 |
| 1246 log_manager_.BeginLoggingWithLog( | 1263 log_manager_.BeginLoggingWithLog( |
| 1247 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); | 1264 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); |
| 1265 NotifyOnNewMetricsLog(); | |
| 1248 if (state_ == INITIALIZED) { | 1266 if (state_ == INITIALIZED) { |
| 1249 // We only need to schedule that run once. | 1267 // We only need to schedule that run once. |
| 1250 state_ = INIT_TASK_SCHEDULED; | 1268 state_ = INIT_TASK_SCHEDULED; |
| 1251 | 1269 |
| 1252 // Schedules a task on the file thread for execution of slower | 1270 // Schedules a task on the file thread for execution of slower |
| 1253 // initialization steps (such as plugin list generation) necessary | 1271 // initialization steps (such as plugin list generation) necessary |
| 1254 // for sending the initial log. This avoids blocking the main UI | 1272 // for sending the initial log. This avoids blocking the main UI |
| 1255 // thread. | 1273 // thread. |
| 1256 BrowserThread::PostDelayedTask( | 1274 BrowserThread::PostDelayedTask( |
| 1257 BrowserThread::FILE, | 1275 BrowserThread::FILE, |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 } | 1553 } |
| 1536 | 1554 |
| 1537 void MetricsService::PrepareInitialStabilityLog() { | 1555 void MetricsService::PrepareInitialStabilityLog() { |
| 1538 DCHECK_EQ(INITIALIZED, state_); | 1556 DCHECK_EQ(INITIALIZED, state_); |
| 1539 PrefService* pref = g_browser_process->local_state(); | 1557 PrefService* pref = g_browser_process->local_state(); |
| 1540 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); | 1558 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); |
| 1541 | 1559 |
| 1542 scoped_ptr<MetricsLog> initial_stability_log( | 1560 scoped_ptr<MetricsLog> initial_stability_log( |
| 1543 new MetricsLog(client_id_, session_id_, | 1561 new MetricsLog(client_id_, session_id_, |
| 1544 MetricsLog::INITIAL_STABILITY_LOG)); | 1562 MetricsLog::INITIAL_STABILITY_LOG)); |
| 1563 NotifyOnNewMetricsLog(); | |
| 1545 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 1564 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
| 1546 return; | 1565 return; |
| 1547 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), | 1566 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), |
| 1548 base::TimeDelta()); | 1567 base::TimeDelta()); |
| 1549 log_manager_.LoadPersistedUnsentLogs(); | 1568 log_manager_.LoadPersistedUnsentLogs(); |
| 1550 | 1569 |
| 1551 log_manager_.PauseCurrentLog(); | 1570 log_manager_.PauseCurrentLog(); |
| 1552 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); | 1571 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); |
| 1553 #if defined(OS_ANDROID) | 1572 #if defined(OS_ANDROID) |
| 1554 ConvertAndroidStabilityPrefsToHistograms(pref); | 1573 ConvertAndroidStabilityPrefsToHistograms(pref); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 // Android has its own settings for metrics / crash uploading. | 2094 // Android has its own settings for metrics / crash uploading. |
| 2076 const PrefService* prefs = g_browser_process->local_state(); | 2095 const PrefService* prefs = g_browser_process->local_state(); |
| 2077 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 2096 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
| 2078 #else | 2097 #else |
| 2079 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 2098 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
| 2080 #endif | 2099 #endif |
| 2081 #else | 2100 #else |
| 2082 return false; | 2101 return false; |
| 2083 #endif | 2102 #endif |
| 2084 } | 2103 } |
| 2104 | |
| 2105 void MetricsServiceHelper::AddMetricsLogObserver( | |
| 2106 MetricsLogObserver* observer) { | |
| 2107 MetricsService* metrics_service = g_browser_process->metrics_service(); | |
| 2108 if (metrics_service != NULL) { | |
|
bengr
2014/05/06 17:14:39
When would this be null?
bolian
2014/05/06 18:00:08
Just as a safety check before dereferring it. In t
| |
| 2109 metrics_service->AddMetricsLogObserver(observer); | |
| 2110 } | |
| 2111 } | |
| 2112 | |
| 2113 void MetricsServiceHelper::RemoveMetricsLogObserver( | |
| 2114 MetricsLogObserver* observer) { | |
| 2115 MetricsService* metrics_service = g_browser_process->metrics_service(); | |
| 2116 if (metrics_service != NULL) { | |
| 2117 metrics_service->RemoveMetricsLogObserver(observer); | |
| 2118 } | |
| 2119 } | |
| OLD | NEW |