Chromium Code Reviews| 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..7d866b8419a4bdb4af5cbdddf23ffdff78ee7a1b 100644 |
| --- a/content/browser/renderer_host/gamepad_browser_message_filter.cc |
| +++ b/content/browser/renderer_host/gamepad_browser_message_filter.cc |
| @@ -2,8 +2,8 @@ |
| // 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" |
|
scottmg
2014/02/06 21:17:07
This should go below the include of gamepad_browse
|
| #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 +28,10 @@ bool GamepadBrowserMessageFilter::OnMessageReceived( |
| *message_was_ok) |
| IPC_MESSAGE_HANDLER(GamepadHostMsg_StartPolling, OnGamepadStartPolling) |
| IPC_MESSAGE_HANDLER(GamepadHostMsg_StopPolling, OnGamepadStopPolling) |
| + IPC_MESSAGE_HANDLER(GamepadHostMsg_ResumePolling, OnGamepadResumePolling) |
| + IPC_MESSAGE_HANDLER(GamepadHostMsg_PausePolling, OnGamepadPausePolling) |
| + IPC_MESSAGE_HANDLER(GamepadHostMsg_UpdateTimestamp, |
| + OnGamepadUpdateTimestamp) |
|
scottmg
2014/02/06 21:17:07
nit; align at (.
|
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP_EX() |
| return handled; |
| @@ -57,4 +61,35 @@ void GamepadBrowserMessageFilter::OnGamepadStopPolling() { |
| } |
| } |
| +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(SaurabhK): 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()); |
|
scottmg
2014/02/06 21:17:07
Ah, I see. Why can't we detect the situations abov
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Regarding
|
| + OnGamepadResumePolling(); |
| +} |
| + |
| } // namespace content |