OLD | NEW |
---|---|
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 " | |
13 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h " | |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/chromeos/file_manager/app_id.h" | 15 #include "chrome/browser/chromeos/file_manager/app_id.h" |
14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
15 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 17 #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" | 18 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" |
17 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "components/arc/arc_service_manager.h" | |
19 #include "components/drive/chromeos/file_system_interface.h" | 22 #include "components/drive/chromeos/file_system_interface.h" |
20 #include "components/drive/file_errors.h" | 23 #include "components/drive/file_errors.h" |
21 #include "components/drive/file_system_core_util.h" | 24 #include "components/drive/file_system_core_util.h" |
22 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
24 #include "google_apis/drive/task_util.h" | 27 #include "google_apis/drive/task_util.h" |
25 #include "storage/browser/fileapi/file_system_context.h" | 28 #include "storage/browser/fileapi/file_system_context.h" |
26 | 29 |
27 namespace file_manager { | 30 namespace file_manager { |
28 namespace util { | 31 namespace util { |
(...skipping 23 matching lines...) Expand all Loading... | |
52 base::File::Error result) { | 55 base::File::Error result) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
54 | 57 |
55 if (result != base::File::FILE_OK || !metadata->mime_type.get()) { | 58 if (result != base::File::FILE_OK || !metadata->mime_type.get()) { |
56 callback.Run(false, std::string()); | 59 callback.Run(false, std::string()); |
57 return; | 60 return; |
58 } | 61 } |
59 callback.Run(true, *metadata->mime_type); | 62 callback.Run(true, *metadata->mime_type); |
60 } | 63 } |
61 | 64 |
65 // Helper function used to implement GetNonNativeLocalPathMimeType. It passes | |
66 // the returned mime type to the callback. | |
67 void GetMimeTypeAfterGetMimeTypeForArcContentFileSystem( | |
68 const base::Callback<void(bool, const std::string&)>& callback, | |
69 const base::Optional<std::string>& mime_type) { | |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
71 if (mime_type.has_value()) { | |
72 callback.Run(true, mime_type.value()); | |
73 } else { | |
74 callback.Run(false, std::string()); | |
75 } | |
76 } | |
77 | |
62 // Helper function to converts a callback that takes boolean value to that takes | 78 // 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. | 79 // File::Error, by regarding FILE_OK as the only successful value. |
64 void BoolCallbackAsFileErrorCallback( | 80 void BoolCallbackAsFileErrorCallback( |
65 const base::Callback<void(bool)>& callback, | 81 const base::Callback<void(bool)>& callback, |
66 base::File::Error error) { | 82 base::File::Error error) { |
67 return callback.Run(error == base::File::FILE_OK); | 83 return callback.Run(error == base::File::FILE_OK); |
68 } | 84 } |
69 | 85 |
70 // Part of PrepareFileOnIOThread. It tries to create a new file if the given | 86 // Part of PrepareFileOnIOThread. It tries to create a new file if the given |
71 // |url| is not already inhabited. | 87 // |url| is not already inhabited. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 192 |
177 parser.file_system()->GetMetadata( | 193 parser.file_system()->GetMetadata( |
178 parser.file_path(), | 194 parser.file_path(), |
179 chromeos::file_system_provider::ProvidedFileSystemInterface:: | 195 chromeos::file_system_provider::ProvidedFileSystemInterface:: |
180 METADATA_FIELD_MIME_TYPE, | 196 METADATA_FIELD_MIME_TYPE, |
181 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem, | 197 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem, |
182 callback)); | 198 callback)); |
183 return; | 199 return; |
184 } | 200 } |
185 | 201 |
202 if (base::FilePath(arc::kContentFileSystemMountPointPath).IsParent(path)) { | |
203 GURL arc_url = arc::PathToArcUrl(path); | |
204 auto* runner = arc::ArcServiceManager::GetGlobalService< | |
Shuhei Takahashi
2017/05/31 03:22:55
GetGlobalService() returns an instance regardless
hashimoto
2017/06/01 09:38:24
Done.
| |
205 arc::ArcFileSystemOperationRunner>(); | |
206 if (!runner) { | |
207 content::BrowserThread::PostTask( | |
208 content::BrowserThread::UI, FROM_HERE, | |
209 base::Bind(callback, false, std::string())); | |
210 return; | |
211 } | |
212 runner->GetMimeType( | |
213 arc_url, base::Bind(&GetMimeTypeAfterGetMimeTypeForArcContentFileSystem, | |
214 callback)); | |
215 return; | |
216 } | |
217 | |
186 // 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 |
187 // 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 |
188 // file extensions. | 220 // file extensions. |
189 content::BrowserThread::PostTask( | 221 content::BrowserThread::PostTask( |
190 content::BrowserThread::UI, | 222 content::BrowserThread::UI, |
191 FROM_HERE, | 223 FROM_HERE, |
192 base::Bind(callback, false /* failure */, std::string())); | 224 base::Bind(callback, false /* failure */, std::string())); |
193 } | 225 } |
194 | 226 |
195 void IsNonNativeLocalPathDirectory( | 227 void IsNonNativeLocalPathDirectory( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 backend->CreateInternalURL(file_system_context.get(), path); | 264 backend->CreateInternalURL(file_system_context.get(), path); |
233 | 265 |
234 content::BrowserThread::PostTask( | 266 content::BrowserThread::PostTask( |
235 content::BrowserThread::IO, FROM_HERE, | 267 content::BrowserThread::IO, FROM_HERE, |
236 base::Bind(&PrepareFileOnIOThread, file_system_context, internal_url, | 268 base::Bind(&PrepareFileOnIOThread, file_system_context, internal_url, |
237 google_apis::CreateRelayCallback(callback))); | 269 google_apis::CreateRelayCallback(callback))); |
238 } | 270 } |
239 | 271 |
240 } // namespace util | 272 } // namespace util |
241 } // namespace file_manager | 273 } // namespace file_manager |
OLD | NEW |