Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 7980011: Convert the PluginService interface to be an async wrapper around PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 MessageLoop::current()->PostTask(FROM_HERE, completion_); 317 MessageLoop::current()->PostTask(FROM_HERE, completion_);
317 } 318 }
318 319
319 private: 320 private:
320 ~MetricsMemoryDetails() {} 321 ~MetricsMemoryDetails() {}
321 322
322 Task* completion_; 323 Task* completion_;
323 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); 324 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
324 }; 325 };
325 326
326 class MetricsService::InitTaskComplete : public Task {
327 public:
328 explicit InitTaskComplete(
329 const std::string& hardware_class,
330 const std::vector<webkit::WebPluginInfo>& plugins)
331 : hardware_class_(hardware_class), plugins_(plugins) {}
332
333 virtual void Run() {
334 g_browser_process->metrics_service()->OnInitTaskComplete(
335 hardware_class_, plugins_);
336 }
337
338 private:
339 std::string hardware_class_;
340 std::vector<webkit::WebPluginInfo> plugins_;
341 };
342
343 class MetricsService::InitTask : public Task {
344 public:
345 explicit InitTask(MessageLoop* callback_loop)
346 : callback_loop_(callback_loop) {}
347
348 virtual void Run() {
349 std::vector<webkit::WebPluginInfo> plugins;
350 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins);
351 std::string hardware_class; // Empty string by default.
352 #if defined(OS_CHROMEOS)
353 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
354 "hardware_class", &hardware_class);
355 #endif // OS_CHROMEOS
356 callback_loop_->PostTask(FROM_HERE, new InitTaskComplete(
357 hardware_class, plugins));
358 }
359
360 private:
361 MessageLoop* callback_loop_;
362 };
363
364 // static 327 // static
365 void MetricsService::RegisterPrefs(PrefService* local_state) { 328 void MetricsService::RegisterPrefs(PrefService* local_state) {
366 DCHECK(IsSingleThreaded()); 329 DCHECK(IsSingleThreaded());
367 local_state->RegisterStringPref(prefs::kMetricsClientID, ""); 330 local_state->RegisterStringPref(prefs::kMetricsClientID, "");
368 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); 331 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0);
369 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); 332 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0);
370 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); 333 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0);
371 local_state->RegisterStringPref(prefs::kStabilityStatsVersion, ""); 334 local_state->RegisterStringPref(prefs::kStabilityStatsVersion, "");
372 local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); 335 local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0);
373 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); 336 local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 size_t switch_count = command_line->GetSwitches().size(); 754 size_t switch_count = command_line->GetSwitches().size();
792 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count); 755 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineFlagCount", switch_count);
793 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", 756 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount",
794 switch_count - common_commands); 757 switch_count - common_commands);
795 758
796 // 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
797 // getting updated) every n minutes. 760 // getting updated) every n minutes.
798 ScheduleNextStateSave(); 761 ScheduleNextStateSave();
799 } 762 }
800 763
801 void MetricsService::OnInitTaskComplete( 764 void MetricsService::InitTaskGetHardwareClass(
802 const std::string& hardware_class, 765 base::MessageLoopProxy* target_loop) {
766 DCHECK(state_ == INIT_TASK_SCHEDULED);
767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
768
769 std::string hardware_class;
770 #if defined(OS_CHROMEOS)
771 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
772 "hardware_class", &hardware_class);
773 #endif // OS_CHROMEOS
774
775 target_loop->PostTask(FROM_HERE,
776 base::Bind(&MetricsService::OnInitTaskGotHardwareClass,
777 base::Unretained(this), hardware_class));
778 }
779
780 void MetricsService::OnInitTaskGotHardwareClass(
781 const std::string& hardware_class) {
782 DCHECK(state_ == INIT_TASK_SCHEDULED);
783 hardware_class_ = hardware_class;
784
785 // Start the next part of the init task: loading plugin information.
786 PluginService::GetInstance()->GetPlugins(
787 base::Bind(&MetricsService::OnInitTaskGotPluginInfo,
788 base::Unretained(this)));
789 }
790
791 void MetricsService::OnInitTaskGotPluginInfo(
803 const std::vector<webkit::WebPluginInfo>& plugins) { 792 const std::vector<webkit::WebPluginInfo>& plugins) {
804 DCHECK(state_ == INIT_TASK_SCHEDULED); 793 DCHECK(state_ == INIT_TASK_SCHEDULED);
805 hardware_class_ = hardware_class;
806 plugins_ = plugins; 794 plugins_ = plugins;
795
807 io_thread_ = g_browser_process->io_thread(); 796 io_thread_ = g_browser_process->io_thread();
808 if (state_ == INIT_TASK_SCHEDULED) 797 if (state_ == INIT_TASK_SCHEDULED)
809 state_ = INIT_TASK_DONE; 798 state_ = INIT_TASK_DONE;
810 } 799 }
811 800
812 std::string MetricsService::GenerateClientID() { 801 std::string MetricsService::GenerateClientID() {
813 return guid::GenerateGUID(); 802 return guid::GenerateGUID();
814 } 803 }
815 804
816 //------------------------------------------------------------------------------ 805 //------------------------------------------------------------------------------
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 837
849 current_log_ = new MetricsLog(client_id_, session_id_); 838 current_log_ = new MetricsLog(client_id_, session_id_);
850 if (state_ == INITIALIZED) { 839 if (state_ == INITIALIZED) {
851 // We only need to schedule that run once. 840 // We only need to schedule that run once.
852 state_ = INIT_TASK_SCHEDULED; 841 state_ = INIT_TASK_SCHEDULED;
853 842
854 // Schedules a task on the file thread for execution of slower 843 // Schedules a task on the file thread for execution of slower
855 // initialization steps (such as plugin list generation) necessary 844 // initialization steps (such as plugin list generation) necessary
856 // for sending the initial log. This avoids blocking the main UI 845 // for sending the initial log. This avoids blocking the main UI
857 // thread. 846 // thread.
858 g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE, 847 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
859 new InitTask(MessageLoop::current()), 848 base::Bind(&MetricsService::InitTaskGetHardwareClass,
849 base::Unretained(this),
850 MessageLoop::current()->message_loop_proxy()),
860 kInitializationDelaySeconds * 1000); 851 kInitializationDelaySeconds * 1000);
861 } 852 }
862 } 853 }
863 854
864 void MetricsService::StopRecording() { 855 void MetricsService::StopRecording() {
865 if (!current_log_) 856 if (!current_log_)
866 return; 857 return;
867 858
868 // 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
869 // 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
1750 if (local_state) { 1741 if (local_state) {
1751 const PrefService::Preference* uma_pref = 1742 const PrefService::Preference* uma_pref =
1752 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1743 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1753 if (uma_pref) { 1744 if (uma_pref) {
1754 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1745 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1755 DCHECK(success); 1746 DCHECK(success);
1756 } 1747 }
1757 } 1748 }
1758 return result; 1749 return result;
1759 } 1750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698