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

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

Issue 556873004: Battery Status API: add UMA logging for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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_win.h" 5 #include "content/browser/battery_status/battery_status_manager_win.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/metrics/histogram.h"
8 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
9 #include "base/win/message_window.h" 10 #include "base/win/message_window.h"
10 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
11 #include "content/browser/battery_status/battery_status_manager.h" 12 #include "content/browser/battery_status/battery_status_manager.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 namespace { 17 namespace {
17 18
18 typedef BatteryStatusService::BatteryUpdateCallback BatteryCallback; 19 typedef BatteryStatusService::BatteryUpdateCallback BatteryCallback;
19 20
20 const wchar_t kWindowClassName[] = L"BatteryStatusMessageWindow"; 21 const wchar_t kWindowClassName[] = L"BatteryStatusMessageWindow";
21 22
23 // This enum is used for histogram. Don't change the order of the existing
24 // values.
25 enum NumberBatteriesType {
26 NO_BATTERY = 0,
27 ONE_OR_MORE_BATTERIES = 1,
28 UNKNOWN_BATTERIES = 2,
29 BATTERY_TYPES_COUNT = 3,
30 };
31
32 void UpdateNumberBatteriesHistogram(NumberBatteriesType count) {
33 UMA_HISTOGRAM_ENUMERATION("BatteryStatus.NumberBatteriesWin",
34 count,
35 BATTERY_TYPES_COUNT);
36 }
37
38 void UpdateNumberBatteriesHistogram() {
39 SYSTEM_POWER_STATUS win_status;
40 if (!GetSystemPowerStatus(&win_status)) {
41 UpdateNumberBatteriesHistogram(UNKNOWN_BATTERIES);
42 return;
43 }
44
45 if (win_status.BatteryFlag == 255)
46 UpdateNumberBatteriesHistogram(UNKNOWN_BATTERIES);
47 else if (win_status.BatteryFlag == 128)
48 UpdateNumberBatteriesHistogram(NO_BATTERY);
49 else
50 UpdateNumberBatteriesHistogram(ONE_OR_MORE_BATTERIES);
51 }
52
22 // Message-only window for handling battery changes on Windows. 53 // Message-only window for handling battery changes on Windows.
23 class BatteryStatusObserver 54 class BatteryStatusObserver
24 : public base::RefCountedThreadSafe<BatteryStatusObserver> { 55 : public base::RefCountedThreadSafe<BatteryStatusObserver> {
25 public: 56 public:
26 explicit BatteryStatusObserver(const BatteryCallback& callback) 57 explicit BatteryStatusObserver(const BatteryCallback& callback)
27 : power_handle_(NULL), 58 : power_handle_(NULL),
28 battery_change_handle_(NULL), 59 battery_change_handle_(NULL),
29 callback_(callback) { 60 callback_(callback) {
30 } 61 }
31 62
(...skipping 29 matching lines...) Expand all
61 // versions prior to Vista, see crbug.com/402466. 92 // versions prior to Vista, see crbug.com/402466.
62 power_handle_ = 93 power_handle_ =
63 RegisterNotification(&GUID_ACDC_POWER_SOURCE); 94 RegisterNotification(&GUID_ACDC_POWER_SOURCE);
64 battery_change_handle_ = 95 battery_change_handle_ =
65 RegisterNotification(&GUID_BATTERY_PERCENTAGE_REMAINING); 96 RegisterNotification(&GUID_BATTERY_PERCENTAGE_REMAINING);
66 } else { 97 } else {
67 // Could not create a message window, execute callback with the default 98 // Could not create a message window, execute callback with the default
68 // values. 99 // values.
69 callback_.Run(blink::WebBatteryStatus()); 100 callback_.Run(blink::WebBatteryStatus());
70 } 101 }
102
103 UpdateNumberBatteriesHistogram();
71 } 104 }
72 105
73 void StopOnUI() { 106 void StopOnUI() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 if (!window_) 108 if (!window_)
76 return; 109 return;
77 110
78 if (power_handle_) 111 if (power_handle_)
79 UnregisterNotification(power_handle_); 112 UnregisterNotification(power_handle_);
80 if (battery_change_handle_) 113 if (battery_change_handle_)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 230 }
198 231
199 // static 232 // static
200 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( 233 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create(
201 const BatteryStatusService::BatteryUpdateCallback& callback) { 234 const BatteryStatusService::BatteryUpdateCallback& callback) {
202 return scoped_ptr<BatteryStatusManager>( 235 return scoped_ptr<BatteryStatusManager>(
203 new BatteryStatusManagerWin(callback)); 236 new BatteryStatusManagerWin(callback));
204 } 237 }
205 238
206 } // namespace content 239 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698