[NaCl SDK] Refactor FakeFileSystemInterface.
Move FakeFileSystemInterface from fake_pepper_interface_html5_fs.{cc,h} to fake_file_system_interface.{cc,h} to share the code with the future code. depot_tools/clang-format was run so the formatting of code is accepted in the code review by policy. It was run in all the {.cc,.h} files, and the code formats of some files were changed. CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_nacl_sdk;master.tryserver.chromium.mac:mac_nacl_sdk;master.tryserver.chromium.win:win_nacl_sdk Review-Url: https://codereview.chromium.org/2455973003 Cr-Commit-Position: refs/heads/master@{#429186}
This commit is contained in:

committed by
Commit bot

parent
617838d02b
commit
9b7e1ceacd
native_client_sdk/src/tests/nacl_io_test
@ -15,6 +15,8 @@
|
||||
'fake_ppapi/fake_file_io_interface.h',
|
||||
'fake_ppapi/fake_file_ref_interface.cc',
|
||||
'fake_ppapi/fake_file_ref_interface.h',
|
||||
'fake_ppapi/fake_file_system_interface.cc',
|
||||
'fake_ppapi/fake_file_system_interface.h',
|
||||
'fake_ppapi/fake_host_resolver_interface.cc',
|
||||
'fake_ppapi/fake_host_resolver_interface.h',
|
||||
'fake_ppapi/fake_messaging_interface.cc',
|
||||
|
@ -0,0 +1,52 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "fake_ppapi/fake_file_system_interface.h"
|
||||
|
||||
#include <ppapi/c/pp_completion_callback.h>
|
||||
#include <ppapi/c/pp_errors.h>
|
||||
|
||||
#include "fake_ppapi/fake_core_interface.h"
|
||||
#include "fake_ppapi/fake_pepper_interface_html5_fs.h"
|
||||
#include "fake_ppapi/fake_util.h"
|
||||
|
||||
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) {
|
||||
FakeHtml5FsResource* instance_resource =
|
||||
core_interface_->resource_manager()->Get<FakeHtml5FsResource>(instance);
|
||||
if (instance_resource == NULL)
|
||||
return PP_ERROR_BADRESOURCE;
|
||||
|
||||
FakeFileSystemResource* file_system_resource = new FakeFileSystemResource;
|
||||
file_system_resource->filesystem = new FakeHtml5FsFilesystem(
|
||||
*instance_resource->filesystem_template, filesystem_type);
|
||||
|
||||
return CREATE_RESOURCE(core_interface_->resource_manager(),
|
||||
FakeFileSystemResource, file_system_resource);
|
||||
}
|
||||
|
||||
int32_t FakeFileSystemInterface::Open(PP_Resource file_system,
|
||||
int64_t expected_size,
|
||||
PP_CompletionCallback callback) {
|
||||
FakeFileSystemResource* file_system_resource =
|
||||
core_interface_->resource_manager()->Get<FakeFileSystemResource>(
|
||||
file_system);
|
||||
if (file_system_resource == NULL)
|
||||
return PP_ERROR_BADRESOURCE;
|
||||
|
||||
file_system_resource->opened = true;
|
||||
return RunCompletionCallback(&callback, PP_OK);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef LIBRARIES_NACL_IO_TEST_FAKE_FILE_SYSTEM_INTERFACE_H_
|
||||
#define LIBRARIES_NACL_IO_TEST_FAKE_FILE_SYSTEM_INTERFACE_H_
|
||||
|
||||
#include "fake_ppapi/fake_core_interface.h"
|
||||
#include "sdk_util/macros.h"
|
||||
|
||||
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,
|
||||
PP_CompletionCallback callback);
|
||||
|
||||
private:
|
||||
FakeCoreInterface* core_interface_; // Weak reference.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInterface);
|
||||
};
|
||||
|
||||
#endif // LIBRARIES_NACL_IO_TEST_FAKE_FILE_SYSTEM_INTERFACE_H_
|
@ -8,25 +8,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <ppapi/c/pp_completion_callback.h>
|
||||
#include <ppapi/c/pp_errors.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "fake_ppapi/fake_util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeInstanceResource : public FakeResource {
|
||||
public:
|
||||
FakeInstanceResource() : filesystem_template(NULL) {}
|
||||
static const char* classname() { return "FakeInstanceResource"; }
|
||||
|
||||
FakeHtml5FsFilesystem* filesystem_template; // Weak reference.
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
FakeHtml5FsNode::FakeHtml5FsNode(const PP_FileInfo& info) : info_(info) {}
|
||||
|
||||
FakeHtml5FsNode::FakeHtml5FsNode(const PP_FileInfo& info,
|
||||
@ -242,46 +229,6 @@ FakeHtml5FsFilesystem::Path FakeHtml5FsFilesystem::GetParentPath(
|
||||
return path.substr(0, last_slash);
|
||||
}
|
||||
|
||||
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 =
|
||||
core_interface_->resource_manager()->Get<FakeInstanceResource>(instance);
|
||||
if (instance_resource == NULL)
|
||||
return PP_ERROR_BADRESOURCE;
|
||||
|
||||
FakeFileSystemResource* file_system_resource = new FakeFileSystemResource;
|
||||
file_system_resource->filesystem = new FakeHtml5FsFilesystem(
|
||||
*instance_resource->filesystem_template, filesystem_type);
|
||||
|
||||
return CREATE_RESOURCE(core_interface_->resource_manager(),
|
||||
FakeFileSystemResource, file_system_resource);
|
||||
}
|
||||
|
||||
int32_t FakeFileSystemInterface::Open(PP_Resource file_system,
|
||||
int64_t expected_size,
|
||||
PP_CompletionCallback callback) {
|
||||
FakeFileSystemResource* file_system_resource =
|
||||
core_interface_->resource_manager()->Get<FakeFileSystemResource>(
|
||||
file_system);
|
||||
if (file_system_resource == NULL)
|
||||
return PP_ERROR_BADRESOURCE;
|
||||
|
||||
file_system_resource->opened = true;
|
||||
return RunCompletionCallback(&callback, PP_OK);
|
||||
}
|
||||
|
||||
FakePepperInterfaceHtml5Fs::FakePepperInterfaceHtml5Fs()
|
||||
: core_interface_(&resource_manager_),
|
||||
var_interface_(&var_manager_),
|
||||
@ -304,11 +251,11 @@ FakePepperInterfaceHtml5Fs::FakePepperInterfaceHtml5Fs(
|
||||
}
|
||||
|
||||
void FakePepperInterfaceHtml5Fs::Init() {
|
||||
FakeInstanceResource* instance_resource = new FakeInstanceResource;
|
||||
FakeHtml5FsResource* instance_resource = new FakeHtml5FsResource;
|
||||
instance_resource->filesystem_template = &filesystem_template_;
|
||||
|
||||
instance_ = CREATE_RESOURCE(core_interface_.resource_manager(),
|
||||
FakeInstanceResource, instance_resource);
|
||||
FakeHtml5FsResource, instance_resource);
|
||||
}
|
||||
|
||||
FakePepperInterfaceHtml5Fs::~FakePepperInterfaceHtml5Fs() {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "fake_ppapi/fake_core_interface.h"
|
||||
#include "fake_ppapi/fake_file_io_interface.h"
|
||||
#include "fake_ppapi/fake_file_ref_interface.h"
|
||||
#include "fake_ppapi/fake_file_system_interface.h"
|
||||
#include "fake_ppapi/fake_var_interface.h"
|
||||
#include "fake_ppapi/fake_var_manager.h"
|
||||
#include "nacl_io/pepper_interface_dummy.h"
|
||||
@ -97,22 +98,6 @@ class FakeHtml5FsFilesystem {
|
||||
PP_FileSystemType filesystem_type_;
|
||||
};
|
||||
|
||||
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,
|
||||
PP_CompletionCallback callback);
|
||||
|
||||
private:
|
||||
FakeCoreInterface* core_interface_; // Weak reference.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInterface);
|
||||
};
|
||||
|
||||
class FakePepperInterfaceHtml5Fs : public nacl_io::PepperInterfaceDummy {
|
||||
public:
|
||||
FakePepperInterfaceHtml5Fs();
|
||||
|
@ -32,6 +32,14 @@ class FakeFileSystemResource : public FakeResource {
|
||||
bool opened;
|
||||
};
|
||||
|
||||
class FakeHtml5FsResource : public FakeResource {
|
||||
public:
|
||||
FakeHtml5FsResource() : filesystem_template(NULL) {}
|
||||
static const char* classname() { return "FakeHtml5FsResource"; }
|
||||
|
||||
FakeHtml5FsFilesystem* filesystem_template; // Weak reference.
|
||||
};
|
||||
|
||||
int32_t RunCompletionCallback(PP_CompletionCallback* callback, int32_t result);
|
||||
|
||||
#endif // LIBRARIES_NACL_IO_TEST_FAKE_UTIL_H_
|
||||
|
Reference in New Issue
Block a user