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

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

Issue 10078017: Added asynchronous notification of readiness to the StatisticsProvider, and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 8 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) 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
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 and waiting for hardware statistics on Chrome OS.
95 // (when complete) make an async callback (via a Task) to indicate the 95 // That task will (when complete) make an async callback (via a Task) to
96 // completion. 96 // indicate the completion.
97 // 97 //
98 // INIT_TASK_DONE, // Waiting for timer to send initial log. 98 // 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 99 // 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 100 // created. This callback typically arrives back less than one second after
101 // the deferred init task is dispatched. 101 // the deferred init task is dispatched.
102 // 102 //
103 // INITIAL_LOG_READY, // Initial log generated, and waiting for reply. 103 // INITIAL_LOG_READY, // Initial log generated, and waiting for reply.
104 // This state is entered only after an initial log has been composed, and 104 // 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 105 // prepared for transmission. It is also the case that any previously unsent
106 // logs have been loaded into instance variables for possible transmission. 106 // logs have been loaded into instance variables for possible transmission.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 //------------------------------------------------------------------------------ 143 //------------------------------------------------------------------------------
144 144
145 #include "chrome/browser/metrics/metrics_service.h" 145 #include "chrome/browser/metrics/metrics_service.h"
146 146
147 #include "base/bind.h" 147 #include "base/bind.h"
148 #include "base/callback.h" 148 #include "base/callback.h"
149 #include "base/command_line.h" 149 #include "base/command_line.h"
150 #include "base/md5.h" 150 #include "base/md5.h"
151 #include "base/metrics/histogram.h" 151 #include "base/metrics/histogram.h"
152 #include "base/string_number_conversions.h" 152 #include "base/string_number_conversions.h"
153 #include "base/string_util.h"
153 #include "base/threading/platform_thread.h" 154 #include "base/threading/platform_thread.h"
154 #include "base/threading/thread.h" 155 #include "base/threading/thread.h"
155 #include "base/utf_string_conversions.h" 156 #include "base/utf_string_conversions.h"
156 #include "base/values.h" 157 #include "base/values.h"
157 #include "chrome/browser/bookmarks/bookmark_model.h" 158 #include "chrome/browser/bookmarks/bookmark_model.h"
158 #include "chrome/browser/browser_process.h" 159 #include "chrome/browser/browser_process.h"
159 #include "chrome/browser/extensions/extension_service.h" 160 #include "chrome/browser/extensions/extension_service.h"
160 #include "chrome/browser/extensions/process_map.h" 161 #include "chrome/browser/extensions/process_map.h"
161 #include "chrome/browser/io_thread.h" 162 #include "chrome/browser/io_thread.h"
162 #include "chrome/browser/memory_details.h" 163 #include "chrome/browser/memory_details.h"
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount", 750 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineUncommonFlagCount",
750 switch_count - common_commands); 751 switch_count - common_commands);
751 752
752 // Kick off the process of saving the state (so the uptime numbers keep 753 // Kick off the process of saving the state (so the uptime numbers keep
753 // getting updated) every n minutes. 754 // getting updated) every n minutes.
754 ScheduleNextStateSave(); 755 ScheduleNextStateSave();
755 } 756 }
756 757
757 // static 758 // static
758 void MetricsService::InitTaskGetHardwareClass( 759 void MetricsService::InitTaskGetHardwareClass(
759 base::WeakPtr<MetricsService> self, 760 base::WeakPtr<MetricsService> self) {
760 base::MessageLoopProxy* target_loop) { 761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 762 #if defined(OS_CHROMEOS)
763 chromeos::system::StatisticsProvider::GetInstance()->WhenReady(
764 base::Bind(&MetricsService::OnStatisticsProviderReady,
765 self));
766 #else
767 if (self)
768 self->OnInitTaskGotHardwareClass(EmptyString());
769 #endif // OS_CHROMEOS
770 }
762 771
772 #if defined(OS_CHROMEOS)
773 void MetricsService::OnStatisticsProviderReady() {
774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
763 std::string hardware_class; 775 std::string hardware_class;
764 #if defined(OS_CHROMEOS)
765 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( 776 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
766 "hardware_class", &hardware_class); 777 "hardware_class", &hardware_class);
767 #endif // OS_CHROMEOS 778 OnInitTaskGotHardwareClass(hardware_class);
768
769 target_loop->PostTask(FROM_HERE,
770 base::Bind(&MetricsService::OnInitTaskGotHardwareClass,
771 self, hardware_class));
772 } 779 }
780 #endif
773 781
774 void MetricsService::OnInitTaskGotHardwareClass( 782 void MetricsService::OnInitTaskGotHardwareClass(
775 const std::string& hardware_class) { 783 const std::string& hardware_class) {
784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
776 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); 785 DCHECK_EQ(state_, INIT_TASK_SCHEDULED);
777 hardware_class_ = hardware_class; 786 hardware_class_ = hardware_class;
778 787
779 // Start the next part of the init task: loading plugin information. 788 // Start the next part of the init task: loading plugin information.
780 PluginService::GetInstance()->GetPlugins( 789 PluginService::GetInstance()->GetPlugins(
781 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, 790 base::Bind(&MetricsService::OnInitTaskGotPluginInfo,
782 self_ptr_factory_.GetWeakPtr())); 791 self_ptr_factory_.GetWeakPtr()));
783 } 792 }
784 793
785 void MetricsService::OnInitTaskGotPluginInfo( 794 void MetricsService::OnInitTaskGotPluginInfo(
786 const std::vector<webkit::WebPluginInfo>& plugins) { 795 const std::vector<webkit::WebPluginInfo>& plugins) {
787 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); 796 DCHECK_EQ(state_, INIT_TASK_SCHEDULED);
788 plugins_ = plugins; 797 plugins_ = plugins;
789 798
790 if (state_ == INIT_TASK_SCHEDULED) 799 if (state_ == INIT_TASK_SCHEDULED)
791 state_ = INIT_TASK_DONE; 800 state_ = INIT_TASK_DONE;
792 } 801 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 MetricsLogManager::ONGOING_LOG); 841 MetricsLogManager::ONGOING_LOG);
833 if (state_ == INITIALIZED) { 842 if (state_ == INITIALIZED) {
834 // We only need to schedule that run once. 843 // We only need to schedule that run once.
835 state_ = INIT_TASK_SCHEDULED; 844 state_ = INIT_TASK_SCHEDULED;
836 845
837 // Schedules a task on the file thread for execution of slower 846 // Schedules a task on the file thread for execution of slower
838 // initialization steps (such as plugin list generation) necessary 847 // initialization steps (such as plugin list generation) necessary
839 // for sending the initial log. This avoids blocking the main UI 848 // for sending the initial log. This avoids blocking the main UI
840 // thread. 849 // thread.
841 BrowserThread::PostDelayedTask( 850 BrowserThread::PostDelayedTask(
842 BrowserThread::FILE, 851 BrowserThread::UI,
843 FROM_HERE, 852 FROM_HERE,
844 base::Bind(&MetricsService::InitTaskGetHardwareClass, 853 base::Bind(&MetricsService::InitTaskGetHardwareClass,
845 self_ptr_factory_.GetWeakPtr(), 854 self_ptr_factory_.GetWeakPtr()),
846 MessageLoop::current()->message_loop_proxy()),
847 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 855 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
848 } 856 }
849 } 857 }
850 858
851 void MetricsService::StopRecording() { 859 void MetricsService::StopRecording() {
852 if (!log_manager_.current_log()) 860 if (!log_manager_.current_log())
853 return; 861 return;
854 862
855 // TODO(jar): Integrate bounds on log recording more consistently, so that we 863 // TODO(jar): Integrate bounds on log recording more consistently, so that we
856 // can stop recording logs that are too big much sooner. 864 // can stop recording logs that are too big much sooner.
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 if (local_state) { 1678 if (local_state) {
1671 const PrefService::Preference* uma_pref = 1679 const PrefService::Preference* uma_pref =
1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1680 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1673 if (uma_pref) { 1681 if (uma_pref) {
1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1682 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1675 DCHECK(success); 1683 DCHECK(success);
1676 } 1684 }
1677 } 1685 }
1678 return result; 1686 return result;
1679 } 1687 }
OLDNEW
« chrome/browser/metrics/metrics_service.h ('K') | « chrome/browser/metrics/metrics_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698