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

Side by Side Diff: content/browser/battery_status/battery_status_manager_linux.cc

Issue 480113003: Battery Status API: add UMA logging for Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added enum for "5+" label Created 6 years, 4 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/battery_status/battery_status_manager_linux.h" 5 #include "content/browser/battery_status/battery_status_manager_linux.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/histogram.h"
8 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "content/browser/battery_status/battery_status_manager.h" 11 #include "content/browser/battery_status/battery_status_manager.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "dbus/bus.h" 13 #include "dbus/bus.h"
13 #include "dbus/message.h" 14 #include "dbus/message.h"
14 #include "dbus/object_path.h" 15 #include "dbus/object_path.h"
15 #include "dbus/object_proxy.h" 16 #include "dbus/object_proxy.h"
16 #include "dbus/property.h" 17 #include "dbus/property.h"
17 #include "dbus/values_util.h" 18 #include "dbus/values_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 proxy->CallMethodAndBlock(&method_call, 90 proxy->CallMethodAndBlock(&method_call,
90 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 91 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
91 92
92 if (response) { 93 if (response) {
93 dbus::MessageReader reader(response.get()); 94 dbus::MessageReader reader(response.get());
94 reader.PopArrayOfObjectPaths(paths.get()); 95 reader.PopArrayOfObjectPaths(paths.get());
95 } 96 }
96 return paths.Pass();; 97 return paths.Pass();;
97 } 98 }
98 99
100 void UpdateNumberBatteriesHistogram(int count) {
101 UMA_HISTOGRAM_CUSTOM_COUNTS(
102 "BatteryStatus.NumberBatteriesLinux", count, 1, 5, 6);
103 }
104
99 // Class that represents a dedicated thread which communicates with DBus to 105 // Class that represents a dedicated thread which communicates with DBus to
100 // obtain battery information and receives battery change notifications. 106 // obtain battery information and receives battery change notifications.
101 class BatteryStatusNotificationThread : public base::Thread { 107 class BatteryStatusNotificationThread : public base::Thread {
102 public: 108 public:
103 BatteryStatusNotificationThread( 109 BatteryStatusNotificationThread(
104 const BatteryStatusService::BatteryUpdateCallback& callback) 110 const BatteryStatusService::BatteryUpdateCallback& callback)
105 : base::Thread(kBatteryNotifierThreadName), 111 : base::Thread(kBatteryNotifierThreadName),
106 callback_(callback), 112 callback_(callback),
107 battery_proxy_(NULL) {} 113 battery_proxy_(NULL) {}
108 114
(...skipping 15 matching lines...) Expand all
124 DCHECK(OnWatcherThread()); 130 DCHECK(OnWatcherThread());
125 131
126 if (system_bus_) 132 if (system_bus_)
127 return; 133 return;
128 134
129 InitDBus(); 135 InitDBus();
130 dbus::ObjectProxy* power_proxy = 136 dbus::ObjectProxy* power_proxy =
131 system_bus_->GetObjectProxy(kUPowerServiceName, 137 system_bus_->GetObjectProxy(kUPowerServiceName,
132 dbus::ObjectPath(kUPowerPath)); 138 dbus::ObjectPath(kUPowerPath));
133 scoped_ptr<PathsVector> device_paths = GetPowerSourcesPaths(power_proxy); 139 scoped_ptr<PathsVector> device_paths = GetPowerSourcesPaths(power_proxy);
140 int num_batteries = 0;
134 141
135 for (size_t i = 0; i < device_paths->size(); ++i) { 142 for (size_t i = 0; i < device_paths->size(); ++i) {
136 const dbus::ObjectPath& device_path = device_paths->at(i); 143 const dbus::ObjectPath& device_path = device_paths->at(i);
137 dbus::ObjectProxy* device_proxy = system_bus_->GetObjectProxy( 144 dbus::ObjectProxy* device_proxy = system_bus_->GetObjectProxy(
138 kUPowerServiceName, device_path); 145 kUPowerServiceName, device_path);
139 scoped_ptr<base::DictionaryValue> dictionary = 146 scoped_ptr<base::DictionaryValue> dictionary =
140 GetPropertiesAsDictionary(device_proxy); 147 GetPropertiesAsDictionary(device_proxy);
141 148
142 if (!dictionary) 149 if (!dictionary)
143 continue; 150 continue;
144 151
145 bool is_present = GetPropertyAsBoolean(*dictionary, "IsPresent", false); 152 bool is_present = GetPropertyAsBoolean(*dictionary, "IsPresent", false);
146 uint32 type = static_cast<uint32>( 153 uint32 type = static_cast<uint32>(
147 GetPropertyAsDouble(*dictionary, "Type", UPOWER_DEVICE_TYPE_UNKNOWN)); 154 GetPropertyAsDouble(*dictionary, "Type", UPOWER_DEVICE_TYPE_UNKNOWN));
148 155
149 if (!is_present || type != UPOWER_DEVICE_TYPE_BATTERY) { 156 if (!is_present || type != UPOWER_DEVICE_TYPE_BATTERY) {
150 system_bus_->RemoveObjectProxy(kUPowerServiceName, 157 system_bus_->RemoveObjectProxy(kUPowerServiceName,
151 device_path, 158 device_path,
152 base::Bind(&base::DoNothing)); 159 base::Bind(&base::DoNothing));
153 continue; 160 continue;
154 } 161 }
155 162
156 if (battery_proxy_) { 163 if (battery_proxy_) {
157 // TODO(timvolodine): add support for multiple batteries. Currently we 164 // TODO(timvolodine): add support for multiple batteries. Currently we
158 // only collect information from the first battery we encounter 165 // only collect information from the first battery we encounter
159 // (crbug.com/400780). 166 // (crbug.com/400780).
160 // TODO(timvolodine): add UMA logging for this case.
161 LOG(WARNING) << "multiple batteries found, " 167 LOG(WARNING) << "multiple batteries found, "
162 << "using status data of the first battery only."; 168 << "using status data of the first battery only.";
163 } else { 169 } else {
164 battery_proxy_ = device_proxy; 170 battery_proxy_ = device_proxy;
165 } 171 }
172 num_batteries++;
166 } 173 }
167 174
175 UpdateNumberBatteriesHistogram(num_batteries);
176
168 if (!battery_proxy_) { 177 if (!battery_proxy_) {
169 callback_.Run(blink::WebBatteryStatus()); 178 callback_.Run(blink::WebBatteryStatus());
170 return; 179 return;
171 } 180 }
172 181
173 battery_proxy_->ConnectToSignal( 182 battery_proxy_->ConnectToSignal(
174 kUPowerDeviceName, 183 kUPowerDeviceName,
175 kUPowerDeviceSignalChanged, 184 kUPowerDeviceSignalChanged,
176 base::Bind(&BatteryStatusNotificationThread::BatteryChanged, 185 base::Bind(&BatteryStatusNotificationThread::BatteryChanged,
177 base::Unretained(this)), 186 base::Unretained(this)),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 374 }
366 375
367 // static 376 // static
368 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( 377 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create(
369 const BatteryStatusService::BatteryUpdateCallback& callback) { 378 const BatteryStatusService::BatteryUpdateCallback& callback) {
370 return scoped_ptr<BatteryStatusManager>( 379 return scoped_ptr<BatteryStatusManager>(
371 new BatteryStatusManagerLinux(callback)); 380 new BatteryStatusManagerLinux(callback));
372 } 381 }
373 382
374 } // namespace content 383 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698