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

Unified Diff: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc

Issue 2156503002: [NaCl SDK] Expose Google Drive to nacl_io. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months 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: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc
index 9b6ea45fc6b3b3bb7ee1427dcd14817e2fbd647d..9aadeaa3c7d61bae8ba5b6f3c4fd50a1fd73d828 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_url_loader.cc
@@ -14,39 +14,8 @@
#include "nacl_io/osinttypes.h"
-namespace {
-
-bool GetHeaderValue(const std::string& headers,
- const std::string& key,
- std::string* out_value) {
- out_value->clear();
-
- size_t offset = 0;
- while (offset != std::string::npos) {
- // Find the next colon; this separates the key from the value.
- size_t colon = headers.find(':', offset);
- if (colon == std::string::npos)
- return false;
-
- // Find the newline; this separates the value from the next header.
- size_t newline = headers.find('\n', offset);
- if (strncasecmp(key.c_str(), &headers.data()[offset], key.size()) != 0) {
- // Key doesn't match, skip to next header.
- offset = newline;
- continue;
- }
-
- // Key matches, extract value. First, skip leading spaces.
- size_t nonspace = headers.find_first_not_of(' ', colon + 1);
- if (nonspace == std::string::npos)
- return false;
-
- out_value->assign(headers, nonspace, newline - nonspace);
- return true;
- }
-
- return false;
-}
+#include "fake_ppapi/fake_filesystem.h"
+#include "fake_ppapi/fake_util.h"
class FakeInstanceResource : public FakeResource {
public:
@@ -82,44 +51,6 @@ class FakeURLLoaderResource : public FakeResource {
off_t read_end;
};
-class FakeURLRequestInfoResource : public FakeResource {
- public:
- FakeURLRequestInfoResource() {}
- static const char* classname() { return "FakeURLRequestInfoResource"; }
-
- std::string url;
- std::string method;
- std::string headers;
-};
-
-class FakeURLResponseInfoResource : public FakeResource {
- public:
- FakeURLResponseInfoResource() : status_code(0) {}
- static const char* classname() { return "FakeURLResponseInfoResource"; }
-
- int status_code;
- std::string url;
- std::string headers;
-};
-
-// Helper function to call the completion callback if it is defined (an
-// asynchronous call), or return the result directly if it isn't (a synchronous
-// call).
-//
-// Use like this:
-// if (<some error condition>)
-// return RunCompletionCallback(callback, PP_ERROR_FUBAR);
-//
-// /* Everything worked OK */
-// return RunCompletionCallback(callback, PP_OK);
-int32_t RunCompletionCallback(PP_CompletionCallback* callback, int32_t result) {
- if (callback->func) {
- PP_RunCompletionCallback(callback, result);
- return PP_OK_COMPLETIONPENDING;
- }
- return result;
-}
-
void HandleContentLength(FakeURLLoaderResource* loader,
FakeURLResponseInfoResource* response,
FakeURLLoaderEntity* entity) {
@@ -154,7 +85,7 @@ void HandlePartial(FakeURLLoaderResource* loader,
}
off_t content_length = entity->size();
- if (lo > content_length) {
+ if (lo >= content_length) {
// Trying to start reading past the end of the entity is
// unsatisfiable.
response->status_code = 416; // Request range not satisfiable.
@@ -185,19 +116,15 @@ void HandlePartial(FakeURLLoaderResource* loader,
response->status_code = 206; // Partial content
}
-} // namespace
-
FakeURLLoaderEntity::FakeURLLoaderEntity(const std::string& body)
- : body_(body), size_(body_.size()), repeat_(false) {
-}
+ : body_(body), size_(body_.size()), repeat_(false) {}
// Rather than specifying the entire file, specify a string to repeat, and the
// full length. This lets us test extremely large files without having to store
// them in memory.
FakeURLLoaderEntity::FakeURLLoaderEntity(const std::string& to_repeat,
off_t size)
- : body_(to_repeat), size_(size), repeat_(true) {
-}
+ : body_(to_repeat), size_(size), repeat_(true) {}
size_t FakeURLLoaderEntity::Read(void* buffer, size_t count, off_t offset) {
off_t max_read_count =
@@ -242,8 +169,7 @@ FakeURLLoaderServer::FakeURLLoaderServer()
: max_read_size_(0),
send_content_length_(false),
allow_partial_(false),
- allow_head_(true) {
-}
+ allow_head_(true) {}
void FakeURLLoaderServer::Clear() {
entity_map_.clear();
@@ -324,8 +250,7 @@ int FakeURLLoaderServer::GetError(const std::string& url) {
FakeURLLoaderInterface::FakeURLLoaderInterface(
FakeCoreInterface* core_interface)
- : core_interface_(core_interface) {
-}
+ : core_interface_(core_interface) {}
PP_Resource FakeURLLoaderInterface::Create(PP_Instance instance) {
FakeInstanceResource* instance_resource =
@@ -339,8 +264,7 @@ PP_Resource FakeURLLoaderInterface::Create(PP_Instance instance) {
new FakeURLLoaderServer(*instance_resource->server_template);
return CREATE_RESOURCE(core_interface_->resource_manager(),
- FakeURLLoaderResource,
- loader_resource);
+ FakeURLLoaderResource, loader_resource);
}
int32_t FakeURLLoaderInterface::Open(PP_Resource loader,
@@ -362,8 +286,7 @@ int32_t FakeURLLoaderInterface::Open(PP_Resource loader,
new FakeURLResponseInfoResource;
loader_resource->response =
CREATE_RESOURCE(core_interface_->resource_manager(),
- FakeURLResponseInfoResource,
- response_resource);
+ FakeURLResponseInfoResource, response_resource);
loader_resource->entity = NULL;
loader_resource->read_offset = 0;
@@ -447,6 +370,12 @@ int32_t FakeURLLoaderInterface::ReadResponseBody(
return RunCompletionCallback(&callback, bytes_read);
}
+int32_t FakeURLLoaderInterface::FinishStreamingToFile(
+ PP_Resource loader,
+ PP_CompletionCallback callback) {
+ return PP_ERROR_NOTSUPPORTED;
+}
+
void FakeURLLoaderInterface::Close(PP_Resource loader) {
FakeURLLoaderResource* loader_resource =
core_interface_->resource_manager()->Get<FakeURLLoaderResource>(loader);
@@ -464,15 +393,9 @@ void FakeURLLoaderInterface::Close(PP_Resource loader) {
FakeURLRequestInfoInterface::FakeURLRequestInfoInterface(
FakeCoreInterface* core_interface,
FakeVarInterface* var_interface)
- : core_interface_(core_interface), var_interface_(var_interface) {
-}
+ : core_interface_(core_interface), var_interface_(var_interface) {}
PP_Resource FakeURLRequestInfoInterface::Create(PP_Instance instance) {
- FakeInstanceResource* instance_resource =
- core_interface_->resource_manager()->Get<FakeInstanceResource>(instance);
- if (instance_resource == NULL)
- return PP_ERROR_BADRESOURCE;
-
return CREATE_RESOURCE(core_interface_->resource_manager(),
FakeURLRequestInfoResource,
new FakeURLRequestInfoResource);
@@ -539,6 +462,12 @@ PP_Bool FakeURLRequestInfoInterface::SetProperty(PP_Resource request,
// Throw the value away for now. TODO(binji): add tests for this.
return PP_TRUE;
}
+ case PP_URLREQUESTPROPERTY_STREAMTOFILE: {
+ if (value.type != PP_VARTYPE_BOOL)
+ return PP_FALSE;
+ // Throw the value away for now. TODO: add tests for this.
+ return PP_TRUE;
+ }
default:
EXPECT_TRUE(false) << "Unimplemented property " << property
<< " in "
@@ -547,10 +476,37 @@ PP_Bool FakeURLRequestInfoInterface::SetProperty(PP_Resource request,
}
}
+PP_Bool FakeURLRequestInfoInterface::AppendDataToBody(PP_Resource request,
+ const void* data,
+ uint32_t len) {
+ FakeURLRequestInfoResource* request_resource =
+ core_interface_->resource_manager()->Get<FakeURLRequestInfoResource>(
+ request);
+ if (request_resource == NULL)
+ return PP_FALSE;
+
+ request_resource->body = std::string((char*)data, len);
+
+ return PP_TRUE;
+}
+
FakeURLResponseInfoInterface::FakeURLResponseInfoInterface(
FakeCoreInterface* core_interface,
- FakeVarInterface* var_interface)
- : core_interface_(core_interface), var_interface_(var_interface) {
+ FakeVarInterface* var_interface,
+ FakeFileRefInterface* file_ref_interface)
+ : core_interface_(core_interface),
+ var_interface_(var_interface),
+ file_ref_interface_(file_ref_interface) {
+ FakeFileSystemResource* file_system_resource = new FakeFileSystemResource;
+ file_system_resource->filesystem = new FakeFilesystem();
+
+ filesystem_resource_ =
+ CREATE_RESOURCE(core_interface_->resource_manager(),
+ FakeFileSystemResource, file_system_resource);
+}
+
+FakeURLResponseInfoInterface::~FakeURLResponseInfoInterface() {
+ core_interface_->ReleaseResource(filesystem_resource_);
}
PP_Var FakeURLResponseInfoInterface::GetProperty(
@@ -581,17 +537,52 @@ PP_Var FakeURLResponseInfoInterface::GetProperty(
}
}
+PP_Resource FakeURLResponseInfoInterface::GetBodyAsFileRef(
+ PP_Resource response) {
+ FakeURLResponseInfoResource* response_resource =
+ core_interface_->resource_manager()->Get<FakeURLResponseInfoResource>(
+ response);
+ if (response_resource == NULL)
+ return PP_ERROR_BADRESOURCE;
+
+ FakeFileSystemResource* file_system_resource =
+ core_interface_->resource_manager()->Get<FakeFileSystemResource>(
+ filesystem_resource_);
+
+ if (file_system_resource == NULL)
+ return PP_ERROR_BADRESOURCE;
+
+ char path_buffer[1024];
+ int char_written = snprintf(path_buffer, sizeof(path_buffer), "%u", response);
+
+ if (char_written < 0 || char_written >= (signed int) sizeof(path_buffer)) {
+ return PP_ERROR_FAILED;
+ }
+
+ FakeNode* fake_node;
+ if (!file_system_resource->filesystem->AddFile(
+ path_buffer, response_resource->body, &fake_node)) {
+ return PP_ERROR_FAILED;
+ }
+
+ file_system_resource->opened = true;
+
+ return file_ref_interface_->Create(filesystem_resource_, path_buffer);
+}
+
FakePepperInterfaceURLLoader::FakePepperInterfaceURLLoader()
: core_interface_(&resource_manager_),
var_interface_(&var_manager_),
+ file_ref_interface_(&core_interface_, &var_interface_),
url_loader_interface_(&core_interface_),
url_request_info_interface_(&core_interface_, &var_interface_),
- url_response_info_interface_(&core_interface_, &var_interface_) {
+ url_response_info_interface_(&core_interface_,
+ &var_interface_,
+ &file_ref_interface_) {
FakeInstanceResource* instance_resource = new FakeInstanceResource;
instance_resource->server_template = &server_template_;
instance_ = CREATE_RESOURCE(core_interface_.resource_manager(),
- FakeInstanceResource,
- instance_resource);
+ FakeInstanceResource, instance_resource);
}
FakePepperInterfaceURLLoader::~FakePepperInterfaceURLLoader() {
@@ -606,6 +597,10 @@ nacl_io::VarInterface* FakePepperInterfaceURLLoader::GetVarInterface() {
return &var_interface_;
}
+nacl_io::FileRefInterface* FakePepperInterfaceURLLoader::GetFileRefInterface() {
+ return &file_ref_interface_;
+}
+
nacl_io::URLLoaderInterface*
FakePepperInterfaceURLLoader::GetURLLoaderInterface() {
return &url_loader_interface_;

Powered by Google App Engine
This is Rietveld 408576698