summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 17:22:41 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 17:22:41 +0000
commit8e6ae313cbc7adc8ef196ea21877d5af5e7b8f42 (patch)
treedff8d9fbd87240479bbcbacd723eda61ec37bc64 /native_client_sdk
parent5f85973d81da8ba07f289ef48add098808165988 (diff)
downloadchromium_src-8e6ae313cbc7adc8ef196ea21877d5af5e7b8f42.zip
chromium_src-8e6ae313cbc7adc8ef196ea21877d5af5e7b8f42.tar.gz
chromium_src-8e6ae313cbc7adc8ef196ea21877d5af5e7b8f42.tar.bz2
[NaCl SDK] nacl_io: Allow passing FileSystem resource to nacl_io.
This is useful if a filesystem can be opened only via JavaScript (e.g. a media galleries filesystem). BUG=none R=sbc@chromium.org Review URL: https://codereview.chromium.org/298723010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc19
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h1
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc8
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h1
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.cc15
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.h11
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc35
7 files changed, 77 insertions, 13 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
index 0d52bee..99be95f 100644
--- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
@@ -161,11 +161,24 @@ Error Html5Fs::Init(const FsInitArgs& args) {
}
} else if (iter->first == "expected_size") {
expected_size = strtoull(iter->second.c_str(), NULL, 10);
+ } else if (iter->first == "filesystem_resource") {
+ PP_Resource resource = strtoull(iter->second.c_str(), NULL, 10);
+ if (!ppapi_->GetFileSystemInterface()->IsFileSystem(resource))
+ return EINVAL;
+
+ filesystem_resource_ = resource;
+ ppapi_->AddRefResource(filesystem_resource_);
}
}
+ if (filesystem_resource_ != 0) {
+ filesystem_open_has_result_ = true;
+ filesystem_open_error_ = PP_OK;
+ return 0;
+ }
+
// Initialize filesystem.
- filesystem_resource_ = args.ppapi->GetFileSystemInterface()->Create(
+ filesystem_resource_ = ppapi_->GetFileSystemInterface()->Create(
ppapi_->GetInstance(), filesystem_type);
if (filesystem_resource_ == 0)
return ENOSYS;
@@ -173,13 +186,13 @@ Error Html5Fs::Init(const FsInitArgs& args) {
// We can't block the main thread, so make an asynchronous call if on main
// thread. If we are off-main-thread, then don't make an asynchronous call;
// otherwise we require a message loop.
- bool main_thread = args.ppapi->GetCoreInterface()->IsMainThread();
+ bool main_thread = ppapi_->GetCoreInterface()->IsMainThread();
PP_CompletionCallback cc =
main_thread ? PP_MakeCompletionCallback(
&Html5Fs::FilesystemOpenCallbackThunk, this)
: PP_BlockUntilComplete();
- int32_t result = args.ppapi->GetFileSystemInterface()->Open(
+ int32_t result = ppapi_->GetFileSystemInterface()->Open(
filesystem_resource_, expected_size, cc);
if (!main_thread) {
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
index a889ecd..2ff3bbc 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
@@ -68,6 +68,7 @@ END_INTERFACE(FileRefInterface, PPB_FileRef_1_1)
/* Chrome M14 required */
BEGIN_INTERFACE(FileSystemInterface, PPB_FileSystem_1_0,
PPB_FILESYSTEM_INTERFACE_1_0)
+ METHOD1(FileSystemInterface, PP_Bool, IsFileSystem, PP_Resource)
METHOD2(FileSystemInterface, PP_Resource, Create, PP_Instance,
PP_FileSystemType)
METHOD3(FileSystemInterface, int32_t, Open, PP_Resource, int64_t,
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
index db30479..c2b1b9b 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
@@ -658,6 +658,14 @@ FakeFileSystemInterface::FakeFileSystemInterface(
FakeCoreInterface* core_interface)
: core_interface_(core_interface) {}
+PP_Bool FakeFileSystemInterface::IsFileSystem(PP_Resource resource) {
+ bool not_found_ok = true;
+ FakeFileSystemResource* file_system_resource =
+ core_interface_->resource_manager()->Get<FakeFileSystemResource>(
+ resource, not_found_ok);
+ return file_system_resource != NULL ? PP_TRUE : PP_FALSE;
+}
+
PP_Resource FakeFileSystemInterface::Create(PP_Instance instance,
PP_FileSystemType filesystem_type) {
FakeInstanceResource* instance_resource =
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
index fbf390f..97fa5c8 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
@@ -164,6 +164,7 @@ class FakeFileSystemInterface : public nacl_io::FileSystemInterface {
public:
FakeFileSystemInterface(FakeCoreInterface* core_interface);
+ virtual PP_Bool IsFileSystem(PP_Resource resource);
virtual PP_Resource Create(PP_Instance instance, PP_FileSystemType type);
virtual int32_t Open(PP_Resource file_system,
int64_t expected_size,
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.cc
index aa40c3c..0ee9212 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.cc
@@ -57,6 +57,9 @@ void FakeResourceManager::AddRef(PP_Resource handle) {
}
void FakeResourceManager::Release(PP_Resource handle) {
+ if (handle == 0)
+ return;
+
sdk_util::AutoLock lock(lock_);
ResourceMap::iterator iter = resource_map_.find(handle);
ASSERT_NE(resource_map_.end(), iter) << "Releasing unknown resource "
@@ -84,13 +87,17 @@ void FakeResourceManager::Release(PP_Resource handle) {
}
}
-FakeResourceTracker* FakeResourceManager::Get(PP_Resource handle) {
+FakeResourceTracker* FakeResourceManager::Get(PP_Resource handle,
+ bool not_found_ok) {
AUTO_LOCK(lock_);
ResourceMap::iterator iter = resource_map_.find(handle);
if (iter == resource_map_.end()) {
- // Can't use FAIL() because it tries to return void.
- EXPECT_TRUE(false) << "Trying to get resource " << handle
- << " that doesn't exist!";
+ if (!not_found_ok) {
+ // Can't use FAIL() because it tries to return void.
+ EXPECT_TRUE(false) << "Trying to get resource " << handle
+ << " that doesn't exist!";
+ }
+
return NULL;
}
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.h
index 10e1d6e..2ddd468 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.h
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_resource_manager.h
@@ -28,10 +28,10 @@ class FakeResourceManager {
void AddRef(PP_Resource handle);
void Release(PP_Resource handle);
template <typename T>
- T* Get(PP_Resource handle);
+ T* Get(PP_Resource handle, bool not_found_ok=false);
private:
- FakeResourceTracker* Get(PP_Resource handle);
+ FakeResourceTracker* Get(PP_Resource handle, bool not_found_ok);
typedef std::map<PP_Resource, FakeResourceTracker*> ResourceMap;
PP_Resource next_handle_;
@@ -103,8 +103,11 @@ class FakeResource {
};
template <typename T>
-inline T* FakeResourceManager::Get(PP_Resource handle) {
- return Get(handle)->resource<T>();
+inline T* FakeResourceManager::Get(PP_Resource handle, bool not_found_ok) {
+ FakeResourceTracker* tracker = Get(handle, not_found_ok);
+ if (!tracker)
+ return NULL;
+ return tracker->resource<T>();
}
#define CREATE_RESOURCE(MANAGER, TYPE, RESOURCE) \
diff --git a/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc b/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
index 8ea7c07..209943c 100644
--- a/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
@@ -40,12 +40,13 @@ namespace {
class Html5FsForTesting : public Html5Fs {
public:
- Html5FsForTesting(StringMap_t& string_map, PepperInterface* ppapi) {
+ Html5FsForTesting(StringMap_t& string_map, PepperInterface* ppapi,
+ int expected_error = 0) {
FsInitArgs args;
args.string_map = string_map;
args.ppapi = ppapi;
Error error = Init(args);
- EXPECT_EQ(0, error);
+ EXPECT_EQ(expected_error, error);
}
};
@@ -118,6 +119,36 @@ TEST_F(Html5FsTest, FilesystemType) {
}
}
+TEST_F(Html5FsTest, PassFilesystemResource) {
+ // Fail if given a bad resource.
+ {
+ StringMap_t map;
+ map["filesystem_resource"] = "0";
+ ScopedRef<Html5FsForTesting> fs(
+ new Html5FsForTesting(map, &ppapi_, EINVAL));
+ }
+
+ {
+ EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
+ PP_Resource filesystem = ppapi_html5_.GetFileSystemInterface()->Create(
+ ppapi_html5_.GetInstance(), PP_FILESYSTEMTYPE_LOCALPERSISTENT);
+
+ ASSERT_EQ(int32_t(PP_OK), ppapi_html5_.GetFileSystemInterface()->Open(
+ filesystem, 0, PP_BlockUntilComplete()));
+
+ StringMap_t map;
+ char buffer[30];
+ snprintf(buffer, 30, "%d", filesystem);
+ map["filesystem_resource"] = buffer;
+ ScopedRef<Html5FsForTesting> fs(
+ new Html5FsForTesting(map, &ppapi_));
+
+ ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK));
+
+ ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem);
+ }
+}
+
TEST_F(Html5FsTest, Access) {
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));