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

Side by Side Diff: device/battery/battery_monitor_impl.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 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
« no previous file with comments | « device/battery/battery_monitor_impl.h ('k') | device/generic_sensor/sensor_impl.h » ('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 "device/battery/battery_monitor_impl.h" 5 #include "device/battery/battery_monitor_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
11 12
12 namespace device { 13 namespace device {
13 14
14 // static 15 // static
15 void BatteryMonitorImpl::Create( 16 void BatteryMonitorImpl::Create(BatteryMonitorRequest request) {
16 mojo::InterfaceRequest<BatteryMonitor> request) { 17 mojo::MakeStrongBinding(base::MakeUnique<BatteryMonitorImpl>(),
17 new BatteryMonitorImpl(std::move(request)); 18 std::move(request));
18 } 19 }
19 20
20 BatteryMonitorImpl::BatteryMonitorImpl( 21 BatteryMonitorImpl::BatteryMonitorImpl() : status_to_report_(false) {
21 mojo::InterfaceRequest<BatteryMonitor> request)
22 : binding_(this, std::move(request)), status_to_report_(false) {
23 // NOTE: DidChange may be called before AddCallback returns. This is done to 22 // NOTE: DidChange may be called before AddCallback returns. This is done to
24 // report current status. 23 // report current status.
25 subscription_ = BatteryStatusService::GetInstance()->AddCallback( 24 subscription_ = BatteryStatusService::GetInstance()->AddCallback(
26 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this))); 25 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this)));
27 } 26 }
28 27
29 BatteryMonitorImpl::~BatteryMonitorImpl() { 28 BatteryMonitorImpl::~BatteryMonitorImpl() {
30 } 29 }
31 30
32 void BatteryMonitorImpl::QueryNextStatus( 31 void BatteryMonitorImpl::QueryNextStatus(
(...skipping 21 matching lines...) Expand all
54 } 53 }
55 54
56 void BatteryMonitorImpl::ReportStatus() { 55 void BatteryMonitorImpl::ReportStatus() {
57 callback_.Run(status_.Clone()); 56 callback_.Run(status_.Clone());
58 callback_.Reset(); 57 callback_.Reset();
59 58
60 status_to_report_ = false; 59 status_to_report_ = false;
61 } 60 }
62 61
63 } // namespace device 62 } // namespace device
OLDNEW
« no previous file with comments | « device/battery/battery_monitor_impl.h ('k') | device/generic_sensor/sensor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698