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

Side by Side Diff: chrome/browser/chromeos/file_manager/filesystem_api_util.cc

Issue 2914433002: arc: Use the MIME type returned by the container to handle content URLs (Closed)
Patch Set: Address comments Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_manager/filesystem_api_util.h" 5 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "chrome/browser/chromeos/arc/arc_util.h"
13 #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h "
14 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h "
12 #include "chrome/browser/chromeos/drive/file_system_util.h" 15 #include "chrome/browser/chromeos/drive/file_system_util.h"
13 #include "chrome/browser/chromeos/file_manager/app_id.h" 16 #include "chrome/browser/chromeos/file_manager/app_id.h"
14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 18 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 19 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
17 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
18 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "components/arc/arc_service_manager.h"
19 #include "components/drive/chromeos/file_system_interface.h" 23 #include "components/drive/chromeos/file_system_interface.h"
20 #include "components/drive/file_errors.h" 24 #include "components/drive/file_errors.h"
21 #include "components/drive/file_system_core_util.h" 25 #include "components/drive/file_system_core_util.h"
22 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
24 #include "google_apis/drive/task_util.h" 28 #include "google_apis/drive/task_util.h"
25 #include "storage/browser/fileapi/file_system_context.h" 29 #include "storage/browser/fileapi/file_system_context.h"
26 30
27 namespace file_manager { 31 namespace file_manager {
28 namespace util { 32 namespace util {
(...skipping 23 matching lines...) Expand all
52 base::File::Error result) { 56 base::File::Error result) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 58
55 if (result != base::File::FILE_OK || !metadata->mime_type.get()) { 59 if (result != base::File::FILE_OK || !metadata->mime_type.get()) {
56 callback.Run(false, std::string()); 60 callback.Run(false, std::string());
57 return; 61 return;
58 } 62 }
59 callback.Run(true, *metadata->mime_type); 63 callback.Run(true, *metadata->mime_type);
60 } 64 }
61 65
66 // Helper function used to implement GetNonNativeLocalPathMimeType. It passes
67 // the returned mime type to the callback.
68 void GetMimeTypeAfterGetMimeTypeForArcContentFileSystem(
69 const base::Callback<void(bool, const std::string&)>& callback,
dcheng 2017/06/02 15:58:29 I didn't notice this earlier, but it might be nice
hashimoto 2017/06/05 04:08:56 Sounds good. Filed crbug.com/729442
70 const base::Optional<std::string>& mime_type) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 if (mime_type.has_value()) {
73 callback.Run(true, mime_type.value());
74 } else {
75 callback.Run(false, std::string());
76 }
77 }
78
62 // Helper function to converts a callback that takes boolean value to that takes 79 // Helper function to converts a callback that takes boolean value to that takes
63 // File::Error, by regarding FILE_OK as the only successful value. 80 // File::Error, by regarding FILE_OK as the only successful value.
64 void BoolCallbackAsFileErrorCallback( 81 void BoolCallbackAsFileErrorCallback(
65 const base::Callback<void(bool)>& callback, 82 const base::Callback<void(bool)>& callback,
66 base::File::Error error) { 83 base::File::Error error) {
67 return callback.Run(error == base::File::FILE_OK); 84 return callback.Run(error == base::File::FILE_OK);
68 } 85 }
69 86
70 // Part of PrepareFileOnIOThread. It tries to create a new file if the given 87 // Part of PrepareFileOnIOThread. It tries to create a new file if the given
71 // |url| is not already inhabited. 88 // |url| is not already inhabited.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 191
175 parser.file_system()->GetMetadata( 192 parser.file_system()->GetMetadata(
176 parser.file_path(), 193 parser.file_path(),
177 chromeos::file_system_provider::ProvidedFileSystemInterface:: 194 chromeos::file_system_provider::ProvidedFileSystemInterface::
178 METADATA_FIELD_MIME_TYPE, 195 METADATA_FIELD_MIME_TYPE,
179 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem, 196 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem,
180 callback)); 197 callback));
181 return; 198 return;
182 } 199 }
183 200
201 if (arc::IsArcAllowedForProfile(profile) &&
202 base::FilePath(arc::kContentFileSystemMountPointPath).IsParent(path)) {
203 GURL arc_url = arc::PathToArcUrl(path);
204 auto* runner = arc::ArcServiceManager::GetGlobalService<
205 arc::ArcFileSystemOperationRunner>();
206 if (!runner) {
207 content::BrowserThread::PostTask(
208 content::BrowserThread::UI, FROM_HERE,
209 base::Bind(callback, false, std::string()));
mtomasz 2017/06/05 04:29:55 nit: BindOnce
hashimoto 2017/06/05 04:55:37 Done.
210 return;
211 }
212 runner->GetMimeType(
213 arc_url, base::Bind(&GetMimeTypeAfterGetMimeTypeForArcContentFileSystem,
214 callback));
215 return;
216 }
217
184 // We don't have a way to obtain metadata other than drive and FSP. Returns an 218 // We don't have a way to obtain metadata other than drive and FSP. Returns an
185 // error with empty MIME type, that leads fallback guessing mime type from 219 // error with empty MIME type, that leads fallback guessing mime type from
186 // file extensions. 220 // file extensions.
187 content::BrowserThread::PostTask( 221 content::BrowserThread::PostTask(
188 content::BrowserThread::UI, FROM_HERE, 222 content::BrowserThread::UI, FROM_HERE,
189 base::BindOnce(callback, false /* failure */, std::string())); 223 base::BindOnce(callback, false /* failure */, std::string()));
190 } 224 }
191 225
192 void IsNonNativeLocalPathDirectory( 226 void IsNonNativeLocalPathDirectory(
193 Profile* profile, 227 Profile* profile,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 backend->CreateInternalURL(file_system_context.get(), path); 262 backend->CreateInternalURL(file_system_context.get(), path);
229 263
230 content::BrowserThread::PostTask( 264 content::BrowserThread::PostTask(
231 content::BrowserThread::IO, FROM_HERE, 265 content::BrowserThread::IO, FROM_HERE,
232 base::BindOnce(&PrepareFileOnIOThread, file_system_context, internal_url, 266 base::BindOnce(&PrepareFileOnIOThread, file_system_context, internal_url,
233 google_apis::CreateRelayCallback(callback))); 267 google_apis::CreateRelayCallback(callback)));
234 } 268 }
235 269
236 } // namespace util 270 } // namespace util
237 } // namespace file_manager 271 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698