Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/nacl_irt/manifest_service.h" | 5 #include "ppapi/nacl_irt/manifest_service.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "ipc/ipc_channel_handle.h" | 8 #include "ipc/ipc_channel_handle.h" |
| 9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
| 11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
| 12 #include "ppapi/nacl_irt/irt_manifest.h" | 12 #include "ppapi/nacl_irt/irt_manifest.h" |
| 13 #include "ppapi/nacl_irt/plugin_startup.h" | 13 #include "ppapi/nacl_irt/plugin_startup.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 | 15 |
| 16 #if !defined(OS_NACL_SFI) | |
| 17 #include <pthread.h> | |
| 18 #include <map> | |
| 19 #include <string> | |
| 20 #endif | |
| 21 | |
| 16 namespace ppapi { | 22 namespace ppapi { |
| 17 | 23 |
| 18 const char kFilePrefix[] = "files/"; | 24 const char kFilePrefix[] = "files/"; |
| 19 | 25 |
| 20 // IPC channel is asynchronously set up. So, the NaCl process may try to | 26 // IPC channel is asynchronously set up. So, the NaCl process may try to |
| 21 // send a OpenResource message to the host before the connection is | 27 // send a OpenResource message to the host before the connection is |
| 22 // established. In such a case, it is necessary to wait for the set up | 28 // established. In such a case, it is necessary to wait for the set up |
| 23 // completion. | 29 // completion. |
| 24 class ManifestMessageFilter : public IPC::SyncMessageFilter { | 30 class ManifestMessageFilter : public IPC::SyncMessageFilter { |
| 25 public: | 31 public: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 ++file; | 132 ++file; |
| 127 | 133 |
| 128 ManifestService* manifest_service = GetManifestService(); | 134 ManifestService* manifest_service = GetManifestService(); |
| 129 if (manifest_service == NULL || | 135 if (manifest_service == NULL || |
| 130 !manifest_service->OpenResource(file, fd)) { | 136 !manifest_service->OpenResource(file, fd)) { |
| 131 return NACL_ABI_EIO; | 137 return NACL_ABI_EIO; |
| 132 } | 138 } |
| 133 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 139 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
| 134 } | 140 } |
| 135 | 141 |
| 142 #if !defined(OS_NACL_SFI) | |
| 143 namespace { | |
| 144 | |
| 145 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; | |
| 146 std::map<std::string, int>* g_fds; | |
| 147 | |
| 148 } // namespace | |
| 149 | |
| 150 void RegisterPreopenedDescriptorsNonSfi( | |
| 151 const std::map<std::string, int>& key_fd_map) { | |
| 152 pthread_mutex_lock(&g_mu); | |
| 153 DCHECK(!g_fds); | |
| 154 g_fds = new std::map<std::string, int>; | |
| 155 *g_fds = key_fd_map; | |
| 156 pthread_mutex_unlock(&g_mu); | |
| 157 } | |
| 158 | |
| 159 int IrtOpenResourceNonSfi(const char* file, int* fd) { | |
| 160 pthread_mutex_lock(&g_mu); | |
| 161 if (g_fds) { | |
| 162 std::map<std::string, int>::iterator it; | |
| 163 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.
| |
| 164 it = g_fds->find(file + 1); | |
| 165 else | |
| 166 it = g_fds->find(file); | |
| 167 if (it != g_fds->end()) { | |
| 168 *fd = it->second; | |
| 169 g_fds->erase(it); | |
| 170 pthread_mutex_unlock(&g_mu); | |
| 171 return 0; | |
| 172 } | |
| 173 } | |
| 174 pthread_mutex_unlock(&g_mu); | |
| 175 return IrtOpenResource(file, fd); | |
| 176 } | |
| 177 #endif | |
| 178 | |
| 136 } // namespace ppapi | 179 } // namespace ppapi |
| OLD | NEW |