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 | 10 // A MetricsService instance is typically created at application startup. It |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // SENDING_OLD_LOGS, // Sending unsent logs from previous session. | 82 // SENDING_OLD_LOGS, // Sending unsent logs from previous session. |
83 // SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue. | 83 // SENDING_CURRENT_LOGS, // Sending standard current logs as they accrue. |
84 // | 84 // |
85 // In more detail, we have: | 85 // In more detail, we have: |
86 // | 86 // |
87 // INITIALIZED, // Constructor was called. | 87 // INITIALIZED, // Constructor was called. |
88 // The MS has been constructed, but has taken no actions to compose the | 88 // The MS has been constructed, but has taken no actions to compose the |
89 // initial log. | 89 // initial log. |
90 // | 90 // |
91 // INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. | 91 // INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. |
92 // Typically about 30 seconds after startup, a task is sent to a second thread | 92 // Typically about 30 seconds after startup, a task is posted to perform |
93 // (the file thread) to perform deferred (lower priority and slower) | 93 // deferred (lower priority and slower) initialization steps such as getting the |
94 // initialization steps such as getting the list of plugins. That task will | 94 // list of plugins. That task will (when complete) make an async callback (via |
95 // (when complete) make an async callback (via a Task) to indicate the | 95 // a Task) to indicate the completion. |
96 // completion. | |
97 // | 96 // |
98 // INIT_TASK_DONE, // Waiting for timer to send initial log. | 97 // INIT_TASK_DONE, // Waiting for timer to send initial log. |
99 // The callback has arrived, and it is now possible for an initial log to be | 98 // The callback has arrived, and it is now possible for an initial log to be |
100 // created. This callback typically arrives back less than one second after | 99 // created. This callback typically arrives back less than one second after |
101 // the deferred init task is dispatched. | 100 // the deferred init task is dispatched. |
102 // | 101 // |
103 // INITIAL_LOG_READY, // Initial log generated, and waiting for reply. | 102 // INITIAL_LOG_READY, // Initial log generated, and waiting for reply. |
104 // This state is entered only after an initial log has been composed, and | 103 // This state is entered only after an initial log has been composed, and |
105 // prepared for transmission. It is also the case that any previously unsent | 104 // prepared for transmission. It is also the case that any previously unsent |
106 // logs have been loaded into instance variables for possible transmission. | 105 // logs have been loaded into instance variables for possible transmission. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 const size_t kUploadLogAvoidRetransmitSize = 50000; | 239 const size_t kUploadLogAvoidRetransmitSize = 50000; |
241 | 240 |
242 // Interval, in minutes, between state saves. | 241 // Interval, in minutes, between state saves. |
243 const int kSaveStateIntervalMinutes = 5; | 242 const int kSaveStateIntervalMinutes = 5; |
244 | 243 |
245 // Used to indicate that the response code is currently not set at all -- | 244 // Used to indicate that the response code is currently not set at all -- |
246 // RESPONSE_CODE_INVALID can sometimes be returned in response to a request if, | 245 // RESPONSE_CODE_INVALID can sometimes be returned in response to a request if, |
247 // e.g., the server is down. | 246 // e.g., the server is down. |
248 const int kNoResponseCode = content::URLFetcher::RESPONSE_CODE_INVALID - 1; | 247 const int kNoResponseCode = content::URLFetcher::RESPONSE_CODE_INVALID - 1; |
249 | 248 |
| 249 // Used to indicate that a report was generated before the hardware_class |
| 250 // property was available from the StatisticsProvider. This is used to identify |
| 251 // faulty reports from Chrome OS clients. |
| 252 const char kHardwareClassNotReady[] = "(not ready)"; |
| 253 |
250 } | 254 } |
251 | 255 |
252 // static | 256 // static |
253 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = | 257 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = |
254 MetricsService::CLEANLY_SHUTDOWN; | 258 MetricsService::CLEANLY_SHUTDOWN; |
255 | 259 |
256 // This is used to quickly log stats from child process related notifications in | 260 // This is used to quickly log stats from child process related notifications in |
257 // MetricsService::child_stats_buffer_. The buffer's contents are transferred | 261 // MetricsService::child_stats_buffer_. The buffer's contents are transferred |
258 // out when Local State is periodically saved. The information is then | 262 // out when Local State is periodically saved. The information is then |
259 // reported to the UMA server on next launch. | 263 // reported to the UMA server on next launch. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 local_state->ClearPref(prefs::kMetricsInitialLogsXml); | 390 local_state->ClearPref(prefs::kMetricsInitialLogsXml); |
387 local_state->ClearPref(prefs::kMetricsOngoingLogsXml); | 391 local_state->ClearPref(prefs::kMetricsOngoingLogsXml); |
388 local_state->ClearPref(prefs::kMetricsInitialLogsProto); | 392 local_state->ClearPref(prefs::kMetricsInitialLogsProto); |
389 local_state->ClearPref(prefs::kMetricsOngoingLogsProto); | 393 local_state->ClearPref(prefs::kMetricsOngoingLogsProto); |
390 } | 394 } |
391 | 395 |
392 MetricsService::MetricsService() | 396 MetricsService::MetricsService() |
393 : recording_active_(false), | 397 : recording_active_(false), |
394 reporting_active_(false), | 398 reporting_active_(false), |
395 state_(INITIALIZED), | 399 state_(INITIALIZED), |
| 400 #if defined(OS_CHROMEOS) |
| 401 hardware_class_(kHardwareClassNotReady), |
| 402 #endif |
396 idle_since_last_transmission_(false), | 403 idle_since_last_transmission_(false), |
397 next_window_id_(0), | 404 next_window_id_(0), |
398 ALLOW_THIS_IN_INITIALIZER_LIST(self_ptr_factory_(this)), | 405 ALLOW_THIS_IN_INITIALIZER_LIST(self_ptr_factory_(this)), |
399 ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)), | 406 ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)), |
400 waiting_for_asynchronus_reporting_step_(false) { | 407 waiting_for_asynchronus_reporting_step_(false) { |
401 DCHECK(IsSingleThreaded()); | 408 DCHECK(IsSingleThreaded()); |
402 InitializeMetricsState(); | 409 InitializeMetricsState(); |
403 | 410 |
404 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 411 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
405 self_ptr_factory_.GetWeakPtr()); | 412 self_ptr_factory_.GetWeakPtr()); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 size_t switch_count = command_line->GetSwitches().size(); | 754 size_t switch_count = command_line->GetSwitches().size(); |
748 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); | 755 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); |
749 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", | 756 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", |
750 switch_count - common_commands); | 757 switch_count - common_commands); |
751 | 758 |
752 // Kick off the process of saving the state (so the uptime numbers keep | 759 // Kick off the process of saving the state (so the uptime numbers keep |
753 // getting updated) every n minutes. | 760 // getting updated) every n minutes. |
754 ScheduleNextStateSave(); | 761 ScheduleNextStateSave(); |
755 } | 762 } |
756 | 763 |
757 // static | 764 void MetricsService::OnStatisticsProviderReady() { |
758 void MetricsService::InitTaskGetHardwareClass( | |
759 base::WeakPtr<MetricsService> self, | |
760 base::MessageLoopProxy* target_loop) { | |
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
762 | |
763 std::string hardware_class; | |
764 #if defined(OS_CHROMEOS) | 765 #if defined(OS_CHROMEOS) |
| 766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
765 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( | 767 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
766 "hardware_class", &hardware_class); | 768 "hardware_class", &hardware_class_); |
767 #endif // OS_CHROMEOS | 769 #endif |
768 | |
769 target_loop->PostTask(FROM_HERE, | |
770 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | |
771 self, hardware_class)); | |
772 } | 770 } |
773 | 771 |
774 void MetricsService::OnInitTaskGotHardwareClass( | 772 void MetricsService::InitTaskGetPluginInfo() { |
775 const std::string& hardware_class) { | 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
776 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); | 774 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
777 hardware_class_ = hardware_class; | |
778 | 775 |
779 // Start the next part of the init task: loading plugin information. | 776 // Start the next part of the init task: loading plugin information. |
780 PluginService::GetInstance()->GetPlugins( | 777 PluginService::GetInstance()->GetPlugins( |
781 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | 778 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
782 self_ptr_factory_.GetWeakPtr())); | 779 self_ptr_factory_.GetWeakPtr())); |
783 } | 780 } |
784 | 781 |
785 void MetricsService::OnInitTaskGotPluginInfo( | 782 void MetricsService::OnInitTaskGotPluginInfo( |
786 const std::vector<webkit::WebPluginInfo>& plugins) { | 783 const std::vector<webkit::WebPluginInfo>& plugins) { |
787 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); | 784 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
788 plugins_ = plugins; | 785 plugins_ = plugins; |
789 | 786 |
790 if (state_ == INIT_TASK_SCHEDULED) | 787 if (state_ == INIT_TASK_SCHEDULED) |
791 state_ = INIT_TASK_DONE; | 788 state_ = INIT_TASK_DONE; |
792 } | 789 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 void MetricsService::StartRecording() { | 824 void MetricsService::StartRecording() { |
828 if (log_manager_.current_log()) | 825 if (log_manager_.current_log()) |
829 return; | 826 return; |
830 | 827 |
831 log_manager_.BeginLoggingWithLog(new MetricsLog(client_id_, session_id_), | 828 log_manager_.BeginLoggingWithLog(new MetricsLog(client_id_, session_id_), |
832 MetricsLogManager::ONGOING_LOG); | 829 MetricsLogManager::ONGOING_LOG); |
833 if (state_ == INITIALIZED) { | 830 if (state_ == INITIALIZED) { |
834 // We only need to schedule that run once. | 831 // We only need to schedule that run once. |
835 state_ = INIT_TASK_SCHEDULED; | 832 state_ = INIT_TASK_SCHEDULED; |
836 | 833 |
837 // Schedules a task on the file thread for execution of slower | 834 #if defined(OS_CHROMEOS) |
838 // initialization steps (such as plugin list generation) necessary | 835 // The hardware class can only be retrieved once the StatisticsProvider is |
839 // for sending the initial log. This avoids blocking the main UI | 836 // ready. This usually happens early enough, but can take longer on some |
840 // thread. | 837 // faulty hardware. |
841 BrowserThread::PostDelayedTask( | 838 chromeos::system::StatisticsProvider::GetInstance()->WhenReady( |
842 BrowserThread::FILE, | 839 base::Bind(&MetricsService::OnStatisticsProviderReady, |
| 840 self_ptr_factory_.GetWeakPtr())); |
| 841 #endif |
| 842 |
| 843 // Schedules a delayed task for execution of slower initialization steps |
| 844 // (such as plugin list generation) necessary for sending the initial log. |
| 845 MessageLoop::current()->PostDelayedTask( |
843 FROM_HERE, | 846 FROM_HERE, |
844 base::Bind(&MetricsService::InitTaskGetHardwareClass, | 847 base::Bind(&MetricsService::InitTaskGetPluginInfo, |
845 self_ptr_factory_.GetWeakPtr(), | 848 self_ptr_factory_.GetWeakPtr()), |
846 MessageLoop::current()->message_loop_proxy()), | |
847 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | 849 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
848 } | 850 } |
849 } | 851 } |
850 | 852 |
851 void MetricsService::StopRecording() { | 853 void MetricsService::StopRecording() { |
852 if (!log_manager_.current_log()) | 854 if (!log_manager_.current_log()) |
853 return; | 855 return; |
854 | 856 |
855 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 857 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
856 // can stop recording logs that are too big much sooner. | 858 // can stop recording logs that are too big much sooner. |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 if (local_state) { | 1672 if (local_state) { |
1671 const PrefService::Preference* uma_pref = | 1673 const PrefService::Preference* uma_pref = |
1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1674 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1673 if (uma_pref) { | 1675 if (uma_pref) { |
1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1676 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1675 DCHECK(success); | 1677 DCHECK(success); |
1676 } | 1678 } |
1677 } | 1679 } |
1678 return result; | 1680 return result; |
1679 } | 1681 } |
OLD | NEW |