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_SHARED_IMPL_TEST_GLOBALS_H_ 6 #define PPAPI_SHARED_IMPL_TEST_GLOBALS_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/shared_memory.h" 10 #include "ppapi/shared_impl/callback_tracker.h" 11 #include "ppapi/shared_impl/ppapi_globals.h" 12 #include "ppapi/shared_impl/resource_tracker.h" 13 #include "ppapi/shared_impl/var_tracker.h" 14 15 namespace ppapi { 16 17 class TestVarTracker : public VarTracker { 18 public: TestVarTracker()19 TestVarTracker() : VarTracker(THREAD_SAFE) {} ~TestVarTracker()20 virtual ~TestVarTracker() {} MakeResourcePPVarFromMessage(PP_Instance instance,const IPC::Message & creation_message,int pending_renderer_id,int pending_browser_id)21 virtual PP_Var MakeResourcePPVarFromMessage( 22 PP_Instance instance, 23 const IPC::Message& creation_message, 24 int pending_renderer_id, 25 int pending_browser_id) OVERRIDE { 26 return PP_MakeNull(); 27 } MakeResourceVar(PP_Resource pp_resource)28 virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE { 29 return NULL; 30 } CreateArrayBuffer(uint32 size_in_bytes)31 virtual ArrayBufferVar* CreateArrayBuffer(uint32 size_in_bytes) OVERRIDE { 32 return NULL; 33 } CreateShmArrayBuffer(uint32 size_in_bytes,base::SharedMemoryHandle handle)34 virtual ArrayBufferVar* CreateShmArrayBuffer( 35 uint32 size_in_bytes, 36 base::SharedMemoryHandle handle) OVERRIDE { 37 return NULL; 38 } DidDeleteInstance(PP_Instance instance)39 virtual void DidDeleteInstance(PP_Instance instance) OVERRIDE { 40 } TrackSharedMemoryHandle(PP_Instance instance,base::SharedMemoryHandle handle,uint32 size_in_bytes)41 virtual int TrackSharedMemoryHandle(PP_Instance instance, 42 base::SharedMemoryHandle handle, 43 uint32 size_in_bytes) OVERRIDE { 44 return -1; 45 } StopTrackingSharedMemoryHandle(int id,PP_Instance instance,base::SharedMemoryHandle * handle,uint32 * size_in_bytes)46 virtual bool StopTrackingSharedMemoryHandle(int id, 47 PP_Instance instance, 48 base::SharedMemoryHandle* handle, 49 uint32* size_in_bytes) OVERRIDE { 50 return false; 51 } 52 }; 53 54 // Implementation of PpapiGlobals for tests that don't need either the host- or 55 // plugin-specific implementations. 56 class TestGlobals : public PpapiGlobals { 57 public: 58 TestGlobals(); 59 explicit TestGlobals(PpapiGlobals::PerThreadForTest); 60 virtual ~TestGlobals(); 61 62 // PpapiGlobals implementation. 63 virtual ResourceTracker* GetResourceTracker() OVERRIDE; 64 virtual VarTracker* GetVarTracker() OVERRIDE; 65 virtual CallbackTracker* GetCallbackTrackerForInstance( 66 PP_Instance instance) OVERRIDE; 67 virtual thunk::PPB_Instance_API* GetInstanceAPI( 68 PP_Instance instance) OVERRIDE; 69 virtual thunk::ResourceCreationAPI* GetResourceCreationAPI( 70 PP_Instance instance) OVERRIDE; 71 virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; 72 virtual std::string GetCmdLine() OVERRIDE; 73 virtual void PreCacheFontForFlash(const void* logfontw) OVERRIDE; 74 virtual void LogWithSource(PP_Instance instance, 75 PP_LogLevel level, 76 const std::string& source, 77 const std::string& value) OVERRIDE; 78 virtual void BroadcastLogWithSource(PP_Module module, 79 PP_LogLevel level, 80 const std::string& source, 81 const std::string& value) OVERRIDE; 82 virtual MessageLoopShared* GetCurrentMessageLoop() OVERRIDE; 83 virtual base::TaskRunner* GetFileTaskRunner() OVERRIDE; 84 85 // PpapiGlobals overrides: 86 virtual bool IsHostGlobals() const OVERRIDE; 87 88 private: 89 ResourceTracker resource_tracker_; 90 TestVarTracker var_tracker_; 91 scoped_refptr<CallbackTracker> callback_tracker_; 92 93 DISALLOW_COPY_AND_ASSIGN(TestGlobals); 94 }; 95 96 } // namespace ppapi 97 98 #endif // PPAPI_SHARED_IMPL_TEST_GLOBALS_H_ 99