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

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

Issue 2715473003: mediaview: Support watchers in ArcDocumentsProviderRoot. (Closed)
Patch Set: Review ready. Created 3 years, 10 months 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"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 void ArcDocumentsProviderRoot::ReadDirectory( 89 void ArcDocumentsProviderRoot::ReadDirectory(
90 const base::FilePath& path, 90 const base::FilePath& path,
91 const ReadDirectoryCallback& callback) { 91 const ReadDirectoryCallback& callback) {
92 DCHECK_CURRENTLY_ON(BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
93 ResolveToDocumentId( 93 ResolveToDocumentId(
94 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId, 94 path, base::Bind(&ArcDocumentsProviderRoot::ReadDirectoryWithDocumentId,
95 weak_ptr_factory_.GetWeakPtr(), callback)); 95 weak_ptr_factory_.GetWeakPtr(), callback));
96 } 96 }
97 97
98 void ArcDocumentsProviderRoot::AddWatcher(
99 const base::FilePath& path,
100 const WatcherCallback& watcher_callback,
101 const StatusCallback& callback) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 if (path_to_watcher_id_.count(path)) {
104 callback.Run(base::File::FILE_ERROR_FAILED);
105 return;
106 }
107 ResolveToDocumentId(
108 path, base::Bind(&ArcDocumentsProviderRoot::AddWatcherWithDocumentId,
109 weak_ptr_factory_.GetWeakPtr(), path, watcher_callback,
110 callback));
111 }
112
113 void ArcDocumentsProviderRoot::RemoveWatcher(const base::FilePath& path,
114 const StatusCallback& callback) {
115 DCHECK_CURRENTLY_ON(BrowserThread::IO);
116 auto iter = path_to_watcher_id_.find(path);
117 if (iter == path_to_watcher_id_.end()) {
118 callback.Run(base::File::FILE_ERROR_FAILED);
119 return;
120 }
121 int64_t watcher_id = iter->second;
122 path_to_watcher_id_.erase(iter);
123 file_system_operation_runner_util::RemoveWatcherOnIOThread(
124 watcher_id, base::Bind(&ArcDocumentsProviderRoot::RemoveWatcherDone,
125 weak_ptr_factory_.GetWeakPtr(), callback));
126 }
127
98 void ArcDocumentsProviderRoot::ResolveToContentUrl( 128 void ArcDocumentsProviderRoot::ResolveToContentUrl(
99 const base::FilePath& path, 129 const base::FilePath& path,
100 const ResolveToContentUrlCallback& callback) { 130 const ResolveToContentUrlCallback& callback) {
101 DCHECK_CURRENTLY_ON(BrowserThread::IO); 131 DCHECK_CURRENTLY_ON(BrowserThread::IO);
102 ResolveToDocumentId( 132 ResolveToDocumentId(
103 path, 133 path,
104 base::Bind(&ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId, 134 base::Bind(&ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId,
105 weak_ptr_factory_.GetWeakPtr(), callback)); 135 weak_ptr_factory_.GetWeakPtr(), callback));
106 } 136 }
107 137
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 205 }
176 EntryList entry_list; 206 EntryList entry_list;
177 for (const auto& pair : mapping) { 207 for (const auto& pair : mapping) {
178 entry_list.emplace_back(pair.first, pair.second.is_directory 208 entry_list.emplace_back(pair.first, pair.second.is_directory
179 ? storage::DirectoryEntry::DIRECTORY 209 ? storage::DirectoryEntry::DIRECTORY
180 : storage::DirectoryEntry::FILE); 210 : storage::DirectoryEntry::FILE);
181 } 211 }
182 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */); 212 callback.Run(base::File::FILE_OK, entry_list, false /* has_more */);
183 } 213 }
184 214
215 void ArcDocumentsProviderRoot::AddWatcherWithDocumentId(
216 const base::FilePath& path,
217 const WatcherCallback& watcher_callback,
218 const StatusCallback& callback,
219 const std::string& document_id) {
220 DCHECK_CURRENTLY_ON(BrowserThread::IO);
221 if (document_id.empty()) {
222 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
223 return;
224 }
225 file_system_operation_runner_util::AddWatcherOnIOThread(
226 authority_, document_id, watcher_callback,
227 base::Bind(&ArcDocumentsProviderRoot::AddWatcherDone,
228 weak_ptr_factory_.GetWeakPtr(), path, callback));
229 }
230
231 void ArcDocumentsProviderRoot::AddWatcherDone(const base::FilePath& path,
232 const StatusCallback& callback,
233 int64_t watcher_id) {
234 DCHECK_CURRENTLY_ON(BrowserThread::IO);
235 if (watcher_id < 0) {
236 callback.Run(base::File::FILE_ERROR_FAILED);
237 return;
238 }
239 if (path_to_watcher_id_.count(path)) {
240 // Multiple watchers have been installed on the same file path in a race.
241 // Following the contract of WatcherManager, we reject all except the first.
242 file_system_operation_runner_util::RemoveWatcherOnIOThread(
243 watcher_id, base::Bind(&ArcDocumentsProviderRoot::AddWatcherAborted,
244 weak_ptr_factory_.GetWeakPtr(), callback));
245 return;
246 }
247 path_to_watcher_id_.insert(std::make_pair(path, watcher_id));
248 callback.Run(base::File::FILE_OK);
249 }
250
251 void ArcDocumentsProviderRoot::AddWatcherAborted(const StatusCallback& callback,
252 bool success) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 callback.Run(base::File::FILE_ERROR_FAILED);
255 }
256
257 void ArcDocumentsProviderRoot::RemoveWatcherDone(const StatusCallback& callback,
258 bool success) {
259 DCHECK_CURRENTLY_ON(BrowserThread::IO);
260 callback.Run(success ? base::File::FILE_OK : base::File::FILE_ERROR_FAILED);
261 }
262
185 void ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId( 263 void ArcDocumentsProviderRoot::ResolveToContentUrlWithDocumentId(
186 const ResolveToContentUrlCallback& callback, 264 const ResolveToContentUrlCallback& callback,
187 const std::string& document_id) { 265 const std::string& document_id) {
188 DCHECK_CURRENTLY_ON(BrowserThread::IO); 266 DCHECK_CURRENTLY_ON(BrowserThread::IO);
189 if (document_id.empty()) { 267 if (document_id.empty()) {
190 callback.Run(GURL()); 268 callback.Run(GURL());
191 return; 269 return;
192 } 270 }
193 callback.Run(BuildDocumentUrl(authority_, document_id)); 271 callback.Run(BuildDocumentUrl(authority_, document_id));
194 } 272 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 369
292 mapping[filename] = 370 mapping[filename] =
293 ThinDocument{document->document_id, 371 ThinDocument{document->document_id,
294 document->mime_type == kAndroidDirectoryMimeType}; 372 document->mime_type == kAndroidDirectoryMimeType};
295 } 373 }
296 374
297 callback.Run(base::File::FILE_OK, std::move(mapping)); 375 callback.Run(base::File::FILE_OK, std::move(mapping));
298 } 376 }
299 377
300 } // namespace arc 378 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698