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

Side by Side Diff: ash/content/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: Reduce Singleton Usage Created 6 years 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/content/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_chromeos.h"
10 #include "ui/accelerometer/accelerometer_types.h"
11
12 namespace ash {
13
14 SensorManagerDelegateChromeOS::SensorManagerDelegateChromeOS() {
15 content::SensorManagerDelegateChromeOS::SetDelegate(this);
16 }
17
18 SensorManagerDelegateChromeOS::~SensorManagerDelegateChromeOS() {
19 // Ensure we have stopped observing when shutdown.
20 StopFetchingDeviceOrientationData();
21 // Content Shell will have closed itself, do not remove as delegate
timvolodine 2014/11/26 19:32:19 nit: "." and the end also not sure what this comme
jonross 2014/11/26 23:17:56 When this class is being destructed, content::Sens
22 }
23
24 void SensorManagerDelegateChromeOS::OnAccelerometerUpdated(
25 const ui::AccelerometerUpdate& update) {
26 ui::AccelerometerSource source;
27
28 if (update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) {
29 source = ui::ACCELEROMETER_SOURCE_SCREEN;
30 } else if (update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
31 source = ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD;
32 } else {
33 return;
34 }
35
36 orientation_callback_.Run(update.get(source).x(), update.get(source).y(),
37 update.get(source).z());
38 }
39
40 void SensorManagerDelegateChromeOS::StartFetchingDeviceOrientationData(
41 const content::OrientationDataCallback& callback) {
42 DCHECK(orientation_callback_.is_null());
43 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
44 orientation_callback_ = callback;
45 }
46
47 void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
48 if (!orientation_callback_.is_null())
49 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
50 orientation_callback_.Reset();
51 }
52
53 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698