Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_root.cc

Issue 2580713004: mediaview: Implement ArcDocumentsProviderBackendDelegate. (Closed)
Patch Set: Remove cache layer. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file.h" 11 #include "base/files/file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" 16 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
17 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h" 17 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_instance_util.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "net/base/mime_util.h" 19 #include "net/base/mime_util.h"
20 #include "url/gurl.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 using EntryList = storage::AsyncFileUtil::EntryList; 23 using EntryList = storage::AsyncFileUtil::EntryList;
23 24
24 namespace arc { 25 namespace arc {
25 26
26 namespace { 27 namespace {
27 28
28 // Computes a file name for a document. 29 // Computes a file name for a document.
29 base::FilePath::StringType GetFileNameForDocument( 30 base::FilePath::StringType GetFileNameForDocument(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 void ArcDocumentsProviderRoot::ReadDirectory( 91 void ArcDocumentsProviderRoot::ReadDirectory(
91 const base::FilePath& path, 92 const base::FilePath& path,
92 const ReadDirectoryCallback& callback) { 93 const ReadDirectoryCallback& callback) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); 94 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94 ResolveToDocumentId( 95 ResolveToDocumentId(
95 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId, 96 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId,
96 weak_ptr_factory_.GetWeakPtr(), callback)); 97 weak_ptr_factory_.GetWeakPtr(), callback));
97 } 98 }
98 99
100 void ArcDocumentsProviderRoot::ResolveToContentUrl(
101 const base::FilePath& path,
102 const ResolveToContentUrlCallback& callback) {
103 DCHECK_CURRENTLY_ON(BrowserThread::IO);
104 ResolveToDocumentId(
105 path,
106 base::Bind(&ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId,
107 weak_ptr_factory_.GetWeakPtr(), callback));
108 }
109
99 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId( 110 void ArcDocumentsProviderRoot::GetFileInfoWithDocumentId(
100 const GetFileInfoCallback& callback, 111 const GetFileInfoCallback& callback,
101 const std::string& document_id) { 112 const std::string& document_id) {
102 if (document_id.empty()) { 113 if (document_id.empty()) {
103 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); 114 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info());
104 return; 115 return;
105 } 116 }
106 file_system_instance_util::GetDocumentOnIOThread( 117 file_system_instance_util::GetDocumentOnIOThread(
107 authority_, document_id, 118 authority_, document_id,
108 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument, 119 base::Bind(&ArcDocumentsProviderRoot::GetFileInfoWithDocument,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK_CURRENTLY_ON(BrowserThread::IO); 158 DCHECK_CURRENTLY_ON(BrowserThread::IO);
148 std::vector<storage::DirectoryEntry> entry_list; 159 std::vector<storage::DirectoryEntry> entry_list;
149 for (const auto& pair : mapping) { 160 for (const auto& pair : mapping) {
150 entry_list.emplace_back(pair.first, pair.second.is_directory 161 entry_list.emplace_back(pair.first, pair.second.is_directory
151 ? storage::DirectoryEntry::DIRECTORY 162 ? storage::DirectoryEntry::DIRECTORY
152 : storage::DirectoryEntry::FILE); 163 : storage::DirectoryEntry::FILE);
153 } 164 }
154 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */); 165 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */);
155 } 166 }
156 167
168 void ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId(
169 const ResolveToContentUrlCallback& callback,
170 const std::string& document_id) {
171 DCHECK_CURRENTLY_ON(BrowserThread::IO);
172 if (document_id.empty()) {
173 callback.Run(GURL());
174 return;
175 }
176 callback.Run(BuildDocumentUrl(authority_, document_id));
177 }
178
157 void ArcDocumentsProviderRoot::ResolveToDocumentId( 179 void ArcDocumentsProviderRoot::ResolveToDocumentId(
158 const base::FilePath& path, 180 const base::FilePath& path,
159 const ResolveToDocumentIdCallback& callback) { 181 const ResolveToDocumentIdCallback& callback) {
160 DCHECK_CURRENTLY_ON(BrowserThread::IO); 182 DCHECK_CURRENTLY_ON(BrowserThread::IO);
161 std::vector<base::FilePath::StringType> components; 183 std::vector<base::FilePath::StringType> components;
162 path.GetComponents(&components); 184 path.GetComponents(&components);
163 ResolveToDocumentIdRecursively(root_document_id_, components, callback); 185 ResolveToDocumentIdRecursively(root_document_id_, components, callback);
164 } 186 }
165 187
166 void ArcDocumentsProviderRoot::ResolveToDocumentIdRecursively( 188 void ArcDocumentsProviderRoot::ResolveToDocumentIdRecursively(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 268
247 mapping[filename] = 269 mapping[filename] =
248 ThinDocument{document->document_id, 270 ThinDocument{document->document_id,
249 document->mime_type == kAndroidDirectoryMimeType}; 271 document->mime_type == kAndroidDirectoryMimeType};
250 } 272 }
251 273
252 callback.Run(std::move(mapping)); 274 callback.Run(std::move(mapping));
253 } 275 }
254 276
255 } // namespace arc 277 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698