Commit b6ff87ac authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

[fsp] Rename has_next to has_more.

For consistency, has_next is changed to has_more. Also, has_more is easier to
understand in providing extensions context.

TEST=browser_tests, unit_test: *FileSystemProvider*
BUG=373165

Review URL: https://codereview.chromium.org/304533003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274217 0039d316-1c4b-4281-b951-d872f2087c98
parent e3903659
......@@ -132,9 +132,9 @@ bool FileSystemProviderInternalReadDirectoryRequestedSuccessFunction::
scoped_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
const bool has_next = params->has_next;
const bool has_more = params->has_more;
FulfillRequest(RequestValue::CreateForReadDirectorySuccess(params.Pass()),
has_next);
has_more);
return true;
}
......@@ -194,9 +194,9 @@ FileSystemProviderInternalReadFileRequestedSuccessFunction::RunWhenValid() {
scoped_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
const bool has_next = params->has_next;
const bool has_more = params->has_more;
FulfillRequest(RequestValue::CreateForReadFileSuccess(params.Pass()),
has_next);
has_more);
return true;
}
......
......@@ -90,8 +90,8 @@ void FileSystemProviderInternalFunction::RejectRequest(
void FileSystemProviderInternalFunction::FulfillRequest(
scoped_ptr<RequestValue> value,
bool has_next) {
if (!request_manager_->FulfillRequest(request_id_, value.Pass(), has_next))
bool has_more) {
if (!request_manager_->FulfillRequest(request_id_, value.Pass(), has_more))
SetErrorResponse(kSecurityErrorName, kResponseFailedErrorMessage);
}
......
......@@ -64,11 +64,11 @@ class FileSystemProviderInternalFunction : public ChromeSyncExtensionFunction {
// Fulfills the request with parsed arguments of this API function
// encapsulated as a RequestValue instance. Also, sets a response.
// If |has_next| is set to true, then the function will be called again for
// If |has_more| is set to true, then the function will be called again for
// this request.
void FulfillRequest(
scoped_ptr<chromeos::file_system_provider::RequestValue> value,
bool has_next);
bool has_more);
// Subclasses implement this for their functionality.
// Called after Parse() is successful, such that |request_id_| and
......
......@@ -198,7 +198,7 @@ void FakeProvidedFileSystem::ReadFile(
FROM_HERE,
base::Bind(callback,
0 /* chunk_length */,
false /* has_next */,
false /* has_more */,
base::File::FILE_ERROR_INVALID_OPERATION));
return;
}
......@@ -213,18 +213,18 @@ void FakeProvidedFileSystem::ReadFile(
FROM_HERE,
base::Bind(callback,
0 /* chunk_length */,
false /* has_next */,
false /* has_more */,
base::File::FILE_OK));
}
while (current_offset < kFakeFileSize && current_length) {
buffer->data()[current_offset - offset] = kFakeFileText[current_offset];
const bool has_next =
const bool has_more =
(current_offset + 1 < kFakeFileSize) && (current_length - 1);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(
callback, 1 /* chunk_length */, has_next, base::File::FILE_OK));
callback, 1 /* chunk_length */, has_more, base::File::FILE_OK));
current_offset++;
current_length--;
}
......
......@@ -78,7 +78,7 @@ void CloseFileOnUIThread(base::WeakPtr<ProvidedFileSystemInterface> file_system,
}
// Requests reading contents of a file. In case of either success or a failure
// |callback| is executed. It can be called many times, until |has_next| is set
// |callback| is executed. It can be called many times, until |has_more| is set
// to false. This function guarantees that it will succeed only if the file has
// not been changed while reading. Must be called on UI thread.
void ReadFileOnUIThread(
......@@ -92,7 +92,7 @@ void ReadFileOnUIThread(
// If the file system got unmounted, then abort the reading operation.
if (!file_system.get()) {
callback.Run(0, false /* has_next */, base::File::FILE_ERROR_ABORT);
callback.Run(0, false /* has_more */, base::File::FILE_ERROR_ABORT);
return;
}
......@@ -104,13 +104,13 @@ void OnReadChunkReceivedOnUIThread(
const ProvidedFileSystemInterface::ReadChunkReceivedCallback&
chunk_received_callback,
int chunk_length,
bool has_next,
bool has_more,
base::File::Error result) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
base::Bind(chunk_received_callback, chunk_length, has_next, result));
base::Bind(chunk_received_callback, chunk_length, has_more, result));
}
// Requests metadata of a file. In case of either succes or a failure,
......@@ -289,13 +289,13 @@ void FileStreamReader::GetLengthAfterInitialized(
void FileStreamReader::OnReadChunkReceived(
const net::CompletionCallback& callback,
int chunk_length,
bool has_next,
bool has_more,
base::File::Error result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
current_length_ += chunk_length;
// If this is the last chunk with a success, then finalize.
if (!has_next && result == base::File::FILE_OK) {
if (!has_more && result == base::File::FILE_OK) {
current_offset_ += current_length_;
callback.Run(current_length_);
return;
......@@ -303,13 +303,13 @@ void FileStreamReader::OnReadChunkReceived(
// In case of an error, abort.
if (result != base::File::FILE_OK) {
DCHECK(!has_next);
DCHECK(!has_more);
callback.Run(net::FileErrorToNetError(result));
return;
}
// More data is about to come, so do not call the callback yet.
DCHECK(has_next);
DCHECK(has_more);
}
void FileStreamReader::OnGetMetadataForGetLengthReceived(
......
......@@ -61,11 +61,11 @@ class FileStreamReader : public webkit_blob::FileStreamReader {
// Called when a file system provider returns chunk of read data. Note, that
// this may be called multiple times per single Read() call, as long as
// |has_next| is set to true. |result| is set to success only if reading is
// |has_more| is set to true. |result| is set to success only if reading is
// successful, and the file has not changed while reading.
void OnReadChunkReceived(const net::CompletionCallback& callback,
int chunk_length,
bool has_next,
bool has_more,
base::File::Error result);
// Called when fetching length of the file is completed with either a success
......
......@@ -37,7 +37,7 @@ bool CloseFile::Execute(int request_id) {
void CloseFile::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
callback_.Run(base::File::FILE_OK);
}
......
......@@ -40,7 +40,7 @@ class CloseFile : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -160,7 +160,7 @@ TEST_F(FileSystemProviderOperationsCloseFileTest, OnSuccess) {
close_file.OnSuccess(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()),
false /* has_next */);
false /* has_more */);
ASSERT_EQ(1u, callback_logger.events().size());
EXPECT_EQ(base::File::FILE_OK, callback_logger.events()[0]);
}
......
......@@ -69,7 +69,7 @@ bool GetMetadata::Execute(int request_id) {
void GetMetadata::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
base::File::Info file_info;
const bool convert_result =
ConvertRequestValueToFileInfo(result.Pass(), &file_info);
......
......@@ -38,7 +38,7 @@ class GetMetadata : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -210,8 +210,8 @@ TEST_F(FileSystemProviderOperationsGetMetadataTest, OnSuccess) {
RequestValue::CreateForGetMetadataSuccess(params.Pass()));
ASSERT_TRUE(request_value.get());
const bool has_next = false;
get_metadata.OnSuccess(kRequestId, request_value.Pass(), has_next);
const bool has_more = false;
get_metadata.OnSuccess(kRequestId, request_value.Pass(), has_more);
ASSERT_EQ(1u, callback_logger.events().size());
CallbackLogger::Event* event = callback_logger.events()[0];
......
......@@ -55,7 +55,7 @@ bool OpenFile::Execute(int request_id) {
void OpenFile::OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
// File handle is the same as request id of the OpenFile operation.
callback_.Run(request_id, base::File::FILE_OK);
}
......
......@@ -42,7 +42,7 @@ class OpenFile : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -196,7 +196,7 @@ TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) {
open_file.OnSuccess(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()),
false /* has_next */);
false /* has_more */);
ASSERT_EQ(1u, callback_logger.events().size());
CallbackLogger::Event* event = callback_logger.events()[0];
EXPECT_EQ(base::File::FILE_OK, event->result());
......
......@@ -40,7 +40,7 @@ class Operation : public RequestManager::HandlerInterface {
virtual bool Execute(int request_id) OVERRIDE = 0;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE = 0;
bool has_more) OVERRIDE = 0;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE = 0;
// Sets custom dispatchign event implementation for tests.
......
......@@ -76,17 +76,17 @@ bool ReadDirectory::Execute(int request_id) {
void ReadDirectory::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
fileapi::AsyncFileUtil::EntryList entry_list;
const bool convert_result =
ConvertRequestValueToEntryList(result.Pass(), &entry_list);
DCHECK(convert_result);
callback_.Run(base::File::FILE_OK, entry_list, has_next);
callback_.Run(base::File::FILE_OK, entry_list, has_more);
}
void ReadDirectory::OnError(int /* request_id */, base::File::Error error) {
callback_.Run(
error, fileapi::AsyncFileUtil::EntryList(), false /* has_next */);
error, fileapi::AsyncFileUtil::EntryList(), false /* has_more */);
}
} // namespace operations
......
......@@ -38,7 +38,7 @@ class ReadDirectory : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -203,7 +203,7 @@ TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnSuccess) {
" }\n"
" }\n"
" ],\n"
" false\n" // has_next
" false\n" // has_more
"]\n";
int json_error_code;
......@@ -220,8 +220,8 @@ TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnSuccess) {
RequestValue::CreateForReadDirectorySuccess(params.Pass()));
ASSERT_TRUE(request_value.get());
const bool has_next = false;
read_directory.OnSuccess(kRequestId, request_value.Pass(), has_next);
const bool has_more = false;
read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more);
ASSERT_EQ(1u, callback_logger.events().size());
CallbackLogger::Event* event = callback_logger.events()[0];
......
......@@ -74,18 +74,18 @@ bool ReadFile::Execute(int request_id) {
void ReadFile::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
const int copy_result = CopyRequestValueToBuffer(
result.Pass(), buffer_, current_offset_, length_);
DCHECK_LE(0, copy_result);
DCHECK(!has_next || copy_result > 0);
DCHECK(!has_more || copy_result > 0);
if (copy_result > 0)
current_offset_ += copy_result;
callback_.Run(copy_result, has_next, base::File::FILE_OK);
callback_.Run(copy_result, has_more, base::File::FILE_OK);
}
void ReadFile::OnError(int /* request_id */, base::File::Error error) {
callback_.Run(0 /* chunk_length */, false /* has_next */, error);
callback_.Run(0 /* chunk_length */, false /* has_more */, error);
}
} // namespace operations
......
......@@ -45,7 +45,7 @@ class ReadFile : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -57,17 +57,17 @@ class CallbackLogger {
public:
class Event {
public:
Event(int chunk_length, bool has_next, base::File::Error result)
: chunk_length_(chunk_length), has_next_(has_next), result_(result) {}
Event(int chunk_length, bool has_more, base::File::Error result)
: chunk_length_(chunk_length), has_more_(has_more), result_(result) {}
virtual ~Event() {}
int chunk_length() const { return chunk_length_; }
bool has_next() const { return has_next_; }
bool has_more() const { return has_more_; }
base::File::Error result() const { return result_; }
private:
int chunk_length_;
bool has_next_;
bool has_more_;
base::File::Error result_;
DISALLOW_COPY_AND_ASSIGN(Event);
......@@ -76,8 +76,8 @@ class CallbackLogger {
CallbackLogger() : weak_ptr_factory_(this) {}
virtual ~CallbackLogger() {}
void OnReadFile(int chunk_length, bool has_next, base::File::Error result) {
events_.push_back(new Event(chunk_length, has_next, result));
void OnReadFile(int chunk_length, bool has_more, base::File::Error result) {
events_.push_back(new Event(chunk_length, has_more, result));
}
ScopedVector<Event>& events() { return events_; }
......@@ -202,14 +202,14 @@ TEST_F(FileSystemProviderOperationsReadFileTest, OnSuccess) {
EXPECT_TRUE(read_file.Execute(kRequestId));
const std::string data = "ABCDE";
const bool has_next = false;
const bool has_more = false;
base::ListValue value_as_list;
value_as_list.Set(0, new base::StringValue(kFileSystemId));
value_as_list.Set(1, new base::FundamentalValue(kRequestId));
value_as_list.Set(
2, base::BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size()));
value_as_list.Set(3, new base::FundamentalValue(has_next));
value_as_list.Set(3, new base::FundamentalValue(has_more));
scoped_ptr<Params> params(Params::Create(value_as_list));
ASSERT_TRUE(params.get());
......@@ -217,12 +217,12 @@ TEST_F(FileSystemProviderOperationsReadFileTest, OnSuccess) {
RequestValue::CreateForReadFileSuccess(params.Pass()));
ASSERT_TRUE(request_value.get());
read_file.OnSuccess(kRequestId, request_value.Pass(), has_next);
read_file.OnSuccess(kRequestId, request_value.Pass(), has_more);
ASSERT_EQ(1u, callback_logger.events().size());
CallbackLogger::Event* event = callback_logger.events()[0];
EXPECT_EQ(kLength, event->chunk_length());
EXPECT_FALSE(event->has_next());
EXPECT_FALSE(event->has_more());
EXPECT_EQ(data, std::string(io_buffer_->data(), kLength));
EXPECT_EQ(base::File::FILE_OK, event->result());
}
......
......@@ -30,7 +30,7 @@ bool Unmount::Execute(int request_id) {
void Unmount::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> /* result */,
bool /* has_next */) {
bool /* has_more */) {
callback_.Run(base::File::FILE_OK);
}
......
......@@ -38,7 +38,7 @@ class Unmount : public Operation {
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE;
bool has_more) OVERRIDE;
virtual void OnError(int request_id, base::File::Error error) OVERRIDE;
private:
......
......@@ -32,7 +32,7 @@ class ProvidedFileSystemInterface {
OpenFileCallback;
typedef base::Callback<
void(int chunk_length, bool has_next, base::File::Error result)>
void(int chunk_length, bool has_more, base::File::Error result)>
ReadChunkReceivedCallback;
// Mode of opening a file. Used by OpenFile().
......
// Copyright 2014 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.
// TODO(mtomasz): Move these test cases to operations/unmount_unittest.cc.
#include <string>
#include <vector>
#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/request_manager.h"
#include "chrome/common/extensions/api/file_system_provider.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/event_router.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace file_system_provider {
namespace {
const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
const int kExpectedRequestId = 1;
const char kFileSystemId[] = "camera-pictures";
const char kFileSystemName[] = "Camera Pictures";
class FakeEventRouter : public extensions::EventRouter {
public:
explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {}
virtual ~FakeEventRouter() {}
virtual void DispatchEventToExtension(const std::string& extension_id,
scoped_ptr<extensions::Event> event)
OVERRIDE {
extension_id_ = extension_id;
event_ = event.Pass();
}
const std::string& extension_id() const { return extension_id_; }
const extensions::Event* event() const { return event_.get(); }
private:
std::string extension_id_;
scoped_ptr<extensions::Event> event_;
DISALLOW_COPY_AND_ASSIGN(FakeEventRouter);
};
class EventLogger {
public:
EventLogger() : weak_ptr_factory_(this) {}
virtual ~EventLogger() {}
void OnStatusCallback(base::File::Error error) {
error_.reset(new base::File::Error(error));
}
base::File::Error* error() { return error_.get(); }
base::WeakPtr<EventLogger> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
private:
scoped_ptr<base::File::Error> error_;
base::WeakPtrFactory<EventLogger> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(EventLogger);
};
} // namespace
class FileSystemProviderProvidedFileSystemTest : public testing::Test {
protected:
FileSystemProviderProvidedFileSystemTest() {}
virtual ~FileSystemProviderProvidedFileSystemTest() {}
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile);
event_router_.reset(new FakeEventRouter(profile_.get()));
event_router_->AddEventListener(
extensions::api::file_system_provider::OnUnmountRequested::kEventName,
NULL,
kExtensionId);
const base::FilePath mount_path =
util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId);
file_system_info_.reset(new ProvidedFileSystemInfo(
kExtensionId, kFileSystemId, kFileSystemName, mount_path));
provided_file_system_.reset(
new ProvidedFileSystem(event_router_.get(), *file_system_info_.get()));
}
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
scoped_ptr<FakeEventRouter> event_router_;
scoped_ptr<ProvidedFileSystemInfo> file_system_info_;
scoped_ptr<ProvidedFileSystemInterface> provided_file_system_;
};
TEST_F(FileSystemProviderProvidedFileSystemTest, RequestUnmount_Success) {
EventLogger logger;
provided_file_system_->RequestUnmount(
base::Bind(&EventLogger::OnStatusCallback, logger.GetWeakPtr()));
base::RunLoop().RunUntilIdle();
// Verify that the event has been sent to the providing extension.
EXPECT_EQ(kExtensionId, event_router_->extension_id());
const extensions::Event* event = event_router_->event();
ASSERT_TRUE(event);
ASSERT_TRUE(event->event_args);
base::ListValue* event_args = event->event_args.get();
EXPECT_EQ(2u, event_args->GetSize());
std::string file_system_id;
EXPECT_TRUE(event_args->GetString(0, &file_system_id));
EXPECT_EQ(kFileSystemId, file_system_id);
// Remember the request id, and verify it is valid.
int request_id = 0;
EXPECT_TRUE(event_args->GetInteger(1, &request_id));
EXPECT_EQ(kExpectedRequestId, request_id);
// Callback should not be called, yet.
EXPECT_FALSE(logger.error());
// Simulate sending a success response from the providing extension.
RequestManager* request_manager = provided_file_system_->GetRequestManager();
ASSERT_TRUE(request_manager);
scoped_ptr<RequestValue> response;
bool reply_result = request_manager->FulfillRequest(
request_id, response.Pass(), false /* has_more */);
EXPECT_TRUE(reply_result);
// Callback should be called. Verify the error code.
ASSERT_TRUE(logger.error());
EXPECT_EQ(base::File::FILE_OK, *logger.error());
}
TEST_F(FileSystemProviderProvidedFileSystemTest, RequestUnmount_Error) {
EventLogger logger;
provided_file_system_->RequestUnmount(
base::Bind(&EventLogger::OnStatusCallback, logger.GetWeakPtr()));
base::RunLoop().RunUntilIdle();
// Verify that the event has been sent to the providing extension.
EXPECT_EQ(kExtensionId, event_router_->extension_id());
const extensions::Event* event = event_router_->event();
ASSERT_TRUE(event);
ASSERT_TRUE(event->event_args);
base::ListValue* event_args = event->event_args.get();
EXPECT_EQ(2u, event_args->GetSize());
std::string file_system_id;
EXPECT_TRUE(event_args->GetString(0, &file_system_id));
EXPECT_EQ(kFileSystemId, file_system_id);
// Remember the request id, and verify it is valid.
int request_id = 0;
EXPECT_TRUE(event_args->GetInteger(1, &request_id));
EXPECT_EQ(kExpectedRequestId, request_id);
// Simulate sending an error response from the providing extension.
RequestManager* request_manager = provided_file_system_->GetRequestManager();
ASSERT_TRUE(request_manager);
bool reply_result = request_manager->RejectRequest(
request_id, base::File::FILE_ERROR_NOT_FOUND);
EXPECT_TRUE(reply_result);
// Callback should be called. Verify the error code.
ASSERT_TRUE(logger.error());
EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, *logger.error());
}
} // namespace file_system_provider
} // namespace chromeos
......@@ -73,17 +73,17 @@ int RequestManager::CreateRequest(RequestType type,
bool RequestManager::FulfillRequest(int request_id,
scoped_ptr<RequestValue> response,
bool has_next) {
bool has_more) {
RequestMap::iterator request_it = requests_.find(request_id);
if (request_it == requests_.end())
return false;
request_it->second->handler->OnSuccess(request_id, response.Pass(), has_next);
request_it->second->handler->OnSuccess(request_id, response.Pass(), has_more);
FOR_EACH_OBSERVER(
Observer, observers_, OnRequestFulfilled(request_id, has_next));
Observer, observers_, OnRequestFulfilled(request_id, has_more));
if (!has_next)
if (!has_more)
DestroyRequest(request_id);
else
request_it->second->timeout_timer.Reset();
......
......@@ -47,11 +47,11 @@ class RequestManager {
virtual bool Execute(int request_id) = 0;
// Success callback invoked by the providing extension in response to
// Execute(). It may be called more than once, until |has_next| is set to
// Execute(). It may be called more than once, until |has_more| is set to
// false.
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) = 0;
bool has_more) = 0;
// Error callback invoked by the providing extension in response to
// Execute(). It can be called at most once. It can be also called if the
......@@ -91,12 +91,12 @@ class RequestManager {
// what kind of request it is.
int CreateRequest(RequestType type, scoped_ptr<HandlerInterface> handler);
// Handles successful response for the |request_id|. If |has_next| is false,
// Handles successful response for the |request_id|. If |has_more| is false,
// then the request is disposed, after handling the |response|. On error,
// returns false, and the request is disposed.
bool FulfillRequest(int request_id,
scoped_ptr<RequestValue> response,
bool has_next);
bool has_more);
// Handles error response for the |request_id|. If handling the error fails,
// returns false. Always disposes the request.
......
......@@ -38,20 +38,20 @@ class EventLogger {
class SuccessEvent {
public:
SuccessEvent(int request_id, scoped_ptr<RequestValue> result, bool has_next)
SuccessEvent(int request_id, scoped_ptr<RequestValue> result, bool has_more)
: request_id_(request_id),
result_(result.Pass()),
has_next_(has_next) {}
has_more_(has_more) {}
virtual ~SuccessEvent() {}
int request_id() { return request_id_; }
RequestValue* result() { return result_.get(); }
bool has_next() { return has_next_; }
bool has_more() { return has_more_; }
private:
int request_id_;
scoped_ptr<RequestValue> result_;
bool has_next_;
bool has_more_;
};
class ErrorEvent {
......@@ -77,9 +77,9 @@ class EventLogger {
void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) {
bool has_more) {
success_events_.push_back(
new SuccessEvent(request_id, result.Pass(), has_next));
new SuccessEvent(request_id, result.Pass(), has_more));
}
void OnError(int request_id, base::File::Error error) {
......@@ -123,9 +123,9 @@ class FakeHandler : public RequestManager::HandlerInterface {
// RequestManager::Handler overrides.
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_next) OVERRIDE {
bool has_more) OVERRIDE {
if (logger_.get())
logger_->OnSuccess(request_id, result.Pass(), has_next);
logger_->OnSuccess(request_id, result.Pass(), has_more);
}
// RequestManager::Handler overrides.
......@@ -304,10 +304,10 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill) {
scoped_ptr<RequestValue> response(
RequestValue::CreateForTesting("i-like-vanilla"));
const bool has_next = false;
const bool has_more = false;
bool result =
request_manager_->FulfillRequest(request_id, response.Pass(), has_next);
request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
EXPECT_TRUE(result);
ASSERT_EQ(1u, observer.fulfilled().size());
......@@ -322,14 +322,14 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill) {
const std::string* response_test_string = event->result()->testing_params();
ASSERT_TRUE(response_test_string);
EXPECT_EQ("i-like-vanilla", *response_test_string);
EXPECT_FALSE(event->has_next());
EXPECT_FALSE(event->has_more());
// Confirm, that the request is removed. Basically, fulfilling again for the
// same request, should fail.
{
scoped_ptr<RequestValue> response;
bool retry =
request_manager_->FulfillRequest(request_id, response.Pass(), has_next);
request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
EXPECT_FALSE(retry);
EXPECT_EQ(1u, observer.fulfilled().size());
}
......@@ -371,10 +371,10 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill_WithHasNext) {
EXPECT_EQ(request_id, observer.executed()[0].request_id());
scoped_ptr<RequestValue> response;
const bool has_next = true;
const bool has_more = true;
bool result =
request_manager_->FulfillRequest(request_id, response.Pass(), has_next);
request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
EXPECT_TRUE(result);
// Validate if the callback has correct arguments.
......@@ -382,18 +382,18 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill_WithHasNext) {
EXPECT_EQ(0u, logger.error_events().size());
EventLogger::SuccessEvent* event = logger.success_events()[0];
EXPECT_FALSE(event->result());
EXPECT_TRUE(event->has_next());
EXPECT_TRUE(event->has_more());
ASSERT_EQ(1u, observer.fulfilled().size());
EXPECT_EQ(request_id, observer.fulfilled()[0].request_id());
EXPECT_TRUE(observer.fulfilled()[0].has_more());
// Confirm, that the request is not removed (since it has has_next == true).
// Confirm, that the request is not removed (since it has has_more == true).
// Basically, fulfilling again for the same request, should not fail.
{
bool new_has_next = false;
bool new_has_more = false;
bool retry = request_manager_->FulfillRequest(
request_id, response.Pass(), new_has_next);
request_id, response.Pass(), new_has_more);
EXPECT_TRUE(retry);
ASSERT_EQ(2u, observer.fulfilled().size());
......@@ -401,12 +401,12 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndFulFill_WithHasNext) {
EXPECT_FALSE(observer.fulfilled()[1].has_more());
}
// Since |new_has_next| is false, then the request should be removed. To check
// Since |new_has_more| is false, then the request should be removed. To check
// it, try to fulfill again, what should fail.
{
bool new_has_next = false;
bool new_has_more = false;
bool retry = request_manager_->FulfillRequest(
request_id, response.Pass(), new_has_next);
request_id, response.Pass(), new_has_more);
EXPECT_FALSE(retry);
EXPECT_EQ(0u, observer.rejected().size());
}
......@@ -457,9 +457,9 @@ TEST_F(FileSystemProviderRequestManagerTest, CreateAndReject) {
// same request, should fail.
{
scoped_ptr<RequestValue> response;
bool has_next = false;
bool has_more = false;
bool retry =
request_manager_->FulfillRequest(request_id, response.Pass(), has_next);
request_manager_->FulfillRequest(request_id, response.Pass(), has_more);
EXPECT_FALSE(retry);
EXPECT_EQ(0u, observer.fulfilled().size());
}
......
......@@ -70,16 +70,16 @@ namespace fileSystemProvider {
callback MetadataCallback = void(EntryMetadata metadata);
// Success callback for the <code>onReadDirectoryRequested</code> event. If
// more entries will be returned, then <code>hasNext</code> must be true, and
// more entries will be returned, then <code>hasMore</code> must be true, and
// it has to be called again with additional entries. If no more entries are
// available, then <code>hasNext</code> must be set to false.
callback EntriesCallback = void(ResourceEntry[] entries, bool hasNext);
// available, then <code>hasMore</code> must be set to false.
callback EntriesCallback = void(ResourceEntry[] entries, bool hasMore);
// Success callback for the <code>onReadFileRequested</code> event. If more
// data will be returned, then <code>hasNext</code> must be true, and it
// data will be returned, then <code>hasMore</code> must be true, and it
// has to be called again with additional entries. If no more data is
// available, then <code>hasNext</code> must be set to false.
callback FileDataCallback = void(ArrayBuffer data, bool hasNext);
// available, then <code>hasMore</code> must be set to false.
callback FileDataCallback = void(ArrayBuffer data, bool hasMore);
interface Functions {
// Mounts a file system with the given <code>fileSystemId</code> and <code>
......
......@@ -40,7 +40,7 @@ namespace fileSystemProviderInternal {
DOMString fileSystemId,
long requestId,
fileSystemProvider.EntryMetadata[] entries,
boolean hasNext);
boolean hasMore);
// Internal. Error callback of the <code>onReadDirectoryRequested</code>
// event. Must be called when reading a directory fails.
......@@ -81,7 +81,7 @@ namespace fileSystemProviderInternal {
DOMString fileSystemId,
long requestId,
ArrayBuffer data,
boolean hasNext);
boolean hasMore);
// Internal. Error callback of the <code>onReadFileRequested</code>
// event. Must be called when reading a file fails.
......
......@@ -100,8 +100,8 @@ function onReadDirectoryRequested(
return;
}
onSuccess([TESTING_TIRAMISU_FILE], true /* has_next */);
onSuccess([TESTING_CANDIES_DIR], false /* has_next */);
onSuccess([TESTING_TIRAMISU_FILE], true /* hasMore */);
onSuccess([TESTING_CANDIES_DIR], false /* hasMore */);
}
/**
......
......@@ -198,7 +198,7 @@ function onReadFileRequested(
reader.onload = function(e) {
onSuccess(
e.target.result,
index < textToSendInChunks.length - 1 /* has_next */);
index < textToSendInChunks.length - 1 /* hasMore */);
};
reader.readAsArrayBuffer(new Blob([item]));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment