| 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/media_galleries/fileapi/supported_audio_video_checker.h
" | 5 #include "chrome/browser/media_galleries/fileapi/supported_audio_video_checker.h
" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h" | 16 #include "chrome/browser/media_galleries/fileapi/safe_audio_video_checker.h" |
| 17 #include "components/mime_util/mime_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/base/mime_util.h" | 19 #include "net/base/mime_util.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class SupportedAudioVideoExtensions { | 23 class SupportedAudioVideoExtensions { |
| 23 public: | 24 public: |
| 24 SupportedAudioVideoExtensions() { | 25 SupportedAudioVideoExtensions() { |
| 25 std::vector<base::FilePath::StringType> extensions; | 26 std::vector<base::FilePath::StringType> extensions; |
| 26 net::GetExtensionsForMimeType("audio/*", &extensions); | 27 net::GetExtensionsForMimeType("audio/*", &extensions); |
| 27 net::GetExtensionsForMimeType("video/*", &extensions); | 28 net::GetExtensionsForMimeType("video/*", &extensions); |
| 28 for (size_t i = 0; i < extensions.size(); ++i) { | 29 for (size_t i = 0; i < extensions.size(); ++i) { |
| 29 std::string mime_type; | 30 std::string mime_type; |
| 30 if (net::GetWellKnownMimeTypeFromExtension(extensions[i], &mime_type) && | 31 if (net::GetWellKnownMimeTypeFromExtension(extensions[i], &mime_type) && |
| 31 net::IsSupportedMimeType(mime_type)) { | 32 mime_util::IsSupportedMimeType(mime_type)) { |
| 32 audio_video_extensions_.insert( | 33 audio_video_extensions_.insert( |
| 33 base::FilePath::kExtensionSeparator + extensions[i]); | 34 base::FilePath::kExtensionSeparator + extensions[i]); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 bool HasSupportedAudioVideoExtension(const base::FilePath& file) { | 39 bool HasSupportedAudioVideoExtension(const base::FilePath& file) { |
| 39 return ContainsKey(audio_video_extensions_, file.Extension()); | 40 return ContainsKey(audio_video_extensions_, file.Extension()); |
| 40 } | 41 } |
| 41 | 42 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void SupportedAudioVideoChecker::OnFileOpen(base::File file) { | 86 void SupportedAudioVideoChecker::OnFileOpen(base::File file) { |
| 86 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 87 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 87 if (!file.IsValid()) { | 88 if (!file.IsValid()) { |
| 88 callback_.Run(base::File::FILE_ERROR_SECURITY); | 89 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 92 safe_checker_ = new SafeAudioVideoChecker(file.Pass(), callback_); | 93 safe_checker_ = new SafeAudioVideoChecker(file.Pass(), callback_); |
| 93 safe_checker_->Start(); | 94 safe_checker_->Start(); |
| 94 } | 95 } |
| OLD | NEW |