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 | |
|
hashimoto
2016/12/15 03:53:22
I don't understand why this becomes the reason to
Shuhei Takahashi
2016/12/15 05:21:53
From AsyncFileUtil comment:
// As far as an inst
Shuhei Takahashi
2016/12/15 05:26:15
Oh, BTW, you're right that weak_ptr_factory_ is us
hashimoto
2016/12/15 10:34:57
Sorry, I still don't understand why the said comme
| |
| 84 // |context| until the operation finishes. | |
| 85 base::Unretained(this), base::Passed(std::move(context)), | |
|
hashimoto
2016/12/15 03:53:22
Why don't you use the newly added WeakPtrFactory h
Shuhei Takahashi
2016/12/15 05:21:53
Ditto.
| |
| 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( | |
| 106 &ArcDocumentsProviderAsyncFileUtil::OnReadDirectory, | |
| 107 // It is guaranteed that |this| outlives |context|, so keep | |
|
hashimoto
2016/12/15 03:53:21
ditto.
Shuhei Takahashi
2016/12/15 05:21:53
Ditto.
| |
| 108 // |context| until the operation finishes. | |
| 109 // In this case we can't use base::Passed() because the callback | |
| 110 // might be called multiple times with |has_more| = true. | |
| 111 base::Unretained(this), | |
|
hashimoto
2016/12/15 03:53:22
ditto.
Shuhei Takahashi
2016/12/15 05:21:53
Ditto.
| |
| 112 base::Owned(new std::unique_ptr<storage::FileSystemOperationContext>( | |
| 113 std::move(context))), | |
| 114 callback)); | |
| 74 } | 115 } |
| 75 | 116 |
| 76 void ArcDocumentsProviderAsyncFileUtil::Touch( | 117 void ArcDocumentsProviderAsyncFileUtil::Touch( |
| 77 std::unique_ptr<storage::FileSystemOperationContext> context, | 118 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 78 const storage::FileSystemURL& url, | 119 const storage::FileSystemURL& url, |
| 79 const base::Time& last_access_time, | 120 const base::Time& last_access_time, |
| 80 const base::Time& last_modified_time, | 121 const base::Time& last_modified_time, |
| 81 const StatusCallback& callback) { | 122 const StatusCallback& callback) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 83 NOTREACHED(); // Read-only file system. | 124 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, | 199 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 159 const storage::FileSystemURL& url, | 200 const storage::FileSystemURL& url, |
| 160 const CreateSnapshotFileCallback& callback) { | 201 const CreateSnapshotFileCallback& callback) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 202 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 162 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. | 203 NOTIMPLEMENTED(); // TODO(crbug.com/671511): Implement this function. |
| 163 callback.Run(base::File::FILE_ERROR_FAILED, base::File::Info(), | 204 callback.Run(base::File::FILE_ERROR_FAILED, base::File::Info(), |
| 164 base::FilePath(), | 205 base::FilePath(), |
| 165 scoped_refptr<storage::ShareableFileReference>()); | 206 scoped_refptr<storage::ShareableFileReference>()); |
| 166 } | 207 } |
| 167 | 208 |
| 209 void ArcDocumentsProviderAsyncFileUtil::OnGetFileInfo( | |
| 210 std::unique_ptr<storage::FileSystemOperationContext> context, | |
| 211 const GetFileInfoCallback& callback, | |
| 212 base::File::Error result, | |
| 213 const base::File::Info& file_info) { | |
| 214 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 215 callback.Run(result, file_info); | |
| 216 } | |
| 217 | |
| 218 void ArcDocumentsProviderAsyncFileUtil::OnReadDirectory( | |
| 219 std::unique_ptr<storage::FileSystemOperationContext>* context, | |
| 220 const ReadDirectoryCallback& callback, | |
| 221 base::File::Error result, | |
| 222 const EntryList& file_list, | |
| 223 bool has_more) { | |
| 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 225 callback.Run(result, file_list, has_more); | |
| 226 // |has_more| = false indicates the last call, so release |context|. | |
| 227 if (!has_more) { | |
| 228 DCHECK(*context); | |
| 229 context->reset(); | |
| 230 } | |
| 231 } | |
| 232 | |
| 168 } // namespace arc | 233 } // namespace arc |
| OLD | NEW |