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 #include "native_client/tests/fake_browser_ppapi/fake_host.h" | 7 #include "native_client/tests/fake_browser_ppapi/fake_host.h" |
8 | 8 |
9 #if !NACL_WINDOWS | 9 #if !NACL_WINDOWS |
10 # include <dlfcn.h> | 10 # include <dlfcn.h> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 get_interface_ = | 55 get_interface_ = |
56 reinterpret_cast<GetInterfaceFunc>( | 56 reinterpret_cast<GetInterfaceFunc>( |
57 reinterpret_cast<uintptr_t>(dlsym(dl_handle_, "PPP_GetInterface"))); | 57 reinterpret_cast<uintptr_t>(dlsym(dl_handle_, "PPP_GetInterface"))); |
58 CHECK(get_interface_ != NULL); | 58 CHECK(get_interface_ != NULL); |
59 } | 59 } |
60 | 60 |
61 Host::~Host() { | 61 Host::~Host() { |
62 int rc = dlclose(dl_handle_); | 62 int rc = dlclose(dl_handle_); |
63 CHECK(rc == 0); | 63 CHECK(rc == 0); |
64 | 64 |
65 ResourceMap::iterator it; | 65 ResourceMap::iterator ri; |
66 while ((it = resource_map_.begin()) != resource_map_.end()) { | 66 while ((ri = resource_map_.begin()) != resource_map_.end()) { |
67 delete(it->second); | 67 delete(ri->second); |
68 resource_map_.erase(it); | 68 resource_map_.erase(ri); |
| 69 } |
| 70 |
| 71 InstanceMap::iterator ii; |
| 72 while ((ii = instance_map_.begin()) != instance_map_.end()) { |
| 73 delete(ii->second); |
| 74 instance_map_.erase(ii); |
69 } | 75 } |
70 } | 76 } |
71 | 77 |
72 int32_t Host::InitializeModule(PP_Module module, | 78 int32_t Host::InitializeModule(PP_Module module, |
73 PPB_GetInterface get_intf) { | 79 PPB_GetInterface get_intf) { |
74 return (*initialize_module_)(module, get_intf); | 80 return (*initialize_module_)(module, get_intf); |
75 } | 81 } |
76 | 82 |
77 void Host::ShutdownModule() { | 83 void Host::ShutdownModule() { |
78 return (*shutdown_module_)(); | 84 return (*shutdown_module_)(); |
79 } | 85 } |
80 | 86 |
81 const void* Host::GetInterface(const char* interface_name) { | 87 const void* Host::GetInterface(const char* interface_name) { |
82 return (*get_interface_)(interface_name); | 88 return (*get_interface_)(interface_name); |
83 } | 89 } |
84 | 90 |
85 PP_Resource Host::TrackResource(Resource* resource) { | 91 PP_Resource Host::TrackResource(Resource* resource) { |
86 PP_Resource resource_id = ++last_resource_id_; | 92 PP_Resource resource_id = ++last_resource_id_; |
87 resource_map_[resource_id] = resource; | 93 resource_map_[resource_id] = resource; |
| 94 resource->set_resource_id(resource_id); |
88 return resource_id; | 95 return resource_id; |
89 } | 96 } |
90 | 97 |
91 Resource* Host::GetResource(PP_Resource resource_id) { | 98 Resource* Host::GetResource(PP_Resource resource_id) { |
92 ResourceMap::iterator iter = resource_map_.find(resource_id); | 99 ResourceMap::iterator iter = resource_map_.find(resource_id); |
93 if (iter == resource_map_.end()) | 100 if (iter == resource_map_.end()) |
94 return Resource::Invalid(); | 101 return Resource::Invalid(); |
95 return iter->second; | 102 return iter->second; |
96 } | 103 } |
97 | 104 |
| 105 PP_Instance Host::TrackInstance(Instance* instance) { |
| 106 PP_Instance instance_id = ++last_instance_id_; |
| 107 instance_map_[instance_id] = instance; |
| 108 instance->set_instance_id(instance_id); |
| 109 return instance_id; |
| 110 } |
| 111 |
| 112 Instance* Host::GetInstance(PP_Instance instance_id) { |
| 113 InstanceMap::iterator iter = instance_map_.find(instance_id); |
| 114 if (iter == instance_map_.end()) |
| 115 return Instance::Invalid(); |
| 116 return iter->second; |
| 117 } |
| 118 |
98 } // namespace fake_browser_ppapi | 119 } // namespace fake_browser_ppapi |
OLD | NEW |