OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ | 5 #ifndef ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ |
6 #define ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ | 6 #define ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ |
7 | 7 |
8 #include "athena/system/device_socket_listener.h" | 8 #include "athena/system/device_socket_listener.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace athena { | 21 namespace athena { |
22 | 22 |
23 // Monitors accelerometers, detecting orientation changes. When a change is | 23 // Monitors accelerometers, detecting orientation changes. When a change is |
24 // detected rotates the root window to match. | 24 // detected rotates the root window to match. |
25 class OrientationController | 25 class OrientationController |
26 : public DeviceSocketListener, | 26 : public DeviceSocketListener, |
27 public base::RefCountedThreadSafe<OrientationController> { | 27 public base::RefCountedThreadSafe<OrientationController> { |
28 public: | 28 public: |
29 OrientationController(); | 29 OrientationController(); |
30 | 30 |
31 void InitWith(scoped_refptr<base::TaskRunner> io_task_runner); | 31 void InitWith(scoped_refptr<base::TaskRunner> file_task_runner); |
| 32 |
| 33 void Shutdown(); |
32 | 34 |
33 private: | 35 private: |
34 friend class base::RefCountedThreadSafe<OrientationController>; | 36 friend class base::RefCountedThreadSafe<OrientationController>; |
35 | 37 |
36 virtual ~OrientationController(); | 38 virtual ~OrientationController(); |
37 | 39 |
38 // Watch for the socket path to be created, called on the IO thread. | 40 void ShutdownOnFILE(); |
39 void WatchForSocketPathOnIO(); | 41 // Watch for the socket path to be created, called on the FILE thread. |
40 void OnFilePathChangedOnIO(const base::FilePath& path, bool error); | 42 void WatchForSocketPathOnFILE(); |
| 43 void OnFilePathChangedOnFILE(const base::FilePath& path, bool error); |
41 | 44 |
42 // Overridden from device::DeviceSocketListener: | 45 // Overridden from device::DeviceSocketListener: |
43 virtual void OnDataAvailableOnIO(const void* data) OVERRIDE; | 46 virtual void OnDataAvailableOnFILE(const void* data) OVERRIDE; |
44 | 47 |
45 // Rotates the display to |rotation|, called on the UI thread. | 48 // Rotates the display to |rotation|, called on the UI thread. |
46 void RotateOnUI(gfx::Display::Rotation rotation); | 49 void RotateOnUI(gfx::Display::Rotation rotation); |
47 | 50 |
48 // The last configured rotation. | 51 // The last configured rotation. |
49 gfx::Display::Rotation current_rotation_; | 52 gfx::Display::Rotation current_rotation_; |
50 | 53 |
51 // The timestamp of the last applied orientation change. | 54 // The timestamp of the last applied orientation change. |
52 int64_t last_orientation_change_time_; | 55 int64_t last_orientation_change_time_; |
53 | 56 |
| 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_; |
| 61 |
54 // A task runner for the UI thread. | 62 // A task runner for the UI thread. |
55 scoped_refptr<base::TaskRunner> ui_task_runner_; | 63 scoped_refptr<base::TaskRunner> ui_task_runner_; |
56 | 64 |
| 65 // A task runner for the FILE thread. |
| 66 scoped_refptr<base::TaskRunner> file_task_runner_; |
| 67 |
57 // File path watcher used to detect when sensors are present. | 68 // File path watcher used to detect when sensors are present. |
58 scoped_ptr<base::FilePathWatcher> watcher_; | 69 scoped_ptr<base::FilePathWatcher> watcher_; |
59 | 70 |
60 DISALLOW_COPY_AND_ASSIGN(OrientationController); | 71 DISALLOW_COPY_AND_ASSIGN(OrientationController); |
61 }; | 72 }; |
62 | 73 |
63 } // namespace athena | 74 } // namespace athena |
64 | 75 |
65 #endif // ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ | 76 #endif // ATHENA_SYSTEM_ORIENTATION_CONTROLLER_H_ |
OLD | NEW |