| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/file_handlers/mime_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/filename_util.h" | 13 #include "net/base/filename_util.h" |
| 14 #include "net/base/mime_sniffer.h" | 14 #include "net/base/mime_sniffer.h" |
| 15 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
| 16 #include "storage/browser/fileapi/file_system_url.h" | 16 #include "storage/browser/fileapi/file_system_url.h" |
| 17 | 17 |
| 18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" | 19 #include "extensions/browser/api/extensions_api_client.h" |
| 20 #include "extensions/browser/api/file_handlers/non_native_file_system_delegate.h
" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char kMimeTypeApplicationOctetStream[] = "application/octet-stream"; | 27 const char kMimeTypeApplicationOctetStream[] = "application/octet-stream"; |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 base::Passed(&sniffed_mime_type), | 127 base::Passed(&sniffed_mime_type), |
| 127 callback)); | 128 callback)); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Fetches MIME type for a local path and returns it with a |callback|. | 131 // Fetches MIME type for a local path and returns it with a |callback|. |
| 131 void GetMimeTypeForLocalPath( | 132 void GetMimeTypeForLocalPath( |
| 132 Profile* profile, | 133 Profile* profile, |
| 133 const base::FilePath& local_path, | 134 const base::FilePath& local_path, |
| 134 const base::Callback<void(const std::string&)>& callback) { | 135 const base::Callback<void(const std::string&)>& callback) { |
| 135 #if defined(OS_CHROMEOS) | 136 #if defined(OS_CHROMEOS) |
| 136 if (file_manager::util::IsUnderNonNativeLocalPath(profile, local_path)) { | 137 NonNativeFileSystemDelegate* delegate = |
| 138 ExtensionsAPIClient::Get()->GetNonNativeFileSystemDelegate(); |
| 139 if (delegate && delegate->IsUnderNonNativeLocalPath(profile, local_path)) { |
| 137 // For non-native files, try to get the MIME type from metadata. If not | 140 // For non-native files, try to get the MIME type from metadata. If not |
| 138 // available, then try to guess from the extension. Never sniff (because | 141 // available, then try to guess from the extension. Never sniff (because |
| 139 // it can be very slow). | 142 // it can be very slow). |
| 140 file_manager::util::GetNonNativeLocalPathMimeType( | 143 delegate->GetNonNativeLocalPathMimeType( |
| 141 profile, | 144 profile, |
| 142 local_path, | 145 local_path, |
| 143 base::Bind(&OnGetMimeTypeFromMetadataForNonNativeLocalPathCompleted, | 146 base::Bind(&OnGetMimeTypeFromMetadataForNonNativeLocalPathCompleted, |
| 144 local_path, | 147 local_path, |
| 145 callback)); | 148 callback)); |
| 146 return; | 149 return; |
| 147 } | 150 } |
| 148 #endif | 151 #endif |
| 149 | 152 |
| 150 // For native local files, try to guess the mime from the extension. If | 153 // For native local files, try to guess the mime from the extension. If |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); | 219 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); |
| 217 // Release the callback to avoid a circullar reference in case an instance | 220 // Release the callback to avoid a circullar reference in case an instance |
| 218 // of this class is a member of a ref counted class, which instance is bound | 221 // of this class is a member of a ref counted class, which instance is bound |
| 219 // to this callback. | 222 // to this callback. |
| 220 callback_ = CompletionCallback(); | 223 callback_ = CompletionCallback(); |
| 221 } | 224 } |
| 222 } | 225 } |
| 223 | 226 |
| 224 } // namespace app_file_handler_util | 227 } // namespace app_file_handler_util |
| 225 } // namespace extensions | 228 } // namespace extensions |
| OLD | NEW |