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

Side by Side Diff: ash/accelerometer/sensor_manager_delegate_chromeos.cc

Issue 680383007: DeviceOrientation API on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove implementation details from content/public/browser Created 6 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/accelerometer/sensor_manager_delegate_chromeos.h"
6
7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/shell.h"
9 #include "content/public/browser/sensor_manager_delegate.h"
10 #include "ui/accelerometer/accelerometer_types.h"
11
12 namespace ash {
13
14 SensorManagerDelegateChromeOS::SensorManagerDelegateChromeOS()
15 : observing_accelerometer_(false) {
16 content::SensorManagerDelegate::SetDelegate(this);
17 }
18
19 SensorManagerDelegateChromeOS::~SensorManagerDelegateChromeOS() {
20 // Remove self as observer, if still active during shutdown.
21 if (observing_accelerometer_)
flackr 2014/11/13 00:07:34 Call StopFetchingDeviceOrientationData?
jonross 2014/11/13 01:34:05 Done.
22 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
23 // Content Shell will have closed itself, do not remove as delegate
24 }
25
26 void SensorManagerDelegateChromeOS::OnAccelerometerUpdated(
27 const ui::AccelerometerUpdate& update) {
28 ui::AccelerometerSource source;
29
30 if (update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) {
31 source = ui::ACCELEROMETER_SOURCE_SCREEN;
32 } else if (update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
33 source = ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD;
34 } else {
35 return;
36 }
37
38 double x = update.get(source).x();
39 double y = update.get(source).y();
40 double z = update.get(source).z();
flackr 2014/11/13 00:07:34 Variables only used once, just call update.get(sou
jonross 2014/11/13 01:34:05 Done.
41 orientation_callback_.Run(x, y, z);
42 }
43
44 void SensorManagerDelegateChromeOS::StartFetchingDeviceOrientationData(
45 const base::Callback<void(double, double, double)>& callback) {
46 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
47 orientation_callback_ = callback;
flackr 2014/11/13 00:07:34 maybe D?CHECK(orientation_callback_.is_null()) to
jonross 2014/11/13 01:34:05 Done.
48 observing_accelerometer_ = true;
49 }
50
51 void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
52 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
53 observing_accelerometer_ = false;
flackr 2014/11/13 00:07:34 orientation_callback_.Reset();
jonross 2014/11/13 01:34:05 Done.
54 }
55
56 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698