1 // Copyright (c) 2013 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.
5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_WIN_H_
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_WIN_H_
8 #include <SensorsApi.h>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h"
13 #include "base/win/scoped_comptr.h"
14 #include "content/browser/device_orientation/data_fetcher.h"
15 #include "content/browser/device_orientation/device_data.h"
21 // Windows implementation of DeviceOrientation API.
22 // The SensorEventSink is installed to Windows sensor thread to listen for
23 // sensor's data. Upon each notification, DataFetcherImplWin buffers the data.
24 // Then Chrome sensor polling thread pulls the buffered data via GetDeviceData.
25 // The Inclinometer 3D sensor (SENSOR_TYPE_INCLINOMETER_3D) is used to get the
28 class DataFetcherImplWin
: public DataFetcher
{
30 virtual ~DataFetcherImplWin();
32 // Factory function. It returns NULL on error.
33 // The created object listens for events for the whole lifetime.
34 static DataFetcher
* Create();
36 // Implement DataFetcher.
37 virtual const DeviceData
* GetDeviceData(DeviceData::Type type
) OVERRIDE
;
40 class SensorEventSink
;
41 friend SensorEventSink
;
45 void OnOrientationData(Orientation
* orientation
);
46 const Orientation
* GetOrientation();
48 base::win::ScopedComPtr
<ISensor
> sensor_
;
50 // Value returned by GetDeviceData.
51 scoped_refptr
<Orientation
> current_orientation_
;
53 // The 1-element buffer follows DataFetcherImplAndroid implementation.
54 // It is written by OnOrientationData and read by GetDeviceData.
55 base::Lock next_orientation_lock_
;
56 scoped_refptr
<Orientation
> next_orientation_
;
58 DISALLOW_COPY_AND_ASSIGN(DataFetcherImplWin
);
61 } // namespace content
63 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_WIN_H_