Files.app: Stop to use file system URLs having externalfile:// scheme origin internally.
[chromium-blink-merge.git] / chromeos / accelerometer / accelerometer_reader.h
blob79821ac61479716f9cecdfb1b0913d8bce293867
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.
5 #ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
6 #define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "chromeos/chromeos_export.h"
12 #include "ui/accelerometer/accelerometer_types.h"
14 namespace base {
15 class TaskRunner;
18 namespace chromeos {
20 // Reads an accelerometer device and reports data back to an
21 // AccelerometerDelegate.
22 class CHROMEOS_EXPORT AccelerometerReader {
23 public:
24 // Configuration structure for accelerometer device.
25 struct ConfigurationData {
26 ConfigurationData();
27 ~ConfigurationData();
29 // Number of accelerometers on device.
30 size_t count;
32 // Length of accelerometer updates.
33 size_t length;
35 // Which accelerometers are present on device.
36 bool has[ui::ACCELEROMETER_SOURCE_COUNT];
38 // Scale of accelerometers (i.e. raw value * scale = m/s^2).
39 float scale[ui::ACCELEROMETER_SOURCE_COUNT][3];
41 // Index of each accelerometer axis in data stream.
42 int index[ui::ACCELEROMETER_SOURCE_COUNT][3];
44 typedef base::RefCountedData<ConfigurationData> Configuration;
45 typedef base::RefCountedData<char[12]> Reading;
47 // An interface to receive data from the AccelerometerReader.
48 class Delegate {
49 public:
50 virtual void HandleAccelerometerUpdate(
51 const ui::AccelerometerUpdate& update) = 0;
54 AccelerometerReader(scoped_refptr<base::TaskRunner> blocking_task_runner,
55 Delegate* delegate);
56 ~AccelerometerReader();
58 private:
59 // Dispatched when initialization is complete. If |success|, |configuration|
60 // provides the details of the detected accelerometer.
61 void OnInitialized(scoped_refptr<Configuration> configuration, bool success);
63 // Triggers an asynchronous read from the accelerometer, signalling
64 // OnDataRead with the result.
65 void TriggerRead();
67 // If |success|, converts the raw reading to an AccelerometerUpdate
68 // message and notifies the |delegate_| with the new readings.
69 // Triggers another read from the accelerometer at the current sampling rate.
70 void OnDataRead(scoped_refptr<Reading> reading, bool success);
72 // The task runner to use for blocking tasks.
73 scoped_refptr<base::TaskRunner> task_runner_;
75 // A weak pointer to the delegate to send accelerometer readings to.
76 Delegate* delegate_;
78 // The last seen accelerometer data.
79 ui::AccelerometerUpdate update_;
81 // The accelerometer configuration.
82 scoped_refptr<Configuration> configuration_;
84 base::WeakPtrFactory<AccelerometerReader> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
89 } // namespace chromeos
91 #endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_