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

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: Fix tests 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/fileapi/arc_content_file_system_url_util.h "
12 #include "chrome/browser/chromeos/drive/file_system_util.h" 13 #include "chrome/browser/chromeos/drive/file_system_util.h"
13 #include "chrome/browser/chromeos/file_manager/app_id.h" 14 #include "chrome/browser/chromeos/file_manager/app_id.h"
14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 15 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 16 #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" 17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
17 #include "chrome/browser/extensions/extension_util.h" 18 #include "chrome/browser/extensions/extension_util.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "components/arc/arc_bridge_service.h"
21 #include "components/arc/arc_service_manager.h"
22 #include "components/arc/common/file_system.mojom.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,
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 193
177 parser.file_system()->GetMetadata( 194 parser.file_system()->GetMetadata(
178 parser.file_path(), 195 parser.file_path(),
179 chromeos::file_system_provider::ProvidedFileSystemInterface:: 196 chromeos::file_system_provider::ProvidedFileSystemInterface::
180 METADATA_FIELD_MIME_TYPE, 197 METADATA_FIELD_MIME_TYPE,
181 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem, 198 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem,
182 callback)); 199 callback));
183 return; 200 return;
184 } 201 }
185 202
203 if (base::FilePath(arc::kContentFileSystemMountPointPath).IsParent(path)) {
204 GURL arc_url = arc::PathToArcUrl(path);
205 auto* file_system_instance = ARC_GET_INSTANCE_FOR_METHOD(
Shuhei Takahashi (google) 2017/05/30 09:30:17 Please add ArcFileSystemOperationRunner::GetMimeTy
hashimoto 2017/05/30 10:51:23 Ugh, I totally forgot about that deferring feature
206 arc::ArcServiceManager::Get()->arc_bridge_service()->file_system(),
207 GetMimeType);
208 if (!file_system_instance) {
209 content::BrowserThread::PostTask(
210 content::BrowserThread::UI, FROM_HERE,
211 base::Bind(callback, false, std::string()));
212 return;
213 }
214 file_system_instance->GetMimeType(
215 arc_url.spec(),
216 base::Bind(&GetMimeTypeAfterGetMimeTypeForArcContentFileSystem,
217 callback));
218 return;
219 }
220
186 // We don't have a way to obtain metadata other than drive and FSP. Returns an 221 // We don't have a way to obtain metadata other than drive and FSP. Returns an
187 // error with empty MIME type, that leads fallback guessing mime type from 222 // error with empty MIME type, that leads fallback guessing mime type from
188 // file extensions. 223 // file extensions.
189 content::BrowserThread::PostTask( 224 content::BrowserThread::PostTask(
190 content::BrowserThread::UI, 225 content::BrowserThread::UI,
191 FROM_HERE, 226 FROM_HERE,
192 base::Bind(callback, false /* failure */, std::string())); 227 base::Bind(callback, false /* failure */, std::string()));
193 } 228 }
194 229
195 void IsNonNativeLocalPathDirectory( 230 void IsNonNativeLocalPathDirectory(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 backend->CreateInternalURL(file_system_context.get(), path); 267 backend->CreateInternalURL(file_system_context.get(), path);
233 268
234 content::BrowserThread::PostTask( 269 content::BrowserThread::PostTask(
235 content::BrowserThread::IO, FROM_HERE, 270 content::BrowserThread::IO, FROM_HERE,
236 base::Bind(&PrepareFileOnIOThread, file_system_context, internal_url, 271 base::Bind(&PrepareFileOnIOThread, file_system_context, internal_url,
237 google_apis::CreateRelayCallback(callback))); 272 google_apis::CreateRelayCallback(callback)));
238 } 273 }
239 274
240 } // namespace util 275 } // namespace util
241 } // namespace file_manager 276 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698