OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cmath> | 5 #include <cmath> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 size_t data_size = sizeof(GamepadHardwareBuffer); | 106 size_t data_size = sizeof(GamepadHardwareBuffer); |
107 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 107 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
108 if (monitor) | 108 if (monitor) |
109 monitor->AddDevicesChangedObserver(this); | 109 monitor->AddDevicesChangedObserver(this); |
110 bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); | 110 bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); |
111 CHECK(res); | 111 CHECK(res); |
112 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 112 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
113 memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); | 113 memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); |
114 | 114 |
115 polling_thread_.reset(new base::Thread("Gamepad polling thread")); | 115 polling_thread_.reset(new base::Thread("Gamepad polling thread")); |
116 polling_thread_->StartWithOptions( | 116 #if defined(OS_MACOSX) |
117 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 117 // On Mac, the data fetcher uses IOKit which depends on CFRunLoop, so the |
| 118 // message loop needs to be a UI-type loop. |
| 119 const base::MessageLoop::Type kMessageLoopType = base::MessageLoop::TYPE_UI; |
| 120 #else |
| 121 // On Linux, the data fetcher needs to watch file descriptors, so the message |
| 122 // loop needs to be a libevent loop. On Windows it doesn't matter what the |
| 123 // loop is. |
| 124 const base::MessageLoop::Type kMessageLoopType = base::MessageLoop::TYPE_IO; |
| 125 #endif |
| 126 polling_thread_->StartWithOptions(base::Thread::Options(kMessageLoopType, 0)); |
118 | 127 |
119 polling_thread_->message_loop()->PostTask( | 128 polling_thread_->message_loop()->PostTask( |
120 FROM_HERE, | 129 FROM_HERE, |
121 base::Bind(&GamepadProvider::DoInitializePollingThread, | 130 base::Bind(&GamepadProvider::DoInitializePollingThread, |
122 base::Unretained(this), | 131 base::Unretained(this), |
123 base::Passed(&fetcher))); | 132 base::Passed(&fetcher))); |
124 } | 133 } |
125 | 134 |
126 void GamepadProvider::DoInitializePollingThread( | 135 void GamepadProvider::DoInitializePollingThread( |
127 scoped_ptr<GamepadDataFetcher> fetcher) { | 136 scoped_ptr<GamepadDataFetcher> fetcher) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) { | 211 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) { |
203 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { | 212 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { |
204 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE, | 213 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE, |
205 user_gesture_observers_[i].closure); | 214 user_gesture_observers_[i].closure); |
206 } | 215 } |
207 user_gesture_observers_.clear(); | 216 user_gesture_observers_.clear(); |
208 } | 217 } |
209 } | 218 } |
210 | 219 |
211 } // namespace content | 220 } // namespace content |
OLD | NEW |