This source file includes following definitions.
- is_started_
- OnMessageReceived
- OnGamepadStartPolling
- OnGamepadStopPolling
#include "content/browser/renderer_host/gamepad_browser_message_filter.h"
#include "content/browser/gamepad/gamepad_service.h"
#include "content/common/gamepad_messages.h"
namespace content {
GamepadBrowserMessageFilter::GamepadBrowserMessageFilter()
: BrowserMessageFilter(GamepadMsgStart),
is_started_(false) {
}
GamepadBrowserMessageFilter::~GamepadBrowserMessageFilter() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (is_started_)
GamepadService::GetInstance()->RemoveConsumer();
}
bool GamepadBrowserMessageFilter::OnMessageReceived(
const IPC::Message& message,
bool* message_was_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(GamepadBrowserMessageFilter,
message,
*message_was_ok)
IPC_MESSAGE_HANDLER(GamepadHostMsg_StartPolling, OnGamepadStartPolling)
IPC_MESSAGE_HANDLER(GamepadHostMsg_StopPolling, OnGamepadStopPolling)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
}
void GamepadBrowserMessageFilter::OnGamepadStartPolling(
base::SharedMemoryHandle* renderer_handle) {
GamepadService* service = GamepadService::GetInstance();
if (!is_started_) {
is_started_ = true;
service->AddConsumer();
*renderer_handle = service->GetSharedMemoryHandleForProcess(PeerHandle());
} else {
NOTREACHED();
}
}
void GamepadBrowserMessageFilter::OnGamepadStopPolling() {
if (is_started_) {
is_started_ = false;
GamepadService::GetInstance()->RemoveConsumer();
} else {
NOTREACHED();
}
}
}