Chromium Code Reviews| Index: ppapi/nacl_irt/manifest_service.cc |
| diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc |
| index 8e671b90ceac9f24df864d175a373eb38c643968..95624e8a97bc29be5c9377f95a8d4080007d2432 100644 |
| --- a/ppapi/nacl_irt/manifest_service.cc |
| +++ b/ppapi/nacl_irt/manifest_service.cc |
| @@ -13,6 +13,12 @@ |
| #include "ppapi/nacl_irt/plugin_startup.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| +#if !defined(OS_NACL_SFI) |
| +#include <pthread.h> |
| +#include <map> |
| +#include <string> |
| +#endif |
| + |
| namespace ppapi { |
| const char kFilePrefix[] = "files/"; |
| @@ -133,4 +139,41 @@ int IrtOpenResource(const char* file, int* fd) { |
| return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
| } |
| +#if !defined(OS_NACL_SFI) |
| +namespace { |
| + |
| +pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; |
| +std::map<std::string, int>* g_fds; |
| + |
| +} // namespace |
| + |
| +void RegisterPreopenedDescriptorsNonSfi( |
| + const std::map<std::string, int>& key_fd_map) { |
| + pthread_mutex_lock(&g_mu); |
| + DCHECK(!g_fds); |
| + g_fds = new std::map<std::string, int>; |
| + *g_fds = key_fd_map; |
| + pthread_mutex_unlock(&g_mu); |
| +} |
| + |
| +int IrtOpenResourceNonSfi(const char* file, int* fd) { |
| + pthread_mutex_lock(&g_mu); |
| + if (g_fds) { |
| + std::map<std::string, int>::iterator it; |
| + if (file[0] == '/') |
|
Mark Seaborn
2015/02/09 04:48:35
This check for "/" duplicates the check in IrtOpen
Yusuke Sato
2015/02/11 05:54:21
Done.
|
| + it = g_fds->find(file + 1); |
| + else |
| + it = g_fds->find(file); |
| + if (it != g_fds->end()) { |
| + *fd = it->second; |
| + g_fds->erase(it); |
| + pthread_mutex_unlock(&g_mu); |
| + return 0; |
| + } |
| + } |
| + pthread_mutex_unlock(&g_mu); |
| + return IrtOpenResource(file, fd); |
| +} |
| +#endif |
| + |
| } // namespace ppapi |