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

Side by Side Diff: content/browser/gamepad/gamepad_provider.cc

Issue 133943002: Gamepad API support for chrome on android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
15 #include "base/time/time.h"
15 #include "content/browser/gamepad/gamepad_data_fetcher.h" 16 #include "content/browser/gamepad/gamepad_data_fetcher.h"
16 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h" 17 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h"
17 #include "content/browser/gamepad/gamepad_provider.h" 18 #include "content/browser/gamepad/gamepad_provider.h"
19 #include "content/browser/gamepad/gamepad_service.h"
18 #include "content/common/gamepad_hardware_buffer.h" 20 #include "content/common/gamepad_hardware_buffer.h"
19 #include "content/common/gamepad_messages.h" 21 #include "content/common/gamepad_messages.h"
20 #include "content/common/gamepad_user_gesture.h" 22 #include "content/common/gamepad_user_gesture.h"
21 23
22 namespace content { 24 namespace content {
25 const int64 GamepadProvider::max_timestamp_before_pause_ = 500;
23 26
24 GamepadProvider::ClosureAndThread::ClosureAndThread( 27 GamepadProvider::ClosureAndThread::ClosureAndThread(
25 const base::Closure& c, 28 const base::Closure& c,
26 const scoped_refptr<base::MessageLoopProxy>& m) 29 const scoped_refptr<base::MessageLoopProxy>& m)
27 : closure(c), 30 : closure(c),
28 message_loop(m) { 31 message_loop(m) {
29 } 32 }
30 33
31 GamepadProvider::ClosureAndThread::~ClosureAndThread() { 34 GamepadProvider::ClosureAndThread::~ClosureAndThread() {
32 } 35 }
(...skipping 23 matching lines...) Expand all
56 data_fetcher_.reset(); 59 data_fetcher_.reset();
57 } 60 }
58 61
59 base::SharedMemoryHandle GamepadProvider::GetSharedMemoryHandleForProcess( 62 base::SharedMemoryHandle GamepadProvider::GetSharedMemoryHandleForProcess(
60 base::ProcessHandle process) { 63 base::ProcessHandle process) {
61 base::SharedMemoryHandle renderer_handle; 64 base::SharedMemoryHandle renderer_handle;
62 gamepad_shared_memory_.ShareToProcess(process, &renderer_handle); 65 gamepad_shared_memory_.ShareToProcess(process, &renderer_handle);
63 return renderer_handle; 66 return renderer_handle;
64 } 67 }
65 68
69 bool GamepadProvider::GetPollState() {
70 return is_paused_;
71 }
72
66 void GamepadProvider::Pause() { 73 void GamepadProvider::Pause() {
67 { 74 {
68 base::AutoLock lock(is_paused_lock_); 75 base::AutoLock lock(is_paused_lock_);
69 is_paused_ = true; 76 is_paused_ = true;
70 } 77 }
71 base::MessageLoop* polling_loop = polling_thread_->message_loop(); 78 base::MessageLoop* polling_loop = polling_thread_->message_loop();
72 polling_loop->PostTask( 79 polling_loop->PostTask(
73 FROM_HERE, 80 FROM_HERE,
74 base::Bind(&GamepadProvider::SendPauseHint, Unretained(this), true)); 81 base::Bind(&GamepadProvider::SendPauseHint, Unretained(this), true));
75 } 82 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 &hwbuf->buffer, 167 &hwbuf->buffer,
161 sizeof(blink::WebGamepads), 168 sizeof(blink::WebGamepads),
162 "Racey reads are discarded"); 169 "Racey reads are discarded");
163 170
164 { 171 {
165 base::AutoLock lock(devices_changed_lock_); 172 base::AutoLock lock(devices_changed_lock_);
166 changed = devices_changed_; 173 changed = devices_changed_;
167 devices_changed_ = false; 174 devices_changed_ = false;
168 } 175 }
169 176
177 base::TimeDelta timestamp =
178 (base::Time::NowFromSystemTime()) - (
179 GamepadService::GetInstance()->GetGamepadAccessTimestamp());
180
181 if (timestamp.InMilliseconds() > max_timestamp_before_pause_) {
182 Pause();
183 return;
184 }
185
170 // Acquire the SeqLock. There is only ever one writer to this data. 186 // Acquire the SeqLock. There is only ever one writer to this data.
171 // See gamepad_hardware_buffer.h. 187 // See gamepad_hardware_buffer.h.
172 hwbuf->sequence.WriteBegin(); 188 hwbuf->sequence.WriteBegin();
173 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed); 189 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed);
174 hwbuf->sequence.WriteEnd(); 190 hwbuf->sequence.WriteEnd();
175 191
176 CheckForUserGesture(); 192 CheckForUserGesture();
177 193
178 // Schedule our next interval of polling. 194 // Schedule our next interval of polling.
179 ScheduleDoPoll(); 195 ScheduleDoPoll();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) { 227 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) {
212 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { 228 for (size_t i = 0; i < user_gesture_observers_.size(); i++) {
213 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE, 229 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE,
214 user_gesture_observers_[i].closure); 230 user_gesture_observers_[i].closure);
215 } 231 }
216 user_gesture_observers_.clear(); 232 user_gesture_observers_.clear();
217 } 233 }
218 } 234 }
219 235
220 } // namespace content 236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698