Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / system / orientation_controller.h
blob93887889e50bdb22cdb66237d79c385e8336150d
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 ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_
6 #define ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_
8 #include "athena/system/device_socket_listener.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "ui/gfx/display.h"
15 namespace base {
16 class FilePath;
17 class FilePathWatcher;
18 class TaskRunner;
21 namespace athena {
23 // Monitors accelerometers, detecting orientation changes. When a change is
24 // detected rotates the root window to match.
25 class OrientationController
26 : public DeviceSocketListener,
27 public base::RefCountedThreadSafe<OrientationController> {
28 public:
29 OrientationController();
31 void InitWith(scoped_refptr<base::TaskRunner> file_task_runner);
33 void Shutdown();
35 private:
36 friend class base::RefCountedThreadSafe<OrientationController>;
38 virtual ~OrientationController();
40 void ShutdownOnFILE();
41 // Watch for the socket path to be created, called on the FILE thread.
42 void WatchForSocketPathOnFILE();
43 void OnFilePathChangedOnFILE(const base::FilePath& path, bool error);
45 // Overridden from device::DeviceSocketListener:
46 virtual void OnDataAvailableOnFILE(const void* data) OVERRIDE;
48 // Rotates the display to |rotation|, called on the UI thread.
49 void RotateOnUI(gfx::Display::Rotation rotation);
51 // The last configured rotation.
52 gfx::Display::Rotation current_rotation_;
54 // The timestamp of the last applied orientation change.
55 int64_t last_orientation_change_time_;
57 // True if the OrientaionController has already been shutdown.
58 // This is initialized on UI thread, but must be accessed / modified
59 // only on FILE thread.
60 bool shutdown_;
62 // A task runner for the UI thread.
63 scoped_refptr<base::TaskRunner> ui_task_runner_;
65 // A task runner for the FILE thread.
66 scoped_refptr<base::TaskRunner> file_task_runner_;
68 // File path watcher used to detect when sensors are present.
69 scoped_ptr<base::FilePathWatcher> watcher_;
71 DISALLOW_COPY_AND_ASSIGN(OrientationController);
74 } // namespace athena
76 #endif // ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_