• 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 ash {
22 
23 class AccelerometerObserver;
24 
25 // This class owns the communication interface for talking to the accelerometer
26 // on supporting devices. Observers will be delivered OnAccelerometerRead
27 // notifications if an accelerometer was detected.
28 class ASH_EXPORT AccelerometerController
29 #if defined(OS_CHROMEOS)
30     : public chromeos::AccelerometerReader::Delegate {
31 #else
32     {
33 #endif
34  public:
35   AccelerometerController();
36   virtual ~AccelerometerController();
37 
38   // Initialize the accelerometer reader.
39   void Initialize(scoped_refptr<base::TaskRunner> blocking_task_runner);
40 
41   // Add/remove observer.
42   void AddObserver(AccelerometerObserver* observer);
43   void RemoveObserver(AccelerometerObserver* observer);
44 
45 #if defined(OS_CHROMEOS)
46   // This needs to be CHROMEOS only as on other platforms it does not actually
47   // override a method.
48   // chromeos::AccelerometerReader::Delegate:
49   virtual void HandleAccelerometerUpdate(
50       const ui::AccelerometerUpdate& update) OVERRIDE;
51 #endif
52 
53  private:
54 #if defined(OS_CHROMEOS)
55   // The AccelerometerReader which directly triggers and reads from the
56   // accelerometer device.
57   scoped_ptr<chromeos::AccelerometerReader> reader_;
58 #endif
59 
60   ObserverList<AccelerometerObserver, true> observers_;
61 
62   DISALLOW_COPY_AND_ASSIGN(AccelerometerController);
63 };
64 
65 }  // namespace ash
66 
67 #endif  // ASH_ACCELEROMETER_ACCELEROMETER_CONTROLLER_H_
68