Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #ifndef NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ | 7 #ifndef NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ |
| 8 #define NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ | 8 #define NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ |
| 9 | 9 |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "native_client/src/include/portability.h" | 14 #include "native_client/src/include/portability.h" |
| 15 #include "native_client/tests/fake_browser_ppapi/fake_instance.h" | |
| 15 #include "native_client/tests/fake_browser_ppapi/fake_resource.h" | 16 #include "native_client/tests/fake_browser_ppapi/fake_resource.h" |
| 16 #include "ppapi/c/ppp.h" | 17 #include "ppapi/c/ppp.h" |
| 17 | 18 |
| 18 struct PPB_Var_Deprecated; | 19 struct PPB_Var_Deprecated; |
| 19 | 20 |
| 20 namespace fake_browser_ppapi { | 21 namespace fake_browser_ppapi { |
| 21 | 22 |
| 22 class Host { | 23 class Host { |
| 23 public: | 24 public: |
| 24 explicit Host(const char* plugin_file); | 25 explicit Host(const char* plugin_file); |
| 25 virtual ~Host(); | 26 virtual ~Host(); |
| 26 | 27 |
| 27 // Implementations of the methods invoked by the browser. | 28 // Implementations of the methods invoked by the browser. |
| 28 int32_t InitializeModule(PP_Module module, | 29 int32_t InitializeModule(PP_Module module, |
| 29 PPB_GetInterface get_intf); | 30 PPB_GetInterface get_intf); |
| 30 void ShutdownModule(); | 31 void ShutdownModule(); |
| 31 virtual const void* GetInterface(const char* interface_name); | 32 virtual const void* GetInterface(const char* interface_name); |
| 32 | 33 |
| 33 void set_var_interface(const PPB_Var_Deprecated* var_interface) { | 34 void set_var_interface(const PPB_Var_Deprecated* var_interface) { |
| 34 var_interface_ = var_interface; | 35 var_interface_ = var_interface; |
| 35 } | 36 } |
| 36 const PPB_Var_Deprecated* var_interface() const { | 37 const PPB_Var_Deprecated* var_interface() const { |
| 37 return var_interface_; | 38 return var_interface_; |
| 38 } | 39 } |
| 39 | 40 |
| 40 // Resource tracking. | 41 // Resource and Instance tracking. |
| 41 // The host keeps track of all Resources assigning them a unique resource_id. | 42 // |
| 42 // TrackResource() is to be called right after instantiation of a Resource. | 43 // The host keeps track of all Resources and Instances assigning them a unique |
| 43 // GetResource() can be called to map an id to a tracked Resource. If | 44 // id. TrackResource/Instance() is to be called right after instantiation of a |
| 44 // there is no such resource, Resource::Invalid() is returned. | 45 // Resource/Instance. GetResource/Instance () can be called to map an id to a |
| 46 // tracked Resource/Instance . If there is no such resource, | |
| 47 // Resource::Invalid() or Instance::Invalid() is returned. | |
| 48 // | |
| 49 // Resources and Instances are owned by the host - in other words, they will | |
| 50 // be deleted upon Host's destruction. Do not pass globals/stack variables | |
| 51 // to be tracked! | |
|
sehr (please use chromium)
2011/01/12 00:55:10
We could do this by using a factory pattern for In
neb
2011/01/13 00:00:43
Yup, but then Instances and Resources have differe
| |
| 45 PP_Resource TrackResource(Resource* resource); | 52 PP_Resource TrackResource(Resource* resource); |
| 46 Resource* GetResource(PP_Resource resource_id); | 53 Resource* GetResource(PP_Resource resource_id); |
| 54 PP_Instance TrackInstance(Instance* instance); | |
| 55 Instance* GetInstance(PP_Instance instance_id); | |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 typedef int32_t (*InitializeModuleFunc)(PP_Module module, | 58 typedef int32_t (*InitializeModuleFunc)(PP_Module module, |
| 50 PPB_GetInterface get_intf); | 59 PPB_GetInterface get_intf); |
| 51 typedef void (*ShutdownModuleFunc)(); | 60 typedef void (*ShutdownModuleFunc)(); |
| 52 typedef const void* (*GetInterfaceFunc)(const char* interface_name); | 61 typedef const void* (*GetInterfaceFunc)(const char* interface_name); |
| 53 | 62 |
| 54 void* dl_handle_; | 63 void* dl_handle_; |
| 55 InitializeModuleFunc initialize_module_; | 64 InitializeModuleFunc initialize_module_; |
| 56 ShutdownModuleFunc shutdown_module_; | 65 ShutdownModuleFunc shutdown_module_; |
| 57 GetInterfaceFunc get_interface_; | 66 GetInterfaceFunc get_interface_; |
| 58 | 67 |
| 59 const PPB_Var_Deprecated* var_interface_; | 68 const PPB_Var_Deprecated* var_interface_; |
| 60 | 69 |
| 61 // Resource tracking. | 70 // Resource tracking. |
| 62 PP_Resource last_resource_id_; // Used and incremented for each new resource. | 71 PP_Resource last_resource_id_; // Used and incremented for each new resource. |
| 63 typedef std::map<PP_Resource, Resource*> ResourceMap; | 72 typedef std::map<PP_Resource, Resource*> ResourceMap; |
| 64 ResourceMap resource_map_; | 73 ResourceMap resource_map_; |
| 65 | 74 |
| 75 // Instance tracking. | |
| 76 PP_Instance last_instance_id_; // Used and incremented for each new instance. | |
| 77 typedef std::map<PP_Instance, Instance*> InstanceMap; | |
| 78 InstanceMap instance_map_; | |
| 79 | |
| 66 NACL_DISALLOW_COPY_AND_ASSIGN(Host); | 80 NACL_DISALLOW_COPY_AND_ASSIGN(Host); |
| 67 }; | 81 }; |
| 68 | 82 |
| 69 } // namespace fake_browser_ppapi | 83 } // namespace fake_browser_ppapi |
| 70 | 84 |
| 71 #endif // NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ | 85 #endif // NATIVE_CLIENT_TEST_FAKE_BROWSER_PPAPI_FAKE_HOST_H_ |
| OLD | NEW |