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

Unified Diff: content/browser/renderer_host/gamepad_browser_message_filter.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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/gamepad_browser_message_filter.cc
diff --git a/content/browser/renderer_host/gamepad_browser_message_filter.cc b/content/browser/renderer_host/gamepad_browser_message_filter.cc
index 6b5972e5a0af5c99d147919d022c3abe6456ce1d..77a0b3e3cea4b23ccf34c4eb28f223262e6ea75a 100644
--- a/content/browser/renderer_host/gamepad_browser_message_filter.cc
+++ b/content/browser/renderer_host/gamepad_browser_message_filter.cc
@@ -1,9 +1,10 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/time/time.h"
#include "content/browser/renderer_host/gamepad_browser_message_filter.h"
-
#include "content/browser/gamepad/gamepad_service.h"
#include "content/common/gamepad_messages.h"
@@ -28,6 +29,12 @@ bool GamepadBrowserMessageFilter::OnMessageReceived(
*message_was_ok)
IPC_MESSAGE_HANDLER(GamepadHostMsg_StartPolling, OnGamepadStartPolling)
IPC_MESSAGE_HANDLER(GamepadHostMsg_StopPolling, OnGamepadStopPolling)
+#if defined(OS_ANDROID)
+ IPC_MESSAGE_HANDLER(GamepadHostMsg_ResumePolling, OnGamepadResumePolling)
+ IPC_MESSAGE_HANDLER(GamepadHostMsg_PausePolling, OnGamepadPausePolling)
+ IPC_MESSAGE_HANDLER(GamepadHostMsg_UpdateTimestamp,
+ OnGamepadUpdateTimestamp)
+#endif
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
@@ -57,4 +64,37 @@ void GamepadBrowserMessageFilter::OnGamepadStopPolling() {
}
}
+#if defined(OS_ANDROID)
+void GamepadBrowserMessageFilter::OnGamepadResumePolling() {
+ // The renderer will put the background polling thread to resume state.
+ if (is_started_ && GamepadService::GetInstance()->GetPollState()) {
+ GamepadService::GetInstance()->Resume();
+ } else {
+ NOTREACHED();
+ }
+}
+
+void GamepadBrowserMessageFilter::OnGamepadPausePolling() {
+ // The renderer will put the background polling thread to pause state.
+ if (is_started_ && !GamepadService::GetInstance()->GetPollState()) {
+ GamepadService::GetInstance()->Pause();
+ } else {
+ NOTREACHED();
+ }
+}
+
+void GamepadBrowserMessageFilter::OnGamepadUpdateTimestamp() {
+ // The renderer will set the timestamp for last gamepad data access. This way
+ // the polling thread can be put to pause state when webpage stops accessing
+ // data i.e browser minimize or tab change.
+ // TODO: Currently this approach is expensive. We need to get rid of this
+ // message and set the polling thread to pause state everytime gamepad data
+ // access stops. One possible way is tracking the focus change on the
+ // webpage.
+ GamepadService::GetInstance()->SetGamepadAccessTimestamp(
+ base::Time::NowFromSystemTime());
+ OnGamepadResumePolling();
+}
+#endif
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698