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

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

Issue 2580713004: mediaview: Implement ArcDocumentsProviderBackendDelegate. (Closed)
Patch Set: ThreadChecker failure fix. 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (path.empty()) { 71 if (path.empty()) {
72 ReadDirectoryAfterCacheUpdate(path, callback); 72 ReadDirectoryAfterCacheUpdate(path, callback);
73 return; 73 return;
74 } 74 }
75 UpdateDirectoryCacheUpTo( 75 UpdateDirectoryCacheUpTo(
76 StripBaseName(path), 76 StripBaseName(path),
77 base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryAfterCacheUpdate, 77 base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryAfterCacheUpdate,
78 weak_ptr_factory_.GetWeakPtr(), path, callback)); 78 weak_ptr_factory_.GetWeakPtr(), path, callback));
79 } 79 }
80 80
81 void ArcDocumentsProviderRoot::ResolveToContentUrl(
82 const base::FilePath& path,
83 const ResolveToContentUrlCallback& callback) {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
85 // Skip a cache update if possible.
86 ArcDocumentsProviderDocument* entry = root_directory_->Lookup(path);
87 if (entry) {
88 ResolveToContentUrlAfterCacheUpdate(path, callback);
89 return;
90 }
91 UpdateDirectoryCacheUpTo(
92 path,
93 base::Bind(&ArcDocumentsProviderRoot::ResolveToContentUrlAfterCacheUpdate,
94 weak_ptr_factory_.GetWeakPtr(), path, callback));
95 }
96
81 void ArcDocumentsProviderRoot::GetFileInfoAfterCacheUpdate( 97 void ArcDocumentsProviderRoot::GetFileInfoAfterCacheUpdate(
82 const base::FilePath& path, 98 const base::FilePath& path,
83 const GetFileInfoCallback& callback) { 99 const GetFileInfoCallback& callback) {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO); 100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
85 ArcDocumentsProviderDocument* entry = root_directory_->Lookup(path); 101 ArcDocumentsProviderDocument* entry = root_directory_->Lookup(path);
86 if (!entry) { 102 if (!entry) {
87 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info()); 103 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info());
88 return; 104 return;
89 } 105 }
90 file_system_instance_util::GetDocumentOnIOThread( 106 file_system_instance_util::GetDocumentOnIOThread(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 166
151 std::vector<storage::DirectoryEntry> entry_list; 167 std::vector<storage::DirectoryEntry> entry_list;
152 for (const auto& pair : parent_directory->children()) { 168 for (const auto& pair : parent_directory->children()) {
153 entry_list.emplace_back(pair.first, pair.second->is_directory() 169 entry_list.emplace_back(pair.first, pair.second->is_directory()
154 ? storage::DirectoryEntry::DIRECTORY 170 ? storage::DirectoryEntry::DIRECTORY
155 : storage::DirectoryEntry::FILE); 171 : storage::DirectoryEntry::FILE);
156 } 172 }
157 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */); 173 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */);
158 } 174 }
159 175
176 void ArcDocumentsProviderRoot::ResolveToContentUrlAfterCacheUpdate(
177 const base::FilePath& path,
178 const ResolveToContentUrlCallback& callback) {
179 DCHECK_CURRENTLY_ON(BrowserThread::IO);
180 ArcDocumentsProviderDocument* entry = root_directory_->Lookup(path);
181 if (!entry) {
182 callback.Run(GURL());
183 return;
184 }
185 callback.Run(BuildDocumentUrl(authority_, entry->document_id()));
186 }
187
160 void ArcDocumentsProviderRoot::UpdateDirectoryCacheUpTo( 188 void ArcDocumentsProviderRoot::UpdateDirectoryCacheUpTo(
161 const base::FilePath& path, 189 const base::FilePath& path,
162 const base::Closure& callback) { 190 const base::Closure& callback) {
163 DCHECK_CURRENTLY_ON(BrowserThread::IO); 191 DCHECK_CURRENTLY_ON(BrowserThread::IO);
164 UpdateDirectoryCacheIter(base::FilePath(), path, callback); 192 UpdateDirectoryCacheIter(base::FilePath(), path, callback);
165 } 193 }
166 194
167 void ArcDocumentsProviderRoot::UpdateDirectoryCacheIter( 195 void ArcDocumentsProviderRoot::UpdateDirectoryCacheIter(
168 const base::FilePath& parent_directory_path, 196 const base::FilePath& parent_directory_path,
169 const base::FilePath& remaining_path, 197 const base::FilePath& remaining_path,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 parent_directory_path.Append(components[0]); 246 parent_directory_path.Append(components[0]);
219 base::FilePath next_remaining_path = 247 base::FilePath next_remaining_path =
220 base::FilePath::FromUTF8Unsafe(base::JoinString( 248 base::FilePath::FromUTF8Unsafe(base::JoinString(
221 Components(components.begin() + 1, components.end()), "/")); 249 Components(components.begin() + 1, components.end()), "/"));
222 250
223 UpdateDirectoryCacheIter(next_parent_directory_path, next_remaining_path, 251 UpdateDirectoryCacheIter(next_parent_directory_path, next_remaining_path,
224 callback); 252 callback);
225 } 253 }
226 254
227 } // namespace arc 255 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698