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) { |
801 const std::vector<webkit::WebPluginInfo>& plugins) { | 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) { | |
802 DCHECK(state_ == INIT_TASK_SCHEDULED); | 780 DCHECK(state_ == INIT_TASK_SCHEDULED); |
803 hardware_class_ = hardware_class; | 781 hardware_class_ = hardware_class; |
782 | |
783 // Start the next part of the init task: loading plugin information. | |
784 PluginService::GetInstance()->LoadPluginList(false, | |
785 base::Bind(&MetricsService::OnInitTaskPluginsLoaded, | |
786 base::Unretained(this))); | |
787 } | |
788 | |
789 void MetricsService::OnInitTaskPluginsLoaded() { | |
790 std::vector<webkit::WebPluginInfo> plugins; | |
791 PluginService::GetInstance()->GetPlugins(&plugins); | |
jam
2011/09/22 21:10:59
nit: can just get rid of the plugins local variabl
| |
792 | |
793 DCHECK(state_ == INIT_TASK_SCHEDULED); | |
804 plugins_ = plugins; | 794 plugins_ = plugins; |
795 | |
805 io_thread_ = g_browser_process->io_thread(); | 796 io_thread_ = g_browser_process->io_thread(); |
806 if (state_ == INIT_TASK_SCHEDULED) | 797 if (state_ == INIT_TASK_SCHEDULED) |
807 state_ = INIT_TASK_DONE; | 798 state_ = INIT_TASK_DONE; |
808 } | 799 } |
809 | 800 |
810 std::string MetricsService::GenerateClientID() { | 801 std::string MetricsService::GenerateClientID() { |
811 return guid::GenerateGUID(); | 802 return guid::GenerateGUID(); |
812 } | 803 } |
813 | 804 |
814 //------------------------------------------------------------------------------ | 805 //------------------------------------------------------------------------------ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
846 | 837 |
847 current_log_ = new MetricsLog(client_id_, session_id_); | 838 current_log_ = new MetricsLog(client_id_, session_id_); |
848 if (state_ == INITIALIZED) { | 839 if (state_ == INITIALIZED) { |
849 // We only need to schedule that run once. | 840 // We only need to schedule that run once. |
850 state_ = INIT_TASK_SCHEDULED; | 841 state_ = INIT_TASK_SCHEDULED; |
851 | 842 |
852 // Schedules a task on the file thread for execution of slower | 843 // Schedules a task on the file thread for execution of slower |
853 // initialization steps (such as plugin list generation) necessary | 844 // initialization steps (such as plugin list generation) necessary |
854 // for sending the initial log. This avoids blocking the main UI | 845 // for sending the initial log. This avoids blocking the main UI |
855 // thread. | 846 // thread. |
856 g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE, | 847 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, |
857 new InitTask(MessageLoop::current()), | 848 base::Bind(&MetricsService::InitTaskGetHardwareClass, |
849 base::Unretained(this), | |
850 MessageLoop::current()->message_loop_proxy()), | |
858 kInitializationDelaySeconds * 1000); | 851 kInitializationDelaySeconds * 1000); |
859 } | 852 } |
860 } | 853 } |
861 | 854 |
862 void MetricsService::StopRecording() { | 855 void MetricsService::StopRecording() { |
863 if (!current_log_) | 856 if (!current_log_) |
864 return; | 857 return; |
865 | 858 |
866 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 859 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
867 // can stop recording logs that are too big much sooner. | 860 // 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) { | 1741 if (local_state) { |
1749 const PrefService::Preference* uma_pref = | 1742 const PrefService::Preference* uma_pref = |
1750 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1743 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1751 if (uma_pref) { | 1744 if (uma_pref) { |
1752 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1745 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1753 DCHECK(success); | 1746 DCHECK(success); |
1754 } | 1747 } |
1755 } | 1748 } |
1756 return result; | 1749 return result; |
1757 } | 1750 } |
OLD | NEW |