Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_ util.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_async_file_ util.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 7 #include "base/callback.h" | 10 #include "base/callback.h" |
| 8 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" | |
| 15 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root_map.h" | |
| 16 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | |
| 11 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 12 #include "storage/browser/blob/shareable_file_reference.h" | 18 #include "storage/browser/blob/shareable_file_reference.h" |
| 19 #include "storage/browser/fileapi/file_system_operation_context.h" | |
| 20 #include "storage/browser/fileapi/file_system_url.h" | |
| 13 | 21 |
| 14 using content::BrowserThread; | 22 using content::BrowserThread; |
| 15 | 23 |
| 16 namespace arc { | 24 namespace arc { |
| 17 | 25 |
| 18 ArcDocumentsProviderAsyncFileUtil::ArcDocumentsProviderAsyncFileUtil() = | 26 ArcDocumentsProviderAsyncFileUtil::ArcDocumentsProviderAsyncFileUtil( |
| 19 default; | 27 ArcDocumentsProviderRootMap* roots) |
| 28 : roots_(roots), weak_ptr_factory_(this) {} | |
| 20 | 29 |
| 21 ArcDocumentsProviderAsyncFileUtil::~ArcDocumentsProviderAsyncFileUtil() = | 30 ArcDocumentsProviderAsyncFileUtil::~ArcDocumentsProviderAsyncFileUtil() = |
| 22 default; | 31 default; |
| 23 | 32 |
| 24 void ArcDocumentsProviderAsyncFileUtil::CreateOrOpen( | 33 void ArcDocumentsProviderAsyncFileUtil::CreateOrOpen( |
| 25 std::unique_ptr<storage::FileSystemOperationContext> context, | 34 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 26 const storage::FileSystemURL& url, | 35 const storage::FileSystemURL& url, |
| 27 int file_flags, | 36 int file_flags, |
| 28 const CreateOrOpenCallback& callback) { | 37 const CreateOrOpenCallback& callback) { |
| 29 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 38 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 52 NOTREACHED(); // Read-only file system. | 61 NOTREACHED(); // Read-only file system. |
| 53 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 62 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
| 54 } | 63 } |
| 55 | 64 |
| 56 void ArcDocumentsProviderAsyncFileUtil::GetFileInfo( | 65 void ArcDocumentsProviderAsyncFileUtil::GetFileInfo( |
| 57 std::unique_ptr<storage::FileSystemOperationContext> context, | 66 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 58 const storage::FileSystemURL& url, | 67 const storage::FileSystemURL& url, |
| 59 int fields, | 68 int fields, |
| 60 const GetFileInfoCallback& callback) { | 69 const GetFileInfoCallback& callback) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 62 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 71 DCHECK_EQ(storage::kFileSystemTypeArcDocumentsProvider, url.type()); |
| 63 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); | 72 |
| 73 base::FilePath path; | |
| 74 ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path); | |
| 75 if (!root) { | |
| 76 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 root->GetFileInfo( | |
| 81 path, | |
| 82 base::Bind(&ArcDocumentsProviderAsyncFileUtil::OnGetFileInfo, | |
| 83 // It is guaranteed that |this| outlives |context|, so keep | |
| 84 // |context| until the operation finishes. | |
| 85 base::Unretained(this), base::Passed(std::move(context)), | |
| 86 callback)); | |
| 64 } | 87 } |
| 65 | 88 |
| 66 void ArcDocumentsProviderAsyncFileUtil::ReadDirectory( | 89 void ArcDocumentsProviderAsyncFileUtil::ReadDirectory( |
| 67 std::unique_ptr<storage::FileSystemOperationContext> context, | 90 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 68 const storage::FileSystemURL& url, | 91 const storage::FileSystemURL& url, |
| 69 const ReadDirectoryCallback& callback) { | 92 const ReadDirectoryCallback& callback) { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 71 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 94 DCHECK_EQ(storage::kFileSystemTypeArcDocumentsProvider, url.type()); |
| 72 callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), | 95 |
| 73 false /* has_more */); | 96 base::FilePath path; |
| 97 ArcDocumentsProviderRoot* root = roots_->ParseAndLookup(url, &path); | |
| 98 if (!root) { | |
| 99 callback.Run(base::File::FILE_ERROR_NOT_FOUND, EntryList(), false); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 root->ReadDirectory( | |
| 104 path, | |
| 105 base::Bind(&ArcDocumentsProviderAsyncFileUtil::OnReadDirectory, | |
| 106 // It is guaranteed that |this| outlives |context|, so keep | |
| 107 // |context| until the operation finishes. | |
| 108 // In this case we can't use base::Passed() because the | |
| 109 // callback is called multiple times with |has_more| = true. | |
| 110 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
| |
| 111 callback)); | |
| 74 } | 112 } |
| 75 | 113 |
| 76 void ArcDocumentsProviderAsyncFileUtil::Touch( | 114 void ArcDocumentsProviderAsyncFileUtil::Touch( |
| 77 std::unique_ptr<storage::FileSystemOperationContext> context, | 115 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 78 const storage::FileSystemURL& url, | 116 const storage::FileSystemURL& url, |
| 79 const base::Time& last_access_time, | 117 const base::Time& last_access_time, |
| 80 const base::Time& last_modified_time, | 118 const base::Time& last_modified_time, |
| 81 const StatusCallback& callback) { | 119 const StatusCallback& callback) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 83 NOTREACHED(); // Read-only file system. | 121 NOTREACHED(); // Read-only file system. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 std::unique_ptr<storage::FileSystemOperationContext> context, | 196 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 159 const storage::FileSystemURL& url, | 197 const storage::FileSystemURL& url, |
| 160 const CreateSnapshotFileCallback& callback) { | 198 const CreateSnapshotFileCallback& callback) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 162 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 200 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. |
| 163 callback.Run(base::File::FILE_ERROR_FAILED, base::File::Info(), | 201 callback.Run(base::File::FILE_ERROR_FAILED, base::File::Info(), |
| 164 base::FilePath(), | 202 base::FilePath(), |
| 165 scoped_refptr<storage::ShareableFileReference>()); | 203 scoped_refptr<storage::ShareableFileReference>()); |
| 166 } | 204 } |
| 167 | 205 |
| 206 void ArcDocumentsProviderAsyncFileUtil::OnGetFileInfo( | |
| 207 std::unique_ptr<storage::FileSystemOperationContext> context, | |
| 208 const GetFileInfoCallback& callback, | |
| 209 base::File::Error result, | |
| 210 const base::File::Info& file_info) { | |
| 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 212 callback.Run(result, file_info); | |
| 213 } | |
| 214 | |
| 215 void ArcDocumentsProviderAsyncFileUtil::OnReadDirectory( | |
| 216 storage::FileSystemOperationContext* context, | |
| 217 const ReadDirectoryCallback& callback, | |
| 218 base::File::Error result, | |
| 219 const EntryList& file_list, | |
| 220 bool has_more) { | |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 222 callback.Run(result, file_list, has_more); | |
| 223 } | |
| 224 | |
| 168 } // namespace arc | 225 } // namespace arc |
| OLD | NEW |