sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/mime_registry_impl.h" |
| 6 | |
| 7 | #include "base/files/file_path.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 8 | #include "base/memory/ptr_util.h" |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 9 | #include "content/public/browser/browser_thread.h" |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 10 | #include "mojo/public/cpp/bindings/strong_binding.h" |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 11 | #include "net/base/mime_util.h" |
| 12 | |
| 13 | namespace content { |
| 14 | |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 15 | MimeRegistryImpl::MimeRegistryImpl() = default; |
| 16 | |
| 17 | MimeRegistryImpl::~MimeRegistryImpl() = default; |
| 18 | |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 19 | // static |
ben | a5c972c | 2017-05-04 01:38:43 | [diff] [blame] | 20 | void MimeRegistryImpl::Create( |
ben | a5c972c | 2017-05-04 01:38:43 | [diff] [blame] | 21 | blink::mojom::MimeRegistryRequest request) { |
rockot | 8e66a08d | 2016-09-13 00:48:21 | [diff] [blame] | 22 | mojo::MakeStrongBinding(base::MakeUnique<MimeRegistryImpl>(), |
| 23 | std::move(request)); |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 24 | } |
| 25 | |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 26 | void MimeRegistryImpl::GetMimeTypeFromExtension( |
yzshen | 6b5ad7f2 | 2016-11-22 21:38:21 | [diff] [blame] | 27 | const std::string& extension, |
tzik | cf7bcd65 | 2017-06-15 04:19:30 | [diff] [blame] | 28 | GetMimeTypeFromExtensionCallback callback) { |
Sam McNally | 8373388 | 2017-07-13 00:59:01 | [diff] [blame] | 29 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 30 | std::string mime_type; |
yzshen | 6b5ad7f2 | 2016-11-22 21:38:21 | [diff] [blame] | 31 | net::GetMimeTypeFromExtension( |
sammc | 5a2900a | 2017-01-05 07:45:54 | [diff] [blame] | 32 | base::FilePath::FromUTF8Unsafe(extension).value(), &mime_type); |
tzik | cf7bcd65 | 2017-06-15 04:19:30 | [diff] [blame] | 33 | std::move(callback).Run(mime_type); |
sammc | c0fe274 | 2016-06-06 01:37:25 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | } // namespace content |