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.
5 #ifndef PPAPI_SHARED_IMPL_TEST_GLOBALS_H_
6 #define PPAPI_SHARED_IMPL_TEST_GLOBALS_H_
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"
17 class TestVarTracker
: public VarTracker
{
19 TestVarTracker() : VarTracker(THREAD_SAFE
) {}
20 virtual ~TestVarTracker() {}
21 virtual PP_Var
MakeResourcePPVarFromMessage(
23 const IPC::Message
& creation_message
,
24 int pending_renderer_id
,
25 int pending_browser_id
) OVERRIDE
{
28 virtual ResourceVar
* MakeResourceVar(PP_Resource pp_resource
) OVERRIDE
{
31 virtual ArrayBufferVar
* CreateArrayBuffer(uint32 size_in_bytes
) OVERRIDE
{
34 virtual ArrayBufferVar
* CreateShmArrayBuffer(uint32 size_in_bytes
,
35 base::SharedMemoryHandle handle
)
39 virtual void DidDeleteInstance(PP_Instance instance
) OVERRIDE
{}
40 virtual int TrackSharedMemoryHandle(PP_Instance instance
,
41 base::SharedMemoryHandle handle
,
42 uint32 size_in_bytes
) OVERRIDE
{
45 virtual bool StopTrackingSharedMemoryHandle(int id
,
47 base::SharedMemoryHandle
* handle
,
48 uint32
* size_in_bytes
) OVERRIDE
{
53 // Implementation of PpapiGlobals for tests that don't need either the host- or
54 // plugin-specific implementations.
55 class TestGlobals
: public PpapiGlobals
{
58 explicit TestGlobals(PpapiGlobals::PerThreadForTest
);
59 virtual ~TestGlobals();
61 // PpapiGlobals implementation.
62 virtual ResourceTracker
* GetResourceTracker() OVERRIDE
;
63 virtual VarTracker
* GetVarTracker() OVERRIDE
;
64 virtual CallbackTracker
* GetCallbackTrackerForInstance(PP_Instance instance
)
66 virtual thunk::PPB_Instance_API
* GetInstanceAPI(PP_Instance instance
)
68 virtual thunk::ResourceCreationAPI
* GetResourceCreationAPI(
69 PP_Instance instance
) OVERRIDE
;
70 virtual PP_Module
GetModuleForInstance(PP_Instance instance
) OVERRIDE
;
71 virtual std::string
GetCmdLine() OVERRIDE
;
72 virtual void PreCacheFontForFlash(const void* logfontw
) OVERRIDE
;
73 virtual void LogWithSource(PP_Instance instance
,
75 const std::string
& source
,
76 const std::string
& value
) OVERRIDE
;
77 virtual void BroadcastLogWithSource(PP_Module module
,
79 const std::string
& source
,
80 const std::string
& value
) OVERRIDE
;
81 virtual MessageLoopShared
* GetCurrentMessageLoop() OVERRIDE
;
82 virtual base::TaskRunner
* GetFileTaskRunner() OVERRIDE
;
84 // PpapiGlobals overrides:
85 virtual bool IsHostGlobals() const OVERRIDE
;
88 ResourceTracker resource_tracker_
;
89 TestVarTracker var_tracker_
;
90 scoped_refptr
<CallbackTracker
> callback_tracker_
;
92 DISALLOW_COPY_AND_ASSIGN(TestGlobals
);
97 #endif // PPAPI_SHARED_IMPL_TEST_GLOBALS_H_