OLD | NEW |
(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.h" |
| 10 #include "ui/accelerometer/accelerometer_types.h" |
| 11 |
| 12 namespace ash { |
| 13 |
| 14 SensorManagerDelegateChromeOS::SensorManagerDelegateChromeOS() { |
| 15 content::SensorManagerDelegate::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 |
| 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 |
OLD | NEW |