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

[fsp] Polish FakeProvidedFileSystem methods.

This patch does two things. (1) Always runs callbacks via a PostTask, (2)
fixes an incorrect expression in EOF detection.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273088 0039d316-1c4b-4281-b951-d872f2087c98
parent c6a39755
...@@ -148,13 +148,17 @@ void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path, ...@@ -148,13 +148,17 @@ void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path,
const OpenFileCallback& callback) { const OpenFileCallback& callback) {
if (file_path.AsUTF8Unsafe() != "/hello.txt" || if (file_path.AsUTF8Unsafe() != "/hello.txt" ||
mode == OPEN_FILE_MODE_WRITE || create) { mode == OPEN_FILE_MODE_WRITE || create) {
callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(
callback, 0 /* file_handle */, base::File::FILE_ERROR_SECURITY));
return; return;
} }
const int file_handle = ++last_file_handle_; const int file_handle = ++last_file_handle_;
opened_files_[file_handle] = file_path; opened_files_[file_handle] = file_path;
callback.Run(file_handle, base::File::FILE_OK); base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK));
} }
void FakeProvidedFileSystem::CloseFile( void FakeProvidedFileSystem::CloseFile(
...@@ -196,8 +200,8 @@ void FakeProvidedFileSystem::ReadFile( ...@@ -196,8 +200,8 @@ void FakeProvidedFileSystem::ReadFile(
size_t current_offset = static_cast<size_t>(offset); size_t current_offset = static_cast<size_t>(offset);
size_t current_length = static_cast<size_t>(length); size_t current_length = static_cast<size_t>(length);
// Reading behind EOF, is fine, it will just read 0 bytes. // Reading behind EOF is fine, it will just return 0 bytes.
if (current_offset > kFakeFileSize || !current_length) { if (current_offset >= kFakeFileSize || !current_length) {
base::MessageLoopProxy::current()->PostTask( base::MessageLoopProxy::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(callback, base::Bind(callback,
...@@ -210,7 +214,10 @@ void FakeProvidedFileSystem::ReadFile( ...@@ -210,7 +214,10 @@ void FakeProvidedFileSystem::ReadFile(
buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; buffer->data()[current_offset - offset] = kFakeFileText[current_offset];
const bool has_next = const bool has_next =
(current_offset + 1 < kFakeFileSize) && (current_length - 1); (current_offset + 1 < kFakeFileSize) && (current_length - 1);
callback.Run(1, has_next, base::File::FILE_OK); base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(
callback, 1 /* chunk_length */, has_next, base::File::FILE_OK));
current_offset++; current_offset++;
current_length--; current_length--;
} }
......
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