Skip to content

Commit

Permalink
[NaCl SDK] Add more support and fix FakePepperInterfaceGoogleDriveFs
Browse files Browse the repository at this point in the history
Add FakeDriveURLRequestInfoInterface, an FakeFileIoInterface instance, &
FakeDriveURLResponseInfoInterface::GetProperty() to
FakePepperInterfaceGoogleDriveFs, and fix a reference count cycle issue
in FakePepperInterfaceGoogleDriveFs.  FakePepperInterfaceGoogleDriveFs
is going to be used by the unit tests of the future code.

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/2573523004
Cr-Commit-Position: refs/heads/master@{#440605}
  • Loading branch information
chanpatorikku authored and Commit bot committed Dec 23, 2016
1 parent c04dcf4 commit 7385e43
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ class FakeDriveURLLoaderResource : public FakeResource {
class FakeDriveResponseResource : public FakeURLResponseInfoResource {
public:
FakeDriveResponseResource()
: manager(NULL), loader(0), file_ref(0), stream_to_file(false) {}
: manager(NULL),
loader_resource(NULL),
file_ref(0),
stream_to_file(false) {}

virtual void Destroy() {
EXPECT_TRUE(manager != NULL);
if (loader != 0)
manager->Release(loader);

if (file_ref != 0)
manager->Release(file_ref);
}

static const char* classname() { return "FakeDriveResponseResource"; }

FakeResourceManager* manager;
PP_Resource loader;
FakeDriveURLLoaderResource* loader_resource;
PP_Resource file_ref;
bool stream_to_file;
std::string body;
Expand Down Expand Up @@ -122,9 +122,7 @@ int32_t FakeDriveURLLoaderInterface::Open(PP_Resource loader,
CREATE_RESOURCE(core_interface_->resource_manager(),
FakeDriveResponseResource, drive_response_resource);

drive_response_resource->loader = loader;
core_interface_->resource_manager()->AddRef(drive_response_resource->loader);

drive_response_resource->loader_resource = drive_loader_resource;
drive_response_resource->stream_to_file = request_resource->stream_to_file;

FakeGoogleDriveServerResponse server_response;
Expand Down Expand Up @@ -193,6 +191,23 @@ void FakeDriveURLLoaderInterface::Close(PP_Resource loader) {
drive_loader_resource->response_body.clear();
}

FakeDriveURLRequestInfoInterface::FakeDriveURLRequestInfoInterface(
FakeCoreInterface* core_interface,
FakeVarInterface* var_interface)
: FakeURLRequestInfoInterface(core_interface, var_interface) {}

PP_Resource FakeDriveURLRequestInfoInterface::Create(PP_Instance instance) {
FakeDriveInstanceResource* drive_instance_resource =
core_interface_->resource_manager()->Get<FakeDriveInstanceResource>(
instance);
if (drive_instance_resource == NULL)
return PP_ERROR_BADRESOURCE;

return CREATE_RESOURCE(core_interface_->resource_manager(),
FakeURLRequestInfoResource,
new FakeURLRequestInfoResource);
}

FakeDriveURLResponseInfoInterface::FakeDriveURLResponseInfoInterface(
FakeCoreInterface* core_interface,
FakeVarInterface* var_interface,
Expand All @@ -212,6 +227,35 @@ FakeDriveURLResponseInfoInterface::~FakeDriveURLResponseInfoInterface() {
core_interface_->ReleaseResource(filesystem_resource_);
}

PP_Var FakeDriveURLResponseInfoInterface::GetProperty(
PP_Resource response,
PP_URLResponseProperty property) {
FakeDriveResponseResource* drive_response_resource =
core_interface_->resource_manager()->Get<FakeDriveResponseResource>(
response);
if (drive_response_resource == NULL)
return PP_Var();

switch (property) {
case PP_URLRESPONSEPROPERTY_URL:
return var_interface_->VarFromUtf8(drive_response_resource->url.data(),
drive_response_resource->url.size());

case PP_URLRESPONSEPROPERTY_STATUSCODE:
return PP_MakeInt32(drive_response_resource->status_code);

case PP_URLRESPONSEPROPERTY_HEADERS:
return var_interface_->VarFromUtf8(
drive_response_resource->headers.data(),
drive_response_resource->headers.size());
default:
EXPECT_TRUE(false) << "Unimplemented property " << property
<< " in "
"FakeDriveURLResponseInfoInterface::GetProperty";
return PP_Var();
}
}

PP_Resource FakeDriveURLResponseInfoInterface::GetBodyAsFileRef(
PP_Resource response) {
FakeDriveResponseResource* drive_response_resource =
Expand All @@ -223,13 +267,10 @@ PP_Resource FakeDriveURLResponseInfoInterface::GetBodyAsFileRef(
if (!drive_response_resource->stream_to_file)
return 0;

FakeDriveURLLoaderResource* drive_loader_resource =
core_interface_->resource_manager()->Get<FakeDriveURLLoaderResource>(
drive_response_resource->loader);
if (drive_loader_resource == NULL)
if (drive_response_resource->loader_resource == NULL)
return 0;

if (drive_loader_resource->server == NULL)
if (drive_response_resource->loader_resource->server == NULL)
return 0;

if (drive_response_resource->file_ref == 0) {
Expand Down Expand Up @@ -260,9 +301,10 @@ PP_Resource FakeDriveURLResponseInfoInterface::GetBodyAsFileRef(
FakePepperInterfaceGoogleDriveFs::FakePepperInterfaceGoogleDriveFs()
: core_interface_(&resource_manager_),
var_interface_(&var_manager_),
file_io_interface_(&core_interface_),
file_ref_interface_(&core_interface_, &var_interface_),
drive_url_loader_interface_(&core_interface_),
url_request_info_interface_(&core_interface_, &var_interface_),
drive_url_request_info_interface_(&core_interface_, &var_interface_),
drive_url_response_info_interface_(&core_interface_,
&var_interface_,
&file_ref_interface_) {
Expand All @@ -287,6 +329,11 @@ nacl_io::CoreInterface* FakePepperInterfaceGoogleDriveFs::GetCoreInterface() {
return &core_interface_;
}

nacl_io::FileIoInterface*
FakePepperInterfaceGoogleDriveFs::GetFileIoInterface() {
return &file_io_interface_;
}

nacl_io::FileRefInterface*
FakePepperInterfaceGoogleDriveFs::GetFileRefInterface() {
return &file_ref_interface_;
Expand All @@ -299,7 +346,7 @@ FakePepperInterfaceGoogleDriveFs::GetURLLoaderInterface() {

nacl_io::URLRequestInfoInterface*
FakePepperInterfaceGoogleDriveFs::GetURLRequestInfoInterface() {
return &url_request_info_interface_;
return &drive_url_request_info_interface_;
}

nacl_io::URLResponseInfoInterface*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "sdk_util/macros.h"

#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_pepper_interface_url_loader.h"
#include "fake_ppapi/fake_var_interface.h"
Expand Down Expand Up @@ -50,13 +51,26 @@ class FakeDriveURLLoaderInterface : public FakeURLLoaderInterface {
DISALLOW_COPY_AND_ASSIGN(FakeDriveURLLoaderInterface);
};

class FakeDriveURLRequestInfoInterface : public FakeURLRequestInfoInterface {
public:
FakeDriveURLRequestInfoInterface(FakeCoreInterface* core_interface,
FakeVarInterface* var_interface);

virtual PP_Resource Create(PP_Instance instance);

private:
DISALLOW_COPY_AND_ASSIGN(FakeDriveURLRequestInfoInterface);
};

class FakeDriveURLResponseInfoInterface : public FakeURLResponseInfoInterface {
public:
FakeDriveURLResponseInfoInterface(FakeCoreInterface* core_interface,
FakeVarInterface* var_interface,
FakeFileRefInterface* file_ref_interface);
~FakeDriveURLResponseInfoInterface();

virtual PP_Var GetProperty(PP_Resource response,
PP_URLResponseProperty property);
virtual PP_Resource GetBodyAsFileRef(PP_Resource response);

private:
Expand Down Expand Up @@ -87,6 +101,7 @@ class FakePepperInterfaceGoogleDriveFs : public nacl_io::PepperInterfaceDummy {

virtual PP_Instance GetInstance() { return instance_; }
virtual nacl_io::CoreInterface* GetCoreInterface();
virtual nacl_io::FileIoInterface* GetFileIoInterface();
virtual nacl_io::FileRefInterface* GetFileRefInterface();
virtual nacl_io::VarInterface* GetVarInterface();
virtual nacl_io::URLLoaderInterface* GetURLLoaderInterface();
Expand All @@ -104,10 +119,11 @@ class FakePepperInterfaceGoogleDriveFs : public nacl_io::PepperInterfaceDummy {
FakeCoreInterface core_interface_;
FakeVarInterface var_interface_;
FakeVarManager var_manager_;
FakeFileIoInterface file_io_interface_;
FakeFileRefInterface file_ref_interface_;
FakeGoogleDriveServer google_drive_server_template_;
FakeDriveURLLoaderInterface drive_url_loader_interface_;
FakeURLRequestInfoInterface url_request_info_interface_;
FakeDriveURLRequestInfoInterface drive_url_request_info_interface_;
FakeDriveURLResponseInfoInterface drive_url_response_info_interface_;
PP_Instance instance_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ class FakeURLRequestInfoInterface : public nacl_io::URLRequestInfoInterface {
const void* data,
uint32_t len);

private:
protected:
FakeCoreInterface* core_interface_; // Weak reference.
FakeVarInterface* var_interface_; // Weak reference.

private:
DISALLOW_COPY_AND_ASSIGN(FakeURLRequestInfoInterface);
};

Expand Down

0 comments on commit 7385e43

Please sign in to comment.