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 3// found in the LICENSE file. 4 5#ifndef PPAPI_PROXY_GAMEPAD_RESOURCE_H_ 6#define PPAPI_PROXY_GAMEPAD_RESOURCE_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/memory/shared_memory.h" 12#include "ppapi/c/ppb_gamepad.h" 13#include "ppapi/proxy/plugin_resource.h" 14#include "ppapi/proxy/ppapi_proxy_export.h" 15#include "ppapi/shared_impl/ppb_gamepad_shared.h" 16#include "ppapi/thunk/ppb_gamepad_api.h" 17 18struct PP_GamepadsSampleData; 19 20namespace base { 21class SharedMemory; 22} 23 24namespace ppapi { 25namespace proxy { 26 27// This class is a bit weird. It isn't a true resource from the plugin's 28// perspective. But we need to make requests to the browser and get replies. 29// It's more convenient to do this as a resource, so the instance just 30// maintains an internal lazily instantiated copy of this resource. 31class PPAPI_PROXY_EXPORT GamepadResource 32 : public PluginResource, 33 public thunk::PPB_Gamepad_API { 34 public: 35 GamepadResource(Connection connection, PP_Instance instance); 36 virtual ~GamepadResource(); 37 38 // Resource implementation. 39 virtual thunk::PPB_Gamepad_API* AsPPB_Gamepad_API() OVERRIDE; 40 41 // PPB_Gamepad_API. 42 virtual void Sample(PP_Instance instance, 43 PP_GamepadsSampleData* data) OVERRIDE; 44 45 private: 46 void OnPluginMsgSendMemory(const ResourceMessageReplyParams& params); 47 48 scoped_ptr<base::SharedMemory> shared_memory_; 49 const ContentGamepadHardwareBuffer* buffer_; 50 51 // Last data returned so we can use this in the event of a read failure. 52 PP_GamepadsSampleData last_read_; 53 54 DISALLOW_COPY_AND_ASSIGN(GamepadResource); 55}; 56 57} // namespace proxy 58} // namespace ppapi 59 60#endif // PPAPI_PROXY_GAMEPAD_RESOURCE_H_ 61