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..764a245ab78e2684f4dd6352c73a03b7c2a9ee86 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,43 @@ 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)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
hirono
2014/08/06 08:33:50
How about adding a helper function to call PostTas
mtomasz
2014/08/08 06:29:40
Done.
|
} |
-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( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind( |
callback, EntryMetadata(), base::File::FILE_ERROR_NOT_FOUND)); |
- return; |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
- base::MessageLoopProxy::current()->PostTask( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind(callback, entry_it->second.metadata, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-void FakeProvidedFileSystem::ReadDirectory( |
+ProvidedFileSystemInterface::AbortCallback |
+FakeProvidedFileSystem::ReadDirectory( |
const base::FilePath& directory_path, |
const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { |
fileapi::AsyncFileUtil::EntryList entry_list; |
@@ -116,49 +128,68 @@ void FakeProvidedFileSystem::ReadDirectory( |
} |
} |
- base::MessageLoopProxy::current()->PostTask( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind( |
callback, base::File::FILE_OK, entry_list, false /* has_more */)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind( |
callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); |
- return; |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
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)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, file_handle, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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; |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
opened_files_.erase(opened_file_it); |
- base::MessageLoopProxy::current()->PostTask( |
- FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind(base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id)); |
} |
-void FakeProvidedFileSystem::ReadFile( |
+ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::ReadFile( |
int file_handle, |
net::IOBuffer* buffer, |
int64 offset, |
@@ -169,25 +200,31 @@ void FakeProvidedFileSystem::ReadFile( |
if (opened_file_it == opened_files_.end() || |
opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
- base::MessageLoopProxy::current()->PostTask( |
- FROM_HERE, |
- base::Bind(callback, |
- 0 /* chunk_length */, |
- false /* has_more */, |
- base::File::FILE_ERROR_INVALID_OPERATION)); |
- return; |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, |
+ 0 /* chunk_length */, |
+ false /* has_more */, |
+ base::File::FILE_ERROR_INVALID_OPERATION)); |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
const Entries::const_iterator entry_it = |
entries_.find(opened_file_it->second); |
if (entry_it == entries_.end()) { |
- base::MessageLoopProxy::current()->PostTask( |
- FROM_HERE, |
- base::Bind(callback, |
- 0 /* chunk_length */, |
- false /* has_more */, |
- base::File::FILE_ERROR_INVALID_OPERATION)); |
- return; |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, |
+ 0 /* chunk_length */, |
+ false /* has_more */, |
+ base::File::FILE_ERROR_INVALID_OPERATION)); |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
// Send the response byte by byte. |
@@ -196,83 +233,120 @@ 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)); |
+ const int task_id = tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, |
+ 0 /* chunk_length */, |
+ false /* has_more */, |
+ base::File::FILE_OK)); |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
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)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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)); |
+ const int task_id = tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, result)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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. |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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. |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-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. |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
-void FakeProvidedFileSystem::WriteFile( |
+ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile( |
int file_handle, |
net::IOBuffer* buffer, |
int64 offset, |
@@ -283,26 +357,35 @@ void FakeProvidedFileSystem::WriteFile( |
if (opened_file_it == opened_files_.end() || |
opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
- base::MessageLoopProxy::current()->PostTask( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
- return; |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
const Entries::iterator entry_it = entries_.find(opened_file_it->second); |
if (entry_it == entries_.end()) { |
- base::MessageLoopProxy::current()->PostTask( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
- return; |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
FakeEntry* const entry = &entry_it->second; |
if (offset > entry->metadata.size) { |
- base::MessageLoopProxy::current()->PostTask( |
+ const int task_id = tracker_.PostTask( |
+ base::MessageLoopProxy::current(), |
FROM_HERE, |
base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
- return; |
+ return base::Bind(&FakeProvidedFileSystem::Abort, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ task_id); |
} |
// Allocate the string size in advance. |
@@ -313,8 +396,12 @@ void FakeProvidedFileSystem::WriteFile( |
entry->contents.replace(offset, length, buffer->data(), length); |
- base::MessageLoopProxy::current()->PostTask( |
- FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
+ const int task_id = |
+ tracker_.PostTask(base::MessageLoopProxy::current(), |
+ FROM_HERE, |
+ base::Bind(callback, base::File::FILE_OK)); |
+ return base::Bind( |
+ &FakeProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), task_id); |
} |
const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() |
@@ -338,5 +425,21 @@ FakeProvidedFileSystem::GetWeakPtr() { |
return weak_ptr_factory_.GetWeakPtr(); |
} |
+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 |