| 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 "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 17 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 18 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h" | 18 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
| 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 using EntryList = storage::AsyncFileUtil::EntryList; | 24 using EntryList = storage::AsyncFileUtil::EntryList; |
| 24 | 25 |
| 25 namespace arc { | 26 namespace arc { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Computes a file name for a document. | 30 // Computes a file name for a document. |
| 30 // TODO(crbug.com/675868): Consolidate with the similar logic for Drive. | 31 // TODO(crbug.com/675868): Consolidate with the similar logic for Drive. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 92 |
| 92 void ArcDocumentsProviderRoot::ReadDirectory( | 93 void ArcDocumentsProviderRoot::ReadDirectory( |
| 93 const base::FilePath& path, | 94 const base::FilePath& path, |
| 94 const ReadDirectoryCallback& callback) { | 95 const ReadDirectoryCallback& callback) { |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 96 ResolveToDocumentId( | 97 ResolveToDocumentId( |
| 97 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId, | 98 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId, |
| 98 weak_ptr_factory_.GetWeakPtr(), callback)); | 99 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 99 } | 100 } |
| 100 | 101 |
| 102 void ArcDocumentsProviderRoot::ResolveToContentUrl( |
| 103 const base::FilePath& path, |
| 104 const ResolveToContentUrlCallback& callback) { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 106 ResolveToDocumentId( |
| 107 path, |
| 108 base::Bind(&ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId, |
| 109 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 110 } |
| 111 |
| 101 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId( | 112 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId( |
| 102 const GetFileInfoCallback& callback, | 113 const GetFileInfoCallback& callback, |
| 103 const std::string& document_id) { | 114 const std::string& document_id) { |
| 104 if (document_id.empty()) { | 115 if (document_id.empty()) { |
| 105 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); | 116 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); |
| 106 return; | 117 return; |
| 107 } | 118 } |
| 108 file_system_instance_util::GetDocumentOnIOThread( | 119 file_system_instance_util::GetDocumentOnIOThread( |
| 109 authority_, document_id, | 120 authority_, document_id, |
| 110 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument, | 121 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 166 } |
| 156 EntryList entry_list; | 167 EntryList entry_list; |
| 157 for (const auto& pair : mapping) { | 168 for (const auto& pair : mapping) { |
| 158 entry_list.emplace_back(pair.first, pair.second.is_directory | 169 entry_list.emplace_back(pair.first, pair.second.is_directory |
| 159 ? storage::DirectoryEntry::DIRECTORY | 170 ? storage::DirectoryEntry::DIRECTORY |
| 160 : storage::DirectoryEntry::FILE); | 171 : storage::DirectoryEntry::FILE); |
| 161 } | 172 } |
| 162 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */); | 173 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */); |
| 163 } | 174 } |
| 164 | 175 |
| 176 void ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId( |
| 177 const ResolveToContentUrlCallback& callback, |
| 178 const std::string& document_id) { |
| 179 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 180 if (document_id.empty()) { |
| 181 callback.Run(GURL()); |
| 182 return; |
| 183 } |
| 184 callback.Run(BuildDocumentUrl(authority_, document_id)); |
| 185 } |
| 186 |
| 165 void ArcDocumentsProviderRoot::ResolveToDocumentId( | 187 void ArcDocumentsProviderRoot::ResolveToDocumentId( |
| 166 const base::FilePath& path, | 188 const base::FilePath& path, |
| 167 const ResolveToDocumentIdCallback& callback) { | 189 const ResolveToDocumentIdCallback& callback) { |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 190 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 169 std::vector<base::FilePath::StringType> components; | 191 std::vector<base::FilePath::StringType> components; |
| 170 path.GetComponents(&components); | 192 path.GetComponents(&components); |
| 171 ResolveToDocumentIdRecursively(root_document_id_, components, callback); | 193 ResolveToDocumentIdRecursively(root_document_id_, components, callback); |
| 172 } | 194 } |
| 173 | 195 |
| 174 void ArcDocumentsProviderRoot::ResolveToDocumentIdRecursively( | 196 void ArcDocumentsProviderRoot::ResolveToDocumentIdRecursively( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 282 |
| 261 mapping[filename] = | 283 mapping[filename] = |
| 262 ThinDocument{document->document_id, | 284 ThinDocument{document->document_id, |
| 263 document->mime_type == kAndroidDirectoryMimeType}; | 285 document->mime_type == kAndroidDirectoryMimeType}; |
| 264 } | 286 } |
| 265 | 287 |
| 266 callback.Run(base::File::FILE_OK, std::move(mapping)); | 288 callback.Run(base::File::FILE_OK, std::move(mapping)); |
| 267 } | 289 } |
| 268 | 290 |
| 269 } // namespace arc | 291 } // namespace arc |
| OLD | NEW |