Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: components/nacl/loader/nonsfi/irt_resource_open.cc

Issue 649603004: Non-SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ipc/ and mojo/ changes following Mark's suggestion Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/nacl/loader/nonsfi/irt_resource_open.cc
diff --git a/components/nacl/loader/nonsfi/irt_resource_open.cc b/components/nacl/loader/nonsfi/irt_resource_open.cc
index cf193c13ba14c82afa410f2dd37ba4161ead9c35..6e84f54e1d011ab8fa0071374f56496fa528af43 100644
--- a/components/nacl/loader/nonsfi/irt_resource_open.cc
+++ b/components/nacl/loader/nonsfi/irt_resource_open.cc
@@ -2,14 +2,56 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <pthread.h>
+
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
+
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "ppapi/nacl_irt/irt_manifest.h"
namespace nacl {
namespace nonsfi {
+namespace {
+
+pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;
hidehiko 2015/01/28 09:05:19 base::Lock?
Yusuke Sato 2015/02/04 02:00:28 I used this primitive type to ensure that g_mu nev
Mark Seaborn 2015/02/04 18:52:16 Indeed, I think it's not safe. base::Lock is a no
+std::map<std::string, int>* g_fds;
+
+} // namespace
+
+void RegisterPreopenedDescriptors(
hidehiko 2015/01/28 09:05:19 Could you move the implementation to ppapi/nacl_ir
Mark Seaborn 2015/02/02 23:21:50 I agree. This belongs in ppapi/nacl_irt/manifest_
Yusuke Sato 2015/02/04 02:00:28 Done.
Yusuke Sato 2015/02/04 02:00:29 Done.
+ const std::vector<std::pair<std::string, int> >& key_fd_pairs) {
+ pthread_mutex_lock(&g_mu);
hidehiko 2015/01/28 09:05:19 and base::AutoLock?
Yusuke Sato 2015/02/04 02:00:28 same
+ g_fds = new std::map<std::string, int>;
+ for (size_t i = 0; i < key_fd_pairs.size(); ++i)
+ g_fds->insert(key_fd_pairs[i]);
+ pthread_mutex_unlock(&g_mu);
+}
+
+int IrtOpenResource(const char* file, int* fd) {
+ pthread_mutex_lock(&g_mu);
+ if (g_fds) {
+ std::map<std::string, int>::iterator it;
+ if (file[0] == '/')
+ 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 ppapi::IrtOpenResource(file, fd);
+}
+
const nacl_irt_resource_open kIrtResourceOpen = {
- ppapi::IrtOpenResource,
+ nacl::nonsfi::IrtOpenResource,
};
} // namespace nonsfi

Powered by Google App Engine
This is Rietveld 408576698