• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ASH_ACCELEROMETER_ACCELEROMETER_CONTROLLER_H_
6 #define ASH_ACCELEROMETER_ACCELEROMETER_CONTROLLER_H_
7 
8 #include "ash/ash_export.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 
13 #if defined(OS_CHROMEOS)
14 #include "chromeos/accelerometer/accelerometer_reader.h"
15 #endif
16 
17 namespace base {
18 class TaskRunner;
19 }
20 
21 namespace gfx {
22 class Vector3dF;
23 }
24 
25 namespace ash {
26 
27 class AccelerometerObserver;
28 
29 // This class owns the communication interface for talking to the accelerometer
30 // on supporting devices. Observers will be delivered OnAccelerometerRead
31 // notifications if an accelerometer was detected.
32 class ASH_EXPORT AccelerometerController
33 #if defined(OS_CHROMEOS)
34     : public chromeos::AccelerometerReader::Delegate {
35 #else
36     {
37 #endif
38  public:
39   AccelerometerController();
40   virtual ~AccelerometerController();
41 
42   // Initialize the accelerometer reader.
43   void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner);
44 
45   // Add/remove observer.
46   void AddObserver(AccelerometerObserver* observer);
47   void RemoveObserver(AccelerometerObserver* observer);
48 
49 #if defined(OS_CHROMEOS)
50   // This needs to be CHROMEOS only as on other platforms it does not actually
51   // override a method.
52   // chromeos::AccelerometerReader::Delegate:
53   virtual void HandleAccelerometerReading(const gfx::Vector3dF& base,
54                                           const gfx::Vector3dF& lid) OVERRIDE;
55 #endif
56 
57  private:
58 #if defined(OS_CHROMEOS)
59   // The AccelerometerReader which directly triggers and reads from the
60   // accelerometer device.
61   scoped_ptr<chromeos::AccelerometerReader> reader_;
62 #endif
63 
64   ObserverList<AccelerometerObserver, true> observers_;
65 
66   DISALLOW_COPY_AND_ASSIGN(AccelerometerController);
67 };
68 
69 }  // namespace ash
70 
71 #endif  // ASH_ACCELEROMETER_ACCELEROMETER_CONTROLLER_H_
72