| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 #include "chrome/browser/profiles/profile.h" | 180 #include "chrome/browser/profiles/profile.h" |
| 181 #include "chrome/browser/search_engines/template_url_service.h" | 181 #include "chrome/browser/search_engines/template_url_service.h" |
| 182 #include "chrome/browser/ui/browser_list.h" | 182 #include "chrome/browser/ui/browser_list.h" |
| 183 #include "chrome/common/child_process_logging.h" | 183 #include "chrome/common/child_process_logging.h" |
| 184 #include "chrome/common/chrome_notification_types.h" | 184 #include "chrome/common/chrome_notification_types.h" |
| 185 #include "chrome/common/chrome_switches.h" | 185 #include "chrome/common/chrome_switches.h" |
| 186 #include "chrome/common/guid.h" | 186 #include "chrome/common/guid.h" |
| 187 #include "chrome/common/pref_names.h" | 187 #include "chrome/common/pref_names.h" |
| 188 #include "chrome/common/render_messages.h" | 188 #include "chrome/common/render_messages.h" |
| 189 #include "content/browser/load_notification_details.h" | 189 #include "content/browser/load_notification_details.h" |
| 190 #include "content/browser/plugin_service.h" |
| 190 #include "content/browser/renderer_host/render_process_host.h" | 191 #include "content/browser/renderer_host/render_process_host.h" |
| 191 #include "content/common/child_process_info.h" | 192 #include "content/common/child_process_info.h" |
| 192 #include "content/common/notification_service.h" | 193 #include "content/common/notification_service.h" |
| 193 #include "webkit/plugins/npapi/plugin_list.h" | 194 #include "webkit/plugins/npapi/plugin_list.h" |
| 194 #include "webkit/plugins/webplugininfo.h" | 195 #include "webkit/plugins/webplugininfo.h" |
| 195 | 196 |
| 196 // TODO(port): port browser_distribution.h. | 197 // TODO(port): port browser_distribution.h. |
| 197 #if !defined(OS_POSIX) | 198 #if !defined(OS_POSIX) |
| 198 #include "chrome/installer/util/browser_distribution.h" | 199 #include "chrome/installer/util/browser_distribution.h" |
| 199 #endif | 200 #endif |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 MessageLoop::current()->PostTask(FROM_HERE, completion_); | 315 MessageLoop::current()->PostTask(FROM_HERE, completion_); |
| 315 } | 316 } |
| 316 | 317 |
| 317 private: | 318 private: |
| 318 ~MetricsMemoryDetails() {} | 319 ~MetricsMemoryDetails() {} |
| 319 | 320 |
| 320 Task* completion_; | 321 Task* completion_; |
| 321 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 322 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
| 322 }; | 323 }; |
| 323 | 324 |
| 324 class MetricsService::InitTaskComplete : public Task { | |
| 325 public: | |
| 326 explicit InitTaskComplete( | |
| 327 const std::string& hardware_class, | |
| 328 const std::vector<webkit::WebPluginInfo>& plugins) | |
| 329 : hardware_class_(hardware_class), plugins_(plugins) {} | |
| 330 | |
| 331 virtual void Run() { | |
| 332 g_browser_process->metrics_service()->OnInitTaskComplete( | |
| 333 hardware_class_, plugins_); | |
| 334 } | |
| 335 | |
| 336 private: | |
| 337 std::string hardware_class_; | |
| 338 std::vector<webkit::WebPluginInfo> plugins_; | |
| 339 }; | |
| 340 | |
| 341 class MetricsService::InitTask : public Task { | |
| 342 public: | |
| 343 explicit InitTask(MessageLoop* callback_loop) | |
| 344 : callback_loop_(callback_loop) {} | |
| 345 | |
| 346 virtual void Run() { | |
| 347 std::vector<webkit::WebPluginInfo> plugins; | |
| 348 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); | |
| 349 std::string hardware_class; // Empty string by default. | |
| 350 #if defined(OS_CHROMEOS) | |
| 351 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( | |
| 352 "hardware_class", &hardware_class); | |
| 353 #endif // OS_CHROMEOS | |
| 354 callback_loop_->PostTask(FROM_HERE, new InitTaskComplete( | |
| 355 hardware_class, plugins)); | |
| 356 } | |
| 357 | |
| 358 private: | |
| 359 MessageLoop* callback_loop_; | |
| 360 }; | |
| 361 | |
| 362 // static | 325 // static |
| 363 void MetricsService::RegisterPrefs(PrefService* local_state) { | 326 void MetricsService::RegisterPrefs(PrefService* local_state) { |
| 364 DCHECK(IsSingleThreaded()); | 327 DCHECK(IsSingleThreaded()); |
| 365 local_state->RegisterStringPref(prefs::kMetricsClientID, ""); | 328 local_state->RegisterStringPref(prefs::kMetricsClientID, ""); |
| 366 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); | 329 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); |
| 367 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 330 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
| 368 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 331 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
| 369 local_state->RegisterStringPref(prefs::kStabilityStatsVersion, ""); | 332 local_state->RegisterStringPref(prefs::kStabilityStatsVersion, ""); |
| 370 local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 333 local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
| 371 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 334 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 size_t switch_count = command_line->GetSwitches().size(); | 752 size_t switch_count = command_line->GetSwitches().size(); |
| 790 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); | 753 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); |
| 791 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", | 754 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", |
| 792 switch_count - common_commands); | 755 switch_count - common_commands); |
| 793 | 756 |
| 794 // Kick off the process of saving the state (so the uptime numbers keep | 757 // Kick off the process of saving the state (so the uptime numbers keep |
| 795 // getting updated) every n minutes. | 758 // getting updated) every n minutes. |
| 796 ScheduleNextStateSave(); | 759 ScheduleNextStateSave(); |
| 797 } | 760 } |
| 798 | 761 |
| 799 void MetricsService::OnInitTaskComplete( | 762 void MetricsService::InitTaskGetHardwareClass( |
| 800 const std::string& hardware_class, | 763 base::MessageLoopProxy* target_loop) { |
| 764 DCHECK(state_ == INIT_TASK_SCHEDULED); |
| 765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 766 |
| 767 std::string hardware_class; |
| 768 #if defined(OS_CHROMEOS) |
| 769 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
| 770 "hardware_class", &hardware_class); |
| 771 #endif // OS_CHROMEOS |
| 772 |
| 773 target_loop->PostTask(FROM_HERE, |
| 774 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
| 775 base::Unretained(this), hardware_class)); |
| 776 } |
| 777 |
| 778 void MetricsService::OnInitTaskGotHardwareClass( |
| 779 const std::string& hardware_class) { |
| 780 DCHECK(state_ == INIT_TASK_SCHEDULED); |
| 781 hardware_class_ = hardware_class; |
| 782 |
| 783 // Start the next part of the init task: loading plugin information. |
| 784 PluginService::GetInstance()->GetPlugins( |
| 785 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
| 786 base::Unretained(this))); |
| 787 } |
| 788 |
| 789 void MetricsService::OnInitTaskGotPluginInfo( |
| 801 const std::vector<webkit::WebPluginInfo>& plugins) { | 790 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 802 DCHECK(state_ == INIT_TASK_SCHEDULED); | 791 DCHECK(state_ == INIT_TASK_SCHEDULED); |
| 803 hardware_class_ = hardware_class; | |
| 804 plugins_ = plugins; | 792 plugins_ = plugins; |
| 793 |
| 805 io_thread_ = g_browser_process->io_thread(); | 794 io_thread_ = g_browser_process->io_thread(); |
| 806 if (state_ == INIT_TASK_SCHEDULED) | 795 if (state_ == INIT_TASK_SCHEDULED) |
| 807 state_ = INIT_TASK_DONE; | 796 state_ = INIT_TASK_DONE; |
| 808 } | 797 } |
| 809 | 798 |
| 810 std::string MetricsService::GenerateClientID() { | 799 std::string MetricsService::GenerateClientID() { |
| 811 return guid::GenerateGUID(); | 800 return guid::GenerateGUID(); |
| 812 } | 801 } |
| 813 | 802 |
| 814 //------------------------------------------------------------------------------ | 803 //------------------------------------------------------------------------------ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 835 |
| 847 current_log_ = new MetricsLog(client_id_, session_id_); | 836 current_log_ = new MetricsLog(client_id_, session_id_); |
| 848 if (state_ == INITIALIZED) { | 837 if (state_ == INITIALIZED) { |
| 849 // We only need to schedule that run once. | 838 // We only need to schedule that run once. |
| 850 state_ = INIT_TASK_SCHEDULED; | 839 state_ = INIT_TASK_SCHEDULED; |
| 851 | 840 |
| 852 // Schedules a task on the file thread for execution of slower | 841 // Schedules a task on the file thread for execution of slower |
| 853 // initialization steps (such as plugin list generation) necessary | 842 // initialization steps (such as plugin list generation) necessary |
| 854 // for sending the initial log. This avoids blocking the main UI | 843 // for sending the initial log. This avoids blocking the main UI |
| 855 // thread. | 844 // thread. |
| 856 g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE, | 845 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, |
| 857 new InitTask(MessageLoop::current()), | 846 base::Bind(&MetricsService::InitTaskGetHardwareClass, |
| 847 base::Unretained(this), |
| 848 MessageLoop::current()->message_loop_proxy()), |
| 858 kInitializationDelaySeconds * 1000); | 849 kInitializationDelaySeconds * 1000); |
| 859 } | 850 } |
| 860 } | 851 } |
| 861 | 852 |
| 862 void MetricsService::StopRecording() { | 853 void MetricsService::StopRecording() { |
| 863 if (!current_log_) | 854 if (!current_log_) |
| 864 return; | 855 return; |
| 865 | 856 |
| 866 // 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 |
| 867 // can stop recording logs that are too big much sooner. | 858 // can stop recording logs that are too big much sooner. |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 if (local_state) { | 1739 if (local_state) { |
| 1749 const PrefService::Preference* uma_pref = | 1740 const PrefService::Preference* uma_pref = |
| 1750 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1741 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1751 if (uma_pref) { | 1742 if (uma_pref) { |
| 1752 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1743 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1753 DCHECK(success); | 1744 DCHECK(success); |
| 1754 } | 1745 } |
| 1755 } | 1746 } |
| 1756 return result; | 1747 return result; |
| 1757 } | 1748 } |
| OLD | NEW |