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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } | 753 } |
754 | 754 |
755 std::string MetricsService::GenerateClientID() { | 755 std::string MetricsService::GenerateClientID() { |
756 return guid::GenerateGUID(); | 756 return guid::GenerateGUID(); |
757 } | 757 } |
758 | 758 |
759 //------------------------------------------------------------------------------ | 759 //------------------------------------------------------------------------------ |
760 // State save methods | 760 // State save methods |
761 | 761 |
762 void MetricsService::ScheduleNextStateSave() { | 762 void MetricsService::ScheduleNextStateSave() { |
763 state_saver_factory_.RevokeAll(); | 763 state_saver_factory_.InvalidateWeakPtrs(); |
764 | 764 |
765 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 765 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
766 state_saver_factory_.NewRunnableMethod(&MetricsService::SaveLocalState), | 766 base::Bind(&MetricsService::SaveLocalState, |
| 767 state_saver_factory_.GetWeakPtr()), |
767 kSaveStateInterval * 1000); | 768 kSaveStateInterval * 1000); |
768 } | 769 } |
769 | 770 |
770 void MetricsService::SaveLocalState() { | 771 void MetricsService::SaveLocalState() { |
771 PrefService* pref = g_browser_process->local_state(); | 772 PrefService* pref = g_browser_process->local_state(); |
772 if (!pref) { | 773 if (!pref) { |
773 NOTREACHED(); | 774 NOTREACHED(); |
774 return; | 775 return; |
775 } | 776 } |
776 | 777 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 // Redundant hack to write pref ASAP. | 1298 // Redundant hack to write pref ASAP. |
1298 PrefService* pref = g_browser_process->local_state(); | 1299 PrefService* pref = g_browser_process->local_state(); |
1299 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 1300 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); |
1300 pref->SavePersistentPrefs(); | 1301 pref->SavePersistentPrefs(); |
1301 // Hack: TBD: Remove this wait. | 1302 // Hack: TBD: Remove this wait. |
1302 // 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 |
1303 // 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 |
1304 // completed. | 1305 // completed. |
1305 base::WaitableEvent done_writing(false, false); | 1306 base::WaitableEvent done_writing(false, false); |
1306 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 1307 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
1307 NewRunnableFunction(Signal, &done_writing)); | 1308 base::Bind(Signal, &done_writing)); |
1308 done_writing.TimedWait(base::TimeDelta::FromHours(1)); | 1309 done_writing.TimedWait(base::TimeDelta::FromHours(1)); |
1309 | 1310 |
1310 // 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 |
1311 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1312 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1312 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1313 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1313 | 1314 |
1314 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); | 1315 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
1315 } | 1316 } |
1316 | 1317 |
1317 #if defined(OS_CHROMEOS) | 1318 #if defined(OS_CHROMEOS) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 if (local_state) { | 1548 if (local_state) { |
1548 const PrefService::Preference* uma_pref = | 1549 const PrefService::Preference* uma_pref = |
1549 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1550 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1550 if (uma_pref) { | 1551 if (uma_pref) { |
1551 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1552 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1552 DCHECK(success); | 1553 DCHECK(success); |
1553 } | 1554 } |
1554 } | 1555 } |
1555 return result; | 1556 return result; |
1556 } | 1557 } |
OLD | NEW |