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

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

Issue 301633006: Move ChromeOS hardware class init out of MetricsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/metrics/chromeos_metrics_provider.h" 5 #include "chrome/browser/metrics/chromeos_metrics_provider.h"
6 6
7 #include "base/prefs/pref_registry_simple.h" 7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/login/users/user_manager.h" 13 #include "chrome/browser/chromeos/login/users/user_manager.h"
14 #include "chrome/browser/metrics/metrics_service.h" 14 #include "chrome/browser/metrics/metrics_service.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chromeos/system/statistics_provider.h"
16 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" 17 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
18 #include "content/public/browser/browser_thread.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 19 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_adapter_factory.h" 20 #include "device/bluetooth/bluetooth_adapter_factory.h"
19 #include "device/bluetooth/bluetooth_device.h" 21 #include "device/bluetooth/bluetooth_device.h"
20 #include "ui/events/event_utils.h" 22 #include "ui/events/event_utils.h"
21 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
22 24
23 #if defined(USE_X11) 25 #if defined(USE_X11)
24 #include "ui/events/x/touch_factory_x11.h" 26 #include "ui/events/x/touch_factory_x11.h"
25 #endif // defined(USE_X11) 27 #endif // defined(USE_X11)
26 28
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 PrefService* pref = g_browser_process->local_state(); 89 PrefService* pref = g_browser_process->local_state();
88 DCHECK(pref); 90 DCHECK(pref);
89 int value = pref->GetInteger(path); 91 int value = pref->GetInteger(path);
90 pref->SetInteger(path, value + 1); 92 pref->SetInteger(path, value + 1);
91 } 93 }
92 94
93 } // namespace 95 } // namespace
94 96
95 ChromeOSMetricsProvider::ChromeOSMetricsProvider() 97 ChromeOSMetricsProvider::ChromeOSMetricsProvider()
96 : registered_user_count_at_log_initialization_(false), 98 : registered_user_count_at_log_initialization_(false),
97 user_count_at_log_initialization_(0) { 99 user_count_at_log_initialization_(0),
100 weak_ptr_factory_(this) {
98 } 101 }
99 102
100 ChromeOSMetricsProvider::~ChromeOSMetricsProvider() { 103 ChromeOSMetricsProvider::~ChromeOSMetricsProvider() {
101 } 104 }
102 105
103 // static 106 // static
104 void ChromeOSMetricsProvider::RegisterPrefs(PrefRegistrySimple* registry) { 107 void ChromeOSMetricsProvider::RegisterPrefs(PrefRegistrySimple* registry) {
105 registry->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0); 108 registry->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0);
106 registry->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0); 109 registry->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0);
107 registry->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, 0); 110 registry->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, 0);
(...skipping 17 matching lines...) Expand all
125 128
126 void ChromeOSMetricsProvider::OnDidCreateMetricsLog() { 129 void ChromeOSMetricsProvider::OnDidCreateMetricsLog() {
127 registered_user_count_at_log_initialization_ = false; 130 registered_user_count_at_log_initialization_ = false;
128 if (chromeos::UserManager::IsInitialized()) { 131 if (chromeos::UserManager::IsInitialized()) {
129 registered_user_count_at_log_initialization_ = true; 132 registered_user_count_at_log_initialization_ = true;
130 user_count_at_log_initialization_ = 133 user_count_at_log_initialization_ =
131 chromeos::UserManager::Get()->GetLoggedInUsers().size(); 134 chromeos::UserManager::Get()->GetLoggedInUsers().size();
132 } 135 }
133 } 136 }
134 137
138 void ChromeOSMetricsProvider::InitTaskGetHardwareClass(
139 const base::Closure& callback) {
140 // Run the (potentially expensive) task on the FILE thread to avoid blocking
141 // the UI thread.
142 content::BrowserThread::PostTask(
143 content::BrowserThread::FILE,
144 FROM_HERE,
145 base::Bind(&ChromeOSMetricsProvider::InitTaskGetHardwareClassOnFileThread,
146 weak_ptr_factory_.GetWeakPtr(),
147 base::MessageLoop::current()->message_loop_proxy(),
148 callback));
Alexei Svitkine (slow) 2014/05/28 15:50:10 Can you avoid passing the two params by using Post
blundell 2014/05/28 18:39:35 Done.
149 }
150
151 void ChromeOSMetricsProvider::InitTaskGetHardwareClassOnFileThread(
152 base::MessageLoopProxy* target_loop,
153 const base::Closure& callback) {
154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
155
156 chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
157 "hardware_class", &hardware_class_);
158
159 target_loop->PostTask(FROM_HERE, callback);
160 }
161
135 void ChromeOSMetricsProvider::ProvideSystemProfileMetrics( 162 void ChromeOSMetricsProvider::ProvideSystemProfileMetrics(
136 metrics::SystemProfileProto* system_profile_proto) { 163 metrics::SystemProfileProto* system_profile_proto) {
137 std::vector<PerfDataProto> perf_data; 164 std::vector<PerfDataProto> perf_data;
138 if (perf_provider_.GetPerfData(&perf_data)) { 165 if (perf_provider_.GetPerfData(&perf_data)) {
139 for (std::vector<PerfDataProto>::iterator iter = perf_data.begin(); 166 for (std::vector<PerfDataProto>::iterator iter = perf_data.begin();
140 iter != perf_data.end(); 167 iter != perf_data.end();
141 ++iter) { 168 ++iter) {
142 uma_proto_->add_perf_data()->Swap(&(*iter)); 169 uma_proto_->add_perf_data()->Swap(&(*iter));
143 } 170 }
144 } 171 }
145 172
146 WriteBluetoothProto(system_profile_proto); 173 WriteBluetoothProto(system_profile_proto);
147 UpdateMultiProfileUserCount(system_profile_proto); 174 UpdateMultiProfileUserCount(system_profile_proto);
148 175
149 metrics::SystemProfileProto::Hardware* hardware = 176 metrics::SystemProfileProto::Hardware* hardware =
150 system_profile_proto->mutable_hardware(); 177 system_profile_proto->mutable_hardware();
178 hardware->set_hardware_class(hardware_class_);
151 gfx::Display::TouchSupport has_touch = ui::GetInternalDisplayTouchSupport(); 179 gfx::Display::TouchSupport has_touch = ui::GetInternalDisplayTouchSupport();
152 if (has_touch == gfx::Display::TOUCH_SUPPORT_AVAILABLE) 180 if (has_touch == gfx::Display::TOUCH_SUPPORT_AVAILABLE)
153 hardware->set_internal_display_supports_touch(true); 181 hardware->set_internal_display_supports_touch(true);
154 else if (has_touch == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE) 182 else if (has_touch == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE)
155 hardware->set_internal_display_supports_touch(false); 183 hardware->set_internal_display_supports_touch(false);
156 WriteExternalTouchscreensProto(hardware); 184 WriteExternalTouchscreensProto(hardware);
157 } 185 }
158 186
159 void ChromeOSMetricsProvider::ProvideStabilityMetrics( 187 void ChromeOSMetricsProvider::ProvideStabilityMetrics(
160 metrics::SystemProfileProto* system_profile_proto) { 188 metrics::SystemProfileProto* system_profile_proto) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 282 }
255 283
256 system_profile_proto->set_multi_profile_user_count(user_count); 284 system_profile_proto->set_multi_profile_user_count(user_count);
257 } 285 }
258 } 286 }
259 287
260 void ChromeOSMetricsProvider::SetBluetoothAdapter( 288 void ChromeOSMetricsProvider::SetBluetoothAdapter(
261 scoped_refptr<device::BluetoothAdapter> adapter) { 289 scoped_refptr<device::BluetoothAdapter> adapter) {
262 adapter_ = adapter; 290 adapter_ = adapter;
263 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698