| Index: extensions/browser/api/file_handlers/mime_util.cc
|
| diff --git a/chrome/browser/extensions/api/file_handlers/mime_util.cc b/extensions/browser/api/file_handlers/mime_util.cc
|
| similarity index 83%
|
| rename from chrome/browser/extensions/api/file_handlers/mime_util.cc
|
| rename to extensions/browser/api/file_handlers/mime_util.cc
|
| index 82e3cf970259fe2f122a294e8e67dc8ee4fae103..844937e617bebf7eb1f7b467df73607091439af8 100644
|
| --- a/chrome/browser/extensions/api/file_handlers/mime_util.cc
|
| +++ b/extensions/browser/api/file_handlers/mime_util.cc
|
| @@ -2,13 +2,13 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/extensions/api/file_handlers/mime_util.h"
|
| +#include "extensions/browser/api/file_handlers/mime_util.h"
|
|
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "build/build_config.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| +#include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "net/base/filename_util.h"
|
| #include "net/base/mime_sniffer.h"
|
| @@ -41,8 +41,7 @@ void SniffMimeType(const base::FilePath& local_path, std::string* result) {
|
| base::ReadFile(local_path, &content[0], content.size());
|
|
|
| if (bytes_read >= 0) {
|
| - net::SniffMimeType(&content[0],
|
| - bytes_read,
|
| + net::SniffMimeType(&content[0], bytes_read,
|
| net::FilePathToFileURL(local_path),
|
| std::string(), // type_hint (passes no hint)
|
| result);
|
| @@ -77,13 +76,10 @@ void OnGetMimeTypeFromMetadataForNonNativeLocalPathCompleted(
|
| std::string* const mime_type_from_extension_ptr =
|
| mime_type_from_extension.get();
|
| BrowserThread::PostBlockingPoolTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(base::IgnoreResult(&net::GetMimeTypeFromFile),
|
| - local_path,
|
| - mime_type_from_extension_ptr),
|
| + FROM_HERE, base::Bind(base::IgnoreResult(&net::GetMimeTypeFromFile),
|
| + local_path, mime_type_from_extension_ptr),
|
| base::Bind(&OnGetMimeTypeFromFileForNonNativeLocalPathCompleted,
|
| - base::Passed(&mime_type_from_extension),
|
| - callback));
|
| + base::Passed(&mime_type_from_extension), callback));
|
| }
|
| #endif
|
|
|
| @@ -121,31 +117,27 @@ void OnGetMimeTypeFromFileForNativeLocalPathCompleted(
|
| new std::string(kMimeTypeApplicationOctetStream));
|
| std::string* const sniffed_mime_type_ptr = sniffed_mime_type.get();
|
| BrowserThread::PostBlockingPoolTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(&SniffMimeType, local_path, sniffed_mime_type_ptr),
|
| + FROM_HERE, base::Bind(&SniffMimeType, local_path, sniffed_mime_type_ptr),
|
| base::Bind(&OnSniffMimeTypeForNativeLocalPathCompleted,
|
| - base::Passed(&sniffed_mime_type),
|
| - callback));
|
| + base::Passed(&sniffed_mime_type), callback));
|
| }
|
|
|
| // Fetches MIME type for a local path and returns it with a |callback|.
|
| void GetMimeTypeForLocalPath(
|
| - Profile* profile,
|
| + content::BrowserContext* context,
|
| const base::FilePath& local_path,
|
| const base::Callback<void(const std::string&)>& callback) {
|
| #if defined(OS_CHROMEOS)
|
| NonNativeFileSystemDelegate* delegate =
|
| ExtensionsAPIClient::Get()->GetNonNativeFileSystemDelegate();
|
| - if (delegate && delegate->IsUnderNonNativeLocalPath(profile, local_path)) {
|
| + if (delegate && delegate->IsUnderNonNativeLocalPath(context, local_path)) {
|
| // For non-native files, try to get the MIME type from metadata. If not
|
| // available, then try to guess from the extension. Never sniff (because
|
| // it can be very slow).
|
| delegate->GetNonNativeLocalPathMimeType(
|
| - profile,
|
| - local_path,
|
| + context, local_path,
|
| base::Bind(&OnGetMimeTypeFromMetadataForNonNativeLocalPathCompleted,
|
| - local_path,
|
| - callback));
|
| + local_path, callback));
|
| return;
|
| }
|
| #endif
|
| @@ -156,22 +148,16 @@ void GetMimeTypeForLocalPath(
|
| std::string* const mime_type_from_extension_ptr =
|
| mime_type_from_extension.get();
|
| BrowserThread::PostBlockingPoolTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(base::IgnoreResult(&net::GetMimeTypeFromFile),
|
| - local_path,
|
| - mime_type_from_extension_ptr),
|
| - base::Bind(&OnGetMimeTypeFromFileForNativeLocalPathCompleted,
|
| - local_path,
|
| - base::Passed(&mime_type_from_extension),
|
| - callback));
|
| + FROM_HERE, base::Bind(base::IgnoreResult(&net::GetMimeTypeFromFile),
|
| + local_path, mime_type_from_extension_ptr),
|
| + base::Bind(&OnGetMimeTypeFromFileForNativeLocalPathCompleted, local_path,
|
| + base::Passed(&mime_type_from_extension), callback));
|
| }
|
|
|
| -MimeTypeCollector::MimeTypeCollector(Profile* profile)
|
| - : profile_(profile), left_(0), weak_ptr_factory_(this) {
|
| -}
|
| +MimeTypeCollector::MimeTypeCollector(content::BrowserContext* context)
|
| + : context_(context), left_(0), weak_ptr_factory_(this) {}
|
|
|
| -MimeTypeCollector::~MimeTypeCollector() {
|
| -}
|
| +MimeTypeCollector::~MimeTypeCollector() {}
|
|
|
| void MimeTypeCollector::CollectForURLs(
|
| const std::vector<storage::FileSystemURL>& urls,
|
| @@ -203,11 +189,9 @@ void MimeTypeCollector::CollectForLocalPaths(
|
| }
|
|
|
| for (size_t i = 0; i < local_paths.size(); ++i) {
|
| - GetMimeTypeForLocalPath(profile_,
|
| - local_paths[i],
|
| + GetMimeTypeForLocalPath(context_, local_paths[i],
|
| base::Bind(&MimeTypeCollector::OnMimeTypeCollected,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - i));
|
| + weak_ptr_factory_.GetWeakPtr(), i));
|
| }
|
| }
|
|
|
|
|