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 | 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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 size_t switch_count = command_line->GetSwitches().size(); | 751 size_t switch_count = command_line->GetSwitches().size(); |
| 748 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); | 752 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); |
| 749 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", | 753 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", |
| 750 switch_count - common_commands); | 754 switch_count - common_commands); |
| 751 | 755 |
| 752 // Kick off the process of saving the state (so the uptime numbers keep | 756 // Kick off the process of saving the state (so the uptime numbers keep |
| 753 // getting updated) every n minutes. | 757 // getting updated) every n minutes. |
| 754 ScheduleNextStateSave(); | 758 ScheduleNextStateSave(); |
| 755 } | 759 } |
| 756 | 760 |
| 757 // static | 761 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) | 762 #if defined(OS_CHROMEOS) |
| 763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 765 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( | 764 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
| 766 "hardware_class", &hardware_class); | 765 "hardware_class", &hardware_class_); |
| 767 #endif // OS_CHROMEOS | 766 #endif |
| 768 | |
| 769 target_loop->PostTask(FROM_HERE, | |
| 770 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | |
| 771 self, hardware_class)); | |
| 772 } | 767 } |
| 773 | 768 |
| 774 void MetricsService::OnInitTaskGotHardwareClass( | 769 void MetricsService::InitTaskGetPluginInfo() { |
| 775 const std::string& hardware_class) { | 770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 776 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); | 771 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
| 777 hardware_class_ = hardware_class; | |
| 778 | 772 |
| 779 // Start the next part of the init task: loading plugin information. | 773 // Start the next part of the init task: loading plugin information. |
| 780 PluginService::GetInstance()->GetPlugins( | 774 PluginService::GetInstance()->GetPlugins( |
| 781 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | 775 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
| 782 self_ptr_factory_.GetWeakPtr())); | 776 self_ptr_factory_.GetWeakPtr())); |
| 783 } | 777 } |
| 784 | 778 |
| 785 void MetricsService::OnInitTaskGotPluginInfo( | 779 void MetricsService::OnInitTaskGotPluginInfo( |
| 786 const std::vector<webkit::WebPluginInfo>& plugins) { | 780 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 787 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); | 781 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
| 788 plugins_ = plugins; | 782 plugins_ = plugins; |
| 789 | 783 |
| 790 if (state_ == INIT_TASK_SCHEDULED) | 784 if (state_ == INIT_TASK_SCHEDULED) |
| 791 state_ = INIT_TASK_DONE; | 785 state_ = INIT_TASK_DONE; |
| 792 } | 786 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 void MetricsService::StartRecording() { | 821 void MetricsService::StartRecording() { |
| 828 if (log_manager_.current_log()) | 822 if (log_manager_.current_log()) |
| 829 return; | 823 return; |
| 830 | 824 |
| 831 log_manager_.BeginLoggingWithLog(new MetricsLog(client_id_, session_id_), | 825 log_manager_.BeginLoggingWithLog(new MetricsLog(client_id_, session_id_), |
| 832 MetricsLogManager::ONGOING_LOG); | 826 MetricsLogManager::ONGOING_LOG); |
| 833 if (state_ == INITIALIZED) { | 827 if (state_ == INITIALIZED) { |
| 834 // We only need to schedule that run once. | 828 // We only need to schedule that run once. |
| 835 state_ = INIT_TASK_SCHEDULED; | 829 state_ = INIT_TASK_SCHEDULED; |
| 836 | 830 |
| 837 // Schedules a task on the file thread for execution of slower | 831 #if defined(OS_CHROMEOS) |
| 838 // initialization steps (such as plugin list generation) necessary | 832 // The hardware class can only be retrieved once the StatisticsProvider is |
| 839 // for sending the initial log. This avoids blocking the main UI | 833 // ready. This usually happens early enough, but can take longer on some |
| 840 // thread. | 834 // faulty hardware. Use a temporary special marker to identify those cases. |
| 841 BrowserThread::PostDelayedTask( | 835 hardware_class_ = kHardwareClassNotReady; |
|
Ilya Sherman
2012/04/20 21:18:37
nit: Any reason not to initialize this in the cons
Joao da Silva
2012/04/23 09:36:50
Done.
| |
| 842 BrowserThread::FILE, | 836 chromeos::system::StatisticsProvider::GetInstance()->WhenReady( |
| 837 base::Bind(&MetricsService::OnStatisticsProviderReady, | |
| 838 self_ptr_factory_.GetWeakPtr())); | |
| 839 #endif | |
| 840 | |
| 841 // Schedules a delayed task for execution of slower initialization steps | |
| 842 // (such as plugin list generation) necessary for sending the initial log. | |
| 843 MessageLoop::current()->PostDelayedTask( | |
| 843 FROM_HERE, | 844 FROM_HERE, |
| 844 base::Bind(&MetricsService::InitTaskGetHardwareClass, | 845 base::Bind(&MetricsService::InitTaskGetPluginInfo, |
| 845 self_ptr_factory_.GetWeakPtr(), | 846 self_ptr_factory_.GetWeakPtr()), |
| 846 MessageLoop::current()->message_loop_proxy()), | |
| 847 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | 847 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
| 848 } | 848 } |
| 849 } | 849 } |
| 850 | 850 |
| 851 void MetricsService::StopRecording() { | 851 void MetricsService::StopRecording() { |
| 852 if (!log_manager_.current_log()) | 852 if (!log_manager_.current_log()) |
| 853 return; | 853 return; |
| 854 | 854 |
| 855 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 855 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
| 856 // can stop recording logs that are too big much sooner. | 856 // 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) { | 1670 if (local_state) { |
| 1671 const PrefService::Preference* uma_pref = | 1671 const PrefService::Preference* uma_pref = |
| 1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1673 if (uma_pref) { | 1673 if (uma_pref) { |
| 1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1675 DCHECK(success); | 1675 DCHECK(success); |
| 1676 } | 1676 } |
| 1677 } | 1677 } |
| 1678 return result; | 1678 return result; |
| 1679 } | 1679 } |
| OLD | NEW |