| 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_root.h" | 5 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/time/time.h" |
| 17 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 18 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 18 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h" | 19 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner_u
til.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "net/base/mime_util.h" | 21 #include "net/base/mime_util.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 using EntryList = storage::AsyncFileUtil::EntryList; | 25 using EntryList = storage::AsyncFileUtil::EntryList; |
| 25 | 26 |
| 26 namespace arc { | 27 namespace arc { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 weak_ptr_factory_.GetWeakPtr(), callback)); | 110 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId( | 113 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId( |
| 113 const GetFileInfoCallback& callback, | 114 const GetFileInfoCallback& callback, |
| 114 const std::string& document_id) { | 115 const std::string& document_id) { |
| 115 if (document_id.empty()) { | 116 if (document_id.empty()) { |
| 116 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); | 117 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); |
| 117 return; | 118 return; |
| 118 } | 119 } |
| 119 file_system_instance_util::GetDocumentOnIOThread( | 120 // Specially handle the root directory since Files app does not update the |
| 121 // list of file systems (left pane) until all volumes respond to GetMetadata |
| 122 // requests to root directories. |
| 123 if (document_id == root_document_id_) { |
| 124 base::File::Info info; |
| 125 info.size = -1; |
| 126 info.is_directory = true; |
| 127 info.is_symbolic_link = false; |
| 128 info.last_modified = info.last_accessed = info.creation_time = |
| 129 base::Time::UnixEpoch(); // arbitrary |
| 130 callback.Run(base::File::FILE_OK, info); |
| 131 return; |
| 132 } |
| 133 file_system_operation_runner_util::GetDocumentOnIOThread( |
| 120 authority_, document_id, | 134 authority_, document_id, |
| 121 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument, | 135 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument, |
| 122 weak_ptr_factory_.GetWeakPtr(), callback)); | 136 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 123 } | 137 } |
| 124 | 138 |
| 125 void ArcDocumentsProviderRoot::GetFileInfoWithDocument( | 139 void ArcDocumentsProviderRoot::GetFileInfoWithDocument( |
| 126 const GetFileInfoCallback& callback, | 140 const GetFileInfoCallback& callback, |
| 127 mojom::DocumentPtr document) { | 141 mojom::DocumentPtr document) { |
| 128 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 142 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 129 if (document.is_null()) { | 143 if (document.is_null()) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 242 } |
| 229 ResolveToDocumentIdRecursively(iter->second.document_id, | 243 ResolveToDocumentIdRecursively(iter->second.document_id, |
| 230 std::vector<base::FilePath::StringType>( | 244 std::vector<base::FilePath::StringType>( |
| 231 components.begin() + 1, components.end()), | 245 components.begin() + 1, components.end()), |
| 232 callback); | 246 callback); |
| 233 } | 247 } |
| 234 | 248 |
| 235 void ArcDocumentsProviderRoot::ReadDirectoryInternal( | 249 void ArcDocumentsProviderRoot::ReadDirectoryInternal( |
| 236 const std::string& document_id, | 250 const std::string& document_id, |
| 237 const ReadDirectoryInternalCallback& callback) { | 251 const ReadDirectoryInternalCallback& callback) { |
| 238 file_system_instance_util::GetChildDocumentsOnIOThread( | 252 file_system_operation_runner_util::GetChildDocumentsOnIOThread( |
| 239 authority_, document_id, | 253 authority_, document_id, |
| 240 base::Bind( | 254 base::Bind( |
| 241 &ArcDocumentsProviderRoot::ReadDirectoryInternalWithChildDocuments, | 255 &ArcDocumentsProviderRoot::ReadDirectoryInternalWithChildDocuments, |
| 242 weak_ptr_factory_.GetWeakPtr(), callback)); | 256 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 243 } | 257 } |
| 244 | 258 |
| 245 void ArcDocumentsProviderRoot::ReadDirectoryInternalWithChildDocuments( | 259 void ArcDocumentsProviderRoot::ReadDirectoryInternalWithChildDocuments( |
| 246 const ReadDirectoryInternalCallback& callback, | 260 const ReadDirectoryInternalCallback& callback, |
| 247 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children) { | 261 base::Optional<std::vector<mojom::DocumentPtr>> maybe_children) { |
| 248 if (!maybe_children) { | 262 if (!maybe_children) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 296 |
| 283 mapping[filename] = | 297 mapping[filename] = |
| 284 ThinDocument{document->document_id, | 298 ThinDocument{document->document_id, |
| 285 document->mime_type == kAndroidDirectoryMimeType}; | 299 document->mime_type == kAndroidDirectoryMimeType}; |
| 286 } | 300 } |
| 287 | 301 |
| 288 callback.Run(base::File::FILE_OK, std::move(mapping)); | 302 callback.Run(base::File::FILE_OK, std::move(mapping)); |
| 289 } | 303 } |
| 290 | 304 |
| 291 } // namespace arc | 305 } // namespace arc |
| OLD | NEW |