| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 10 // A MetricsService instance is typically created at application startup. It |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 } | 770 } |
| 771 | 771 |
| 772 void MetricsService::SaveLocalState() { | 772 void MetricsService::SaveLocalState() { |
| 773 PrefService* pref = g_browser_process->local_state(); | 773 PrefService* pref = g_browser_process->local_state(); |
| 774 if (!pref) { | 774 if (!pref) { |
| 775 NOTREACHED(); | 775 NOTREACHED(); |
| 776 return; | 776 return; |
| 777 } | 777 } |
| 778 | 778 |
| 779 RecordCurrentState(pref); | 779 RecordCurrentState(pref); |
| 780 pref->ScheduleSavePersistentPrefs(); | |
| 781 | 780 |
| 782 // TODO(jar): Does this run down the batteries???? | 781 // TODO(jar): Does this run down the batteries???? |
| 783 ScheduleNextStateSave(); | 782 ScheduleNextStateSave(); |
| 784 } | 783 } |
| 785 | 784 |
| 786 | 785 |
| 787 //------------------------------------------------------------------------------ | 786 //------------------------------------------------------------------------------ |
| 788 // Recording control methods | 787 // Recording control methods |
| 789 | 788 |
| 790 void MetricsService::StartRecording() { | 789 void MetricsService::StartRecording() { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 | 1124 |
| 1126 case SENDING_CURRENT_LOGS: | 1125 case SENDING_CURRENT_LOGS: |
| 1127 break; | 1126 break; |
| 1128 | 1127 |
| 1129 default: | 1128 default: |
| 1130 NOTREACHED(); | 1129 NOTREACHED(); |
| 1131 break; | 1130 break; |
| 1132 } | 1131 } |
| 1133 | 1132 |
| 1134 log_manager_.DiscardStagedLog(); | 1133 log_manager_.DiscardStagedLog(); |
| 1135 // Since we sent a log, make sure our in-memory state is recorded to disk. | |
| 1136 PrefService* local_state = g_browser_process->local_state(); | |
| 1137 DCHECK(local_state); | |
| 1138 if (local_state) | |
| 1139 local_state->ScheduleSavePersistentPrefs(); | |
| 1140 | 1134 |
| 1141 if (log_manager_.has_unsent_logs()) | 1135 if (log_manager_.has_unsent_logs()) |
| 1142 DCHECK(state_ < SENDING_CURRENT_LOGS); | 1136 DCHECK(state_ < SENDING_CURRENT_LOGS); |
| 1143 } | 1137 } |
| 1144 | 1138 |
| 1145 // Error 400 indicates a problem with the log, not with the server, so | 1139 // Error 400 indicates a problem with the log, not with the server, so |
| 1146 // don't consider that a sign that the server is in trouble. | 1140 // don't consider that a sign that the server is in trouble. |
| 1147 bool server_is_healthy = upload_succeeded || source->GetResponseCode() == 400; | 1141 bool server_is_healthy = upload_succeeded || source->GetResponseCode() == 400; |
| 1148 | 1142 |
| 1149 scheduler_->UploadFinished(server_is_healthy, | 1143 scheduler_->UploadFinished(server_is_healthy, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 | 1291 |
| 1298 // For use in hack in LogCleanShutdown. | 1292 // For use in hack in LogCleanShutdown. |
| 1299 static void Signal(base::WaitableEvent* event) { | 1293 static void Signal(base::WaitableEvent* event) { |
| 1300 event->Signal(); | 1294 event->Signal(); |
| 1301 } | 1295 } |
| 1302 | 1296 |
| 1303 void MetricsService::LogCleanShutdown() { | 1297 void MetricsService::LogCleanShutdown() { |
| 1304 // Redundant hack to write pref ASAP. | 1298 // Redundant hack to write pref ASAP. |
| 1305 PrefService* pref = g_browser_process->local_state(); | 1299 PrefService* pref = g_browser_process->local_state(); |
| 1306 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 1300 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); |
| 1307 pref->SavePersistentPrefs(); | 1301 pref->CommitPendingWrite(); |
| 1308 // Hack: TBD: Remove this wait. | 1302 // Hack: TBD: Remove this wait. |
| 1309 // We are so concerned that the pref gets written, we are now willing to stall | 1303 // We are so concerned that the pref gets written, we are now willing to stall |
| 1310 // the UI thread until we get assurance that a pref-writing task has | 1304 // the UI thread until we get assurance that a pref-writing task has |
| 1311 // completed. | 1305 // completed. |
| 1312 base::WaitableEvent done_writing(false, false); | 1306 base::WaitableEvent done_writing(false, false); |
| 1313 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 1307 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1314 base::Bind(Signal, &done_writing)); | 1308 base::Bind(Signal, &done_writing)); |
| 1315 done_writing.TimedWait(base::TimeDelta::FromHours(1)); | 1309 done_writing.TimedWait(base::TimeDelta::FromHours(1)); |
| 1316 | 1310 |
| 1317 // Redundant setting to assure that we always reset this value at shutdown | 1311 // Redundant setting to assure that we always reset this value at shutdown |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 if (local_state) { | 1548 if (local_state) { |
| 1555 const PrefService::Preference* uma_pref = | 1549 const PrefService::Preference* uma_pref = |
| 1556 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1550 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1557 if (uma_pref) { | 1551 if (uma_pref) { |
| 1558 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1552 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1559 DCHECK(success); | 1553 DCHECK(success); |
| 1560 } | 1554 } |
| 1561 } | 1555 } |
| 1562 return result; | 1556 return result; |
| 1563 } | 1557 } |
| OLD | NEW |