Chromium Code Reviews| Index: content/browser/device_sensors/sensor_manager_chromeos.h |
| diff --git a/content/browser/device_sensors/sensor_manager_chromeos.h b/content/browser/device_sensors/sensor_manager_chromeos.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..590fdd30bd6403930554b8f2d622c1526e4ca000 |
| --- /dev/null |
| +++ b/content/browser/device_sensors/sensor_manager_chromeos.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |
| +#define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/synchronization/lock.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
| +#include "content/public/browser/sensor_manager_delegate_chromeos.h" |
| + |
| +template <typename T> |
| +struct DefaultSingletonTraits; |
| + |
| +namespace content { |
| + |
| +class SensorManagerChromeOSTest; |
|
timvolodine
2014/11/28 17:46:06
no need for this?
jonross
2014/12/02 16:13:36
Currently used for calling OnAccelerationIncluding
timvolodine
2014/12/03 13:19:55
I think you can drop this line, you already have a
|
| +class SensorManagerDelegateChromeOS; |
| + |
| +// Notifies Chrome OS sensors to start and stop observing accelerometer sensors. |
| +// Provides a callback, which interprets accelerometer data for |
| +// Device Orientation events. |
| +class CONTENT_EXPORT SensorManagerChromeOS |
| + : public base::RefCountedThreadSafe<SensorManagerChromeOS> { |
|
timvolodine
2014/11/26 19:32:19
are you sure about this? the class is a singleton
jonross
2014/11/26 23:17:56
This is based on the example from callback.h for b
timvolodine
2014/11/28 17:46:06
normally you can ensure the callback of a singleto
|
| + public: |
| + // Retrieves the singleton instance. |
| + static SensorManagerChromeOS* GetInstance(); |
|
timvolodine
2014/11/26 19:32:19
ideally we should get rid of this singleton as wel
jonross
2014/12/02 16:13:36
Done.
|
| + |
| + // Sets the delegate which observes accelerometer events. |
| + void SetDelegate(SensorManagerDelegateChromeOS* delegate); |
| + |
| + // Begins monitoring of orientation events, the shared memory of |buffer| will |
| + // be updated upon subsequent events. |
| + bool StartFetchingDeviceOrientationData( |
| + DeviceOrientationHardwareBuffer* buffer); |
| + |
| + // Stops monitoring orientation events. |
| + void StopFetchingDeviceOrientationData(); |
| + |
| + protected: |
| + virtual ~SensorManagerChromeOS(); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<SensorManagerChromeOS>; |
| + friend class SensorManagerChromeOSTest; |
| + friend struct DefaultSingletonTraits<SensorManagerChromeOS>; |
| + |
| + // Shared memory to to update. |
| + DeviceOrientationHardwareBuffer* orientation_buffer_; |
| + |
| + // Synchronize orientation_buffer_ across threads. |
| + base::Lock orientation_buffer_lock_; |
| + |
| + // Thread safe tracking of callback for Chrome OS sensors. |
| + scoped_refptr<SensorManagerChromeOS> callback_ref_; |
| + |
| + // Platform delegate that receives actual accelerometer updates, and provides |
| + // them via a callback. |
| + SensorManagerDelegateChromeOS* delegate_; |
|
timvolodine
2014/11/26 19:32:19
I assume Shell owns (and destructs) this. it's pro
jonross
2014/11/26 23:17:56
After the Shell destructs delegate_ it cannot be u
timvolodine
2014/11/28 17:46:06
ok, that's what I was wondering: the order of dest
jonross
2014/12/02 16:13:36
Extra documentation and a TODO added.
|
| + |
| + SensorManagerChromeOS(); |
|
timvolodine
2014/11/26 19:32:19
this should come before the members
jonross
2014/12/02 16:13:36
Done.
|
| + |
| + // Callback that receives accelerometer events. These events are interpreted |
| + // into orientation events. |
| + void OnAccelerationIncludingGravity(double x, double y, double z); |
|
timvolodine
2014/11/26 19:32:19
this also before the members
jonross
2014/12/02 16:13:36
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOS); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |