Chromium Code Reviews| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.cc |
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.cc |
| index d14a96ac86b43c395a1063f0562ab92a9c412e50..2c070d87d791dbc8a0159446e8aef6f85d283a62 100644 |
| --- a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.cc |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.cc |
| @@ -4,19 +4,28 @@ |
| #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_util.h" |
| +#include <utility> |
| + |
| +#include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/files/file.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h" |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "storage/browser/blob/shareable_file_reference.h" |
| +#include "storage/browser/fileapi/file_system_operation_context.h" |
| +#include "storage/browser/fileapi/file_system_url.h" |
| using content::BrowserThread; |
| namespace arc { |
| -ArcDocumentsProviderAsyncFileUtil::ArcDocumentsProviderAsyncFileUtil() = |
| - default; |
| +ArcDocumentsProviderAsyncFileUtil::ArcDocumentsProviderAsyncFileUtil( |
| + ArcDocumentsProviderRootMap* roots) |
| + : roots_(roots), weak_ptr_factory_(this) {} |
| ArcDocumentsProviderAsyncFileUtil::~ArcDocumentsProviderAsyncFileUtil() = |
| default; |
| @@ -59,8 +68,22 @@ void ArcDocumentsProviderAsyncFileUtil::GetFileInfo( |
| int fields, |
| const GetFileInfoCallback& callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. |
| - callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); |
| + DCHECK_EQ(storage::kFileSystemTypeArcDocumentsProvider, url.type()); |
| + |
| + base::FilePath path; |
| + ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path); |
| + if (!root) { |
| + callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); |
| + return; |
| + } |
| + |
| + root->GetFileInfo( |
| + path, |
| + base::Bind(&ArcDocumentsProviderAsyncFileUtil::OnGetFileInfo, |
| + // It is guaranteed that |this| outlives |context|, so keep |
| + // |context| until the operation finishes. |
| + base::Unretained(this), base::Passed(std::move(context)), |
| + callback)); |
| } |
| void ArcDocumentsProviderAsyncFileUtil::ReadDirectory( |
| @@ -68,9 +91,24 @@ void ArcDocumentsProviderAsyncFileUtil::ReadDirectory( |
| const storage::FileSystemURL& url, |
| const ReadDirectoryCallback& callback) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. |
| - callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), |
| - false /* has_more */); |
| + DCHECK_EQ(storage::kFileSystemTypeArcDocumentsProvider, url.type()); |
| + |
| + base::FilePath path; |
| + ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path); |
| + if (!root) { |
| + callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), false); |
| + return; |
| + } |
| + |
| + root->ReadDirectory( |
| + path, |
| + base::Bind(&ArcDocumentsProviderAsyncFileUtil::OnReadDirectory, |
| + // It is guaranteed that |this| outlives |context|, so keep |
| + // |context| until the operation finishes. |
| + // In this case we can't use base::Passed() because the |
| + // callback is called multiple times with |has_more| = true. |
| + base::Unretained(this), base::Owned(context.release()), |
|
Luis Héctor Chávez
2016/12/14 20:53:50
Who will be responsible of deleting |context|, the
Shuhei Takahashi
2016/12/15 02:37:55
Hmm, maybe. I've changed the code to explicitly re
|
| + callback)); |
| } |
| void ArcDocumentsProviderAsyncFileUtil::Touch( |
| @@ -165,4 +203,23 @@ void ArcDocumentsProviderAsyncFileUtil::CreateSnapshotFile( |
| scoped_refptr<storage::ShareableFileReference>()); |
| } |
| +void ArcDocumentsProviderAsyncFileUtil::OnGetFileInfo( |
| + std::unique_ptr<storage::FileSystemOperationContext> context, |
| + const GetFileInfoCallback& callback, |
| + base::File::Error result, |
| + const base::File::Info& file_info) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + callback.Run(result, file_info); |
| +} |
| + |
| +void ArcDocumentsProviderAsyncFileUtil::OnReadDirectory( |
| + storage::FileSystemOperationContext* context, |
| + const ReadDirectoryCallback& callback, |
| + base::File::Error result, |
| + const EntryList& file_list, |
| + bool has_more) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + callback.Run(result, file_list, has_more); |
| +} |
| + |
| } // namespace arc |