Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: athena/system/orientation_controller.cc

Issue 490033003: Fixes three crashes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path_watcher.h" 9 #include "base/files/file_path_watcher.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } // namespace 57 } // namespace
58 58
59 OrientationController::OrientationController() 59 OrientationController::OrientationController()
60 : DeviceSocketListener(kSocketPath, sizeof(DeviceSensorEvent)), 60 : DeviceSocketListener(kSocketPath, sizeof(DeviceSensorEvent)),
61 last_orientation_change_time_(0) { 61 last_orientation_change_time_(0) {
62 CHECK(base::MessageLoopForUI::current()); 62 CHECK(base::MessageLoopForUI::current());
63 ui_task_runner_ = base::MessageLoopForUI::current()->task_runner(); 63 ui_task_runner_ = base::MessageLoopForUI::current()->task_runner();
64 } 64 }
65 65
66 void OrientationController::InitWith( 66 void OrientationController::InitWith(
67 scoped_refptr<base::TaskRunner> io_task_runner) { 67 scoped_refptr<base::TaskRunner> file_task_runner) {
68 io_task_runner->PostTask(FROM_HERE, base::Bind( 68 file_task_runner->PostTask(
69 &OrientationController::WatchForSocketPathOnIO, this)); 69 FROM_HERE,
70 base::Bind(&OrientationController::WatchForSocketPathOnFILE, this));
70 } 71 }
71 72
72 OrientationController::~OrientationController() { 73 OrientationController::~OrientationController() {
73 } 74 }
74 75
75 void OrientationController::WatchForSocketPathOnIO() { 76 void OrientationController::StopWatchingSocketPath() {
flackr 2014/08/21 03:24:55 This doesn't just stop watching for the socket pat
oshima 2014/08/21 15:03:41 Done.
77 StopListening();
78 watcher_.reset();
flackr 2014/08/21 03:24:55 I don't think this is safe, since this is now call
oshima 2014/08/21 15:03:41 Thank you for the catch. Fixed. I also added shutd
79 }
80
81 void OrientationController::WatchForSocketPathOnFILE() {
76 CHECK(base::MessageLoopForIO::current()); 82 CHECK(base::MessageLoopForIO::current());
77 if (base::PathExists(base::FilePath(kSocketPath))) { 83 if (base::PathExists(base::FilePath(kSocketPath))) {
78 ui_task_runner_->PostTask(FROM_HERE, 84 ui_task_runner_->PostTask(FROM_HERE,
79 base::Bind(&OrientationController::StartListening, this)); 85 base::Bind(&OrientationController::StartListening, this));
80 } else { 86 } else {
81 watcher_.reset(new base::FilePathWatcher); 87 watcher_.reset(new base::FilePathWatcher);
82 watcher_->Watch( 88 watcher_->Watch(
83 base::FilePath(kSocketPath), false, 89 base::FilePath(kSocketPath),
84 base::Bind(&OrientationController::OnFilePathChangedOnIO, this)); 90 false,
91 base::Bind(&OrientationController::OnFilePathChangedOnFILE, this));
85 } 92 }
86 } 93 }
87 94
88 void OrientationController::OnFilePathChangedOnIO(const base::FilePath& path, 95 void OrientationController::OnFilePathChangedOnFILE(const base::FilePath& path,
89 bool error) { 96 bool error) {
90 watcher_.reset(); 97 watcher_.reset();
91 if (error) 98 if (error)
92 return; 99 return;
93 100
94 ui_task_runner_->PostTask(FROM_HERE, 101 ui_task_runner_->PostTask(FROM_HERE,
95 base::Bind(&OrientationController::StartListening, this)); 102 base::Bind(&OrientationController::StartListening, this));
96 } 103 }
97 104
98 void OrientationController::OnDataAvailableOnIO(const void* data) { 105 void OrientationController::OnDataAvailableOnFILE(const void* data) {
99 const DeviceSensorEvent* event = 106 const DeviceSensorEvent* event =
100 static_cast<const DeviceSensorEvent*>(data); 107 static_cast<const DeviceSensorEvent*>(data);
101 if (event->type != SENSOR_ACCELEROMETER) 108 if (event->type != SENSOR_ACCELEROMETER)
102 return; 109 return;
103 110
104 float gravity_x = event->data[0]; 111 float gravity_x = event->data[0];
105 float gravity_y = event->data[1]; 112 float gravity_y = event->data[1];
106 gfx::Display::Rotation rotation; 113 gfx::Display::Rotation rotation;
107 if (gravity_x < -kGravityThreshold) { 114 if (gravity_x < -kGravityThreshold) {
108 rotation = gfx::Display::ROTATE_270; 115 rotation = gfx::Display::ROTATE_270;
(...skipping 15 matching lines...) Expand all
124 } 131 }
125 132
126 last_orientation_change_time_ = event->timestamp; 133 last_orientation_change_time_ = event->timestamp;
127 current_rotation_ = rotation; 134 current_rotation_ = rotation;
128 ui_task_runner_->PostTask(FROM_HERE, 135 ui_task_runner_->PostTask(FROM_HERE,
129 base::Bind(&OrientationController::RotateOnUI, this, rotation)); 136 base::Bind(&OrientationController::RotateOnUI, this, rotation));
130 } 137 }
131 138
132 void OrientationController::RotateOnUI(gfx::Display::Rotation rotation) { 139 void OrientationController::RotateOnUI(gfx::Display::Rotation rotation) {
133 ScreenManager* screen_manager = ScreenManager::Get(); 140 ScreenManager* screen_manager = ScreenManager::Get();
134 // Since this is called from the IO thread, the screen manager may no longer 141 // Since this is called from the FILE thread, the screen manager may no longer
135 // exist. 142 // exist.
136 if (screen_manager) 143 if (screen_manager)
137 screen_manager->SetRotation(rotation); 144 screen_manager->SetRotation(rotation);
138 } 145 }
139 146
140 } // namespace athena 147 } // namespace athena
OLDNEW
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698