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

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: Rebase Created 5 years, 11 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 | « ash/content/accelerometer/sensor_manager_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shell.h"
8 #include "chromeos/accelerometer/accelerometer_reader.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 // When this class is being destructed, content::SensorManagerDelegateChromeOS
22 // will have already been destructed. So calling SetDelegate(nullptr) to
23 // remove this class as the delegate will cause a crash.
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 orientation_callback_.Run(update.get(source).x(), update.get(source).y(),
39 update.get(source).z());
40 }
41
42 void SensorManagerDelegateChromeOS::StartFetchingDeviceOrientationData(
43 const content::OrientationDataCallback& callback) {
44 DCHECK(orientation_callback_.is_null());
45 Shell::GetInstance()->accelerometer_reader()->AddObserver(this);
46 orientation_callback_ = callback;
47 }
48
49 void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
50 if (!orientation_callback_.is_null())
51 Shell::GetInstance()->accelerometer_reader()->RemoveObserver(this);
52 orientation_callback_.Reset();
53 }
54
55 } // namespace ash
OLDNEW
« no previous file with comments | « ash/content/accelerometer/sensor_manager_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698