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

Side by Side Diff: services/device/battery/android/java/src/org/chromium/device/battery/BatteryMonitorFactory.java

Issue 2847523002: Android: Remove GetApplicationContext part 4 (Closed)
Patch Set: Rebase and fix build Created 3 years, 7 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 package org.chromium.device.battery; 5 package org.chromium.device.battery;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 8
9 import org.chromium.base.Log; 9 import org.chromium.base.Log;
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
(...skipping 26 matching lines...) Expand all
37 37
38 List<BatteryMonitorImpl> monitors = new ArrayList<>(mSubscribedMonit ors); 38 List<BatteryMonitorImpl> monitors = new ArrayList<>(mSubscribedMonit ors);
39 for (BatteryMonitorImpl monitor : monitors) { 39 for (BatteryMonitorImpl monitor : monitors) {
40 monitor.didChange(batteryStatus); 40 monitor.didChange(batteryStatus);
41 } 41 }
42 } 42 }
43 }; 43 };
44 44
45 public BatteryMonitorFactory(Context applicationContext) { 45 public BatteryMonitorFactory(Context applicationContext) {
46 assert applicationContext != null; 46 assert applicationContext != null;
47 mManager = new BatteryStatusManager(applicationContext, mCallback); 47 mManager = new BatteryStatusManager(mCallback);
48 } 48 }
49 49
50 @Override 50 @Override
51 public BatteryMonitor createImpl() { 51 public BatteryMonitor createImpl() {
52 ThreadUtils.assertOnUiThread(); 52 ThreadUtils.assertOnUiThread();
53 53
54 if (mSubscribedMonitors.isEmpty() && !mManager.start()) { 54 if (mSubscribedMonitors.isEmpty() && !mManager.start()) {
55 Log.e(TAG, "BatteryStatusManager failed to start."); 55 Log.e(TAG, "BatteryStatusManager failed to start.");
56 } 56 }
57 // TODO(ppi): record the "BatteryStatus.StartAndroid" histogram here onc e we have a Java API 57 // TODO(ppi): record the "BatteryStatus.StartAndroid" histogram here onc e we have a Java API
58 // for UMA - http://crbug.com/442300. 58 // for UMA - http://crbug.com/442300.
59 59
60 BatteryMonitorImpl monitor = new BatteryMonitorImpl(this); 60 BatteryMonitorImpl monitor = new BatteryMonitorImpl(this);
61 mSubscribedMonitors.add(monitor); 61 mSubscribedMonitors.add(monitor);
62 return monitor; 62 return monitor;
63 } 63 }
64 64
65 void unsubscribe(BatteryMonitorImpl monitor) { 65 void unsubscribe(BatteryMonitorImpl monitor) {
66 ThreadUtils.assertOnUiThread(); 66 ThreadUtils.assertOnUiThread();
67 67
68 assert mSubscribedMonitors.contains(monitor); 68 assert mSubscribedMonitors.contains(monitor);
69 mSubscribedMonitors.remove(monitor); 69 mSubscribedMonitors.remove(monitor);
70 if (mSubscribedMonitors.isEmpty()) { 70 if (mSubscribedMonitors.isEmpty()) {
71 mManager.stop(); 71 mManager.stop();
72 } 72 }
73 } 73 }
74 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698