| 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 #include "athena/screen/public/screen_manager.h" | 5 #include "athena/screen/public/screen_manager.h" |
| 6 #include "athena/system/orientation_controller.h" | 6 #include "athena/system/orientation_controller.h" |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path_watcher.h" | 8 #include "base/files/file_path_watcher.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
| 12 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 12 | 13 |
| 13 namespace athena { | 14 namespace athena { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Threshold after which to rotate in a given direction. | 18 // Threshold after which to rotate in a given direction. |
| 18 const int kGravityThreshold = 6.0f; | 19 const int kGravityThreshold = 6.0f; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 OrientationController::OrientationController() { | 23 OrientationController::OrientationController() { |
| 23 } | 24 } |
| 24 | 25 |
| 25 void OrientationController::InitWith( | 26 void OrientationController::InitWith( |
| 26 scoped_refptr<base::TaskRunner> blocking_task_runner) { | 27 scoped_refptr<base::TaskRunner> blocking_task_runner) { |
| 27 accelerometer_reader_.reset(new chromeos::AccelerometerReader()); | 28 chromeos::AccelerometerReader::GetInstance()->Initialize( |
| 28 accelerometer_reader_->Initialize(blocking_task_runner); | 29 blocking_task_runner); |
| 29 accelerometer_reader_->AddObserver(this); | 30 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
| 30 } | 31 } |
| 31 | 32 |
| 32 OrientationController::~OrientationController() { | 33 OrientationController::~OrientationController() { |
| 33 DCHECK(!accelerometer_reader_.get()); | |
| 34 } | 34 } |
| 35 | 35 |
| 36 void OrientationController::Shutdown() { | 36 void OrientationController::Shutdown() { |
| 37 accelerometer_reader_->RemoveObserver(this); | 37 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 38 accelerometer_reader_.reset(); | |
| 39 } | 38 } |
| 40 | 39 |
| 41 void OrientationController::OnAccelerometerUpdated( | 40 void OrientationController::OnAccelerometerUpdated( |
| 42 const ui::AccelerometerUpdate& update) { | 41 const ui::AccelerometerUpdate& update) { |
| 43 if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) | 42 if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) |
| 44 return; | 43 return; |
| 45 | 44 |
| 46 float gravity_x = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).x(); | 45 float gravity_x = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).x(); |
| 47 float gravity_y = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).y(); | 46 float gravity_y = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).y(); |
| 48 gfx::Display::Rotation rotation; | 47 gfx::Display::Rotation rotation; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 } | 59 } |
| 61 | 60 |
| 62 if (rotation == current_rotation_) | 61 if (rotation == current_rotation_) |
| 63 return; | 62 return; |
| 64 | 63 |
| 65 current_rotation_ = rotation; | 64 current_rotation_ = rotation; |
| 66 ScreenManager::Get()->SetRotation(rotation); | 65 ScreenManager::Get()->SetRotation(rotation); |
| 67 } | 66 } |
| 68 | 67 |
| 69 } // namespace athena | 68 } // namespace athena |
| OLD | NEW |