| Index: chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc
|
| diff --git a/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc b/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc
|
| index 4b4a827e303d60ab9e473633f96a0f139980d9e8..d43bbac6416c53c208cd75ab92985405d32d0991 100644
|
| --- a/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc
|
| +++ b/chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc
|
| @@ -73,31 +73,28 @@ bool FakeProvidedFileSystem::GetEntry(const base::FilePath& entry_path,
|
| return true;
|
| }
|
|
|
| -void FakeProvidedFileSystem::RequestUnmount(
|
| +ProvidedFileSystemInterface::AbortCallback
|
| +FakeProvidedFileSystem::RequestUnmount(
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::GetMetadata(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::GetMetadata(
|
| const base::FilePath& entry_path,
|
| const ProvidedFileSystemInterface::GetMetadataCallback& callback) {
|
| const Entries::const_iterator entry_it = entries_.find(entry_path);
|
|
|
| if (entry_it == entries_.end()) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(
|
| - callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND));
|
| - return;
|
| + return PostAbortableTask(base::Bind(
|
| + callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND));
|
| }
|
|
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::ReadDirectory(
|
| +ProvidedFileSystemInterface::AbortCallback
|
| +FakeProvidedFileSystem::ReadDirectory(
|
| const base::FilePath& directory_path,
|
| const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) {
|
| fileapi::AsyncFileUtil::EntryList entry_list;
|
| @@ -116,49 +113,43 @@ void FakeProvidedFileSystem::ReadDirectory(
|
| }
|
| }
|
|
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(
|
| - callback, base::File::FILE_OK, entry_list, false /* has_more */));
|
| + return PostAbortableTask(base::Bind(
|
| + callback, base::File::FILE_OK, entry_list, false /* has_more */));
|
| }
|
|
|
| -void FakeProvidedFileSystem::OpenFile(const base::FilePath& entry_path,
|
| - OpenFileMode mode,
|
| - const OpenFileCallback& callback) {
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::OpenFile(
|
| + const base::FilePath& entry_path,
|
| + OpenFileMode mode,
|
| + const OpenFileCallback& callback) {
|
| const Entries::const_iterator entry_it = entries_.find(entry_path);
|
|
|
| if (entry_it == entries_.end()) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(
|
| - callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND));
|
| - return;
|
| + return PostAbortableTask(base::Bind(
|
| + callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND));
|
| }
|
|
|
| const int file_handle = ++last_file_handle_;
|
| opened_files_[file_handle] = entry_path;
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK));
|
| + return PostAbortableTask(
|
| + base::Bind(callback, file_handle, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::CloseFile(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CloseFile(
|
| int file_handle,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| const OpenedFilesMap::iterator opened_file_it =
|
| opened_files_.find(file_handle);
|
|
|
| if (opened_file_it == opened_files_.end()) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND));
|
| - return;
|
| + return PostAbortableTask(
|
| + base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND));
|
| }
|
|
|
| opened_files_.erase(opened_file_it);
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::ReadFile(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::ReadFile(
|
| int file_handle,
|
| net::IOBuffer* buffer,
|
| int64 offset,
|
| @@ -169,25 +160,21 @@ void FakeProvidedFileSystem::ReadFile(
|
|
|
| if (opened_file_it == opened_files_.end() ||
|
| opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback,
|
| 0 /* chunk_length */,
|
| false /* has_more */,
|
| base::File::FILE_ERROR_INVALID_OPERATION));
|
| - return;
|
| }
|
|
|
| const Entries::const_iterator entry_it =
|
| entries_.find(opened_file_it->second);
|
| if (entry_it == entries_.end()) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback,
|
| 0 /* chunk_length */,
|
| false /* has_more */,
|
| base::File::FILE_ERROR_INVALID_OPERATION));
|
| - return;
|
| }
|
|
|
| // Send the response byte by byte.
|
| @@ -196,83 +183,86 @@ void FakeProvidedFileSystem::ReadFile(
|
|
|
| // Reading behind EOF is fine, it will just return 0 bytes.
|
| if (current_offset >= entry_it->second.metadata.size || !current_length) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(callback,
|
| - 0 /* chunk_length */,
|
| - false /* has_more */,
|
| - base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback,
|
| + 0 /* chunk_length */,
|
| + false /* has_more */,
|
| + base::File::FILE_OK));
|
| }
|
|
|
| const FakeEntry& entry = entry_it->second;
|
| + std::vector<int> task_ids;
|
| while (current_offset < entry.metadata.size && current_length) {
|
| buffer->data()[current_offset - offset] = entry.contents[current_offset];
|
| const bool has_more =
|
| (current_offset + 1 < entry.metadata.size) && (current_length - 1);
|
| - base::MessageLoopProxy::current()->PostTask(
|
| + const int task_id = tracker_.PostTask(
|
| + base::MessageLoopProxy::current(),
|
| FROM_HERE,
|
| base::Bind(
|
| callback, 1 /* chunk_length */, has_more, base::File::FILE_OK));
|
| + task_ids.push_back(task_id);
|
| current_offset++;
|
| current_length--;
|
| }
|
| +
|
| + return base::Bind(&FakeProvidedFileSystem::AbortMany,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + task_ids);
|
| }
|
|
|
| -void FakeProvidedFileSystem::CreateDirectory(
|
| +ProvidedFileSystemInterface::AbortCallback
|
| +FakeProvidedFileSystem::CreateDirectory(
|
| const base::FilePath& directory_path,
|
| bool exclusive,
|
| bool recursive,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| // TODO(mtomasz): Implement it once needed.
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::DeleteEntry(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::DeleteEntry(
|
| const base::FilePath& entry_path,
|
| bool recursive,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| // TODO(mtomasz): Implement it once needed.
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::CreateFile(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CreateFile(
|
| const base::FilePath& file_path,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| const base::File::Error result = file_path.AsUTF8Unsafe() != kFakeFilePath
|
| ? base::File::FILE_ERROR_EXISTS
|
| : base::File::FILE_OK;
|
|
|
| - base::MessageLoopProxy::current()->PostTask(FROM_HERE,
|
| - base::Bind(callback, result));
|
| + return PostAbortableTask(base::Bind(callback, result));
|
| }
|
|
|
| -void FakeProvidedFileSystem::CopyEntry(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::CopyEntry(
|
| const base::FilePath& source_path,
|
| const base::FilePath& target_path,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + // TODO(mtomasz): Implement it once needed.
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::MoveEntry(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::MoveEntry(
|
| const base::FilePath& source_path,
|
| const base::FilePath& target_path,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + // TODO(mtomasz): Implement it once needed.
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::Truncate(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::Truncate(
|
| const base::FilePath& file_path,
|
| int64 length,
|
| const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + // TODO(mtomasz): Implement it once needed.
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| -void FakeProvidedFileSystem::WriteFile(
|
| +ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile(
|
| int file_handle,
|
| net::IOBuffer* buffer,
|
| int64 offset,
|
| @@ -283,26 +273,20 @@ void FakeProvidedFileSystem::WriteFile(
|
|
|
| if (opened_file_it == opened_files_.end() ||
|
| opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION));
|
| - return;
|
| }
|
|
|
| const Entries::iterator entry_it = entries_.find(opened_file_it->second);
|
| if (entry_it == entries_.end()) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION));
|
| - return;
|
| }
|
|
|
| FakeEntry* const entry = &entry_it->second;
|
| if (offset > entry->metadata.size) {
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE,
|
| + return PostAbortableTask(
|
| base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION));
|
| - return;
|
| }
|
|
|
| // Allocate the string size in advance.
|
| @@ -313,8 +297,7 @@ void FakeProvidedFileSystem::WriteFile(
|
|
|
| entry->contents.replace(offset, length, buffer->data(), length);
|
|
|
| - base::MessageLoopProxy::current()->PostTask(
|
| - FROM_HERE, base::Bind(callback, base::File::FILE_OK));
|
| + return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
|
| }
|
|
|
| const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
|
| @@ -338,5 +321,29 @@ FakeProvidedFileSystem::GetWeakPtr() {
|
| return weak_ptr_factory_.GetWeakPtr();
|
| }
|
|
|
| +ProvidedFileSystemInterface::AbortCallback
|
| +FakeProvidedFileSystem::PostAbortableTask(const base::Closure& callback) {
|
| + const int task_id =
|
| + tracker_.PostTask(base::MessageLoopProxy::current(), FROM_HERE, callback);
|
| + return base::Bind(
|
| + &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id);
|
| +}
|
| +
|
| +void FakeProvidedFileSystem::Abort(
|
| + int task_id,
|
| + const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| + tracker_.TryCancel(task_id);
|
| + callback.Run(base::File::FILE_OK);
|
| +}
|
| +
|
| +void FakeProvidedFileSystem::AbortMany(
|
| + const std::vector<int>& task_ids,
|
| + const fileapi::AsyncFileUtil::StatusCallback& callback) {
|
| + for (size_t i = 0; i < task_ids.size(); ++i) {
|
| + tracker_.TryCancel(task_ids[i]);
|
| + }
|
| + callback.Run(base::File::FILE_OK);
|
| +}
|
| +
|
| } // namespace file_system_provider
|
| } // namespace chromeos
|
|
|