Chromium Code Reviews| Index: net/base/mime_util.cc |
| diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
| index 8a83417371336dd914c25f717833dfd77a4b82b5..8bccfb3fc2c049d6a110717c438795a3bbeb8896 100644 |
| --- a/net/base/mime_util.cc |
| +++ b/net/base/mime_util.cc |
| @@ -459,16 +459,20 @@ static const StandardType kStandardTypes[] = { |
| { NULL, NULL, 0 } |
| }; |
| +template <size_t N> |
| void GetExtensionsFromHardCodedMappings( |
|
xunjieli
2017/01/31 17:21:29
nit: Could you add a comment on this function? (hi
eroman
2017/01/31 17:41:30
Done, good idea.
|
| - const MimeInfo* mappings, |
| - size_t mappings_len, |
| - const std::string& leading_mime_type, |
| + const MimeInfo (&mappings)[N], |
| + const std::string& mime_type, |
| + bool prefix_match, |
| std::unordered_set<base::FilePath::StringType>* extensions) { |
| - for (size_t i = 0; i < mappings_len; ++i) { |
| - if (base::StartsWith(mappings[i].mime_type, leading_mime_type, |
| - base::CompareCase::INSENSITIVE_ASCII)) { |
| + for (const auto& mapping : mappings) { |
| + base::StringPiece cur_mime_type(mapping.mime_type); |
| + |
| + if (base::StartsWith(cur_mime_type, mime_type, |
| + base::CompareCase::INSENSITIVE_ASCII) && |
| + (prefix_match || (cur_mime_type.length() == mime_type.length()))) { |
| for (const base::StringPiece& this_extension : base::SplitStringPiece( |
| - mappings[i].extensions, ",", base::TRIM_WHITESPACE, |
| + mapping.extensions, ",", base::TRIM_WHITESPACE, |
| base::SPLIT_WANT_ALL)) { |
| #if defined(OS_WIN) |
| extensions->insert(base::UTF8ToUTF16(this_extension)); |
| @@ -492,13 +496,11 @@ void GetExtensionsHelper( |
| // Also look up the extensions from hard-coded mappings in case that some |
| // supported extensions are not registered in the system registry, like ogg. |
| - GetExtensionsFromHardCodedMappings(kPrimaryMappings, |
| - arraysize(kPrimaryMappings), |
| - leading_mime_type, extensions); |
| + GetExtensionsFromHardCodedMappings(kPrimaryMappings, leading_mime_type, true, |
| + extensions); |
| - GetExtensionsFromHardCodedMappings(kSecondaryMappings, |
| - arraysize(kSecondaryMappings), |
| - leading_mime_type, extensions); |
| + GetExtensionsFromHardCodedMappings(kSecondaryMappings, leading_mime_type, |
| + true, extensions); |
| } |
| // Note that the elements in the source set will be appended to the target |
| @@ -561,12 +563,10 @@ void GetExtensionsForMimeType( |
| // Also look up the extensions from hard-coded mappings in case that some |
| // supported extensions are not registered in the system registry, like ogg. |
| - GetExtensionsFromHardCodedMappings(kPrimaryMappings, |
| - arraysize(kPrimaryMappings), mime_type, |
| + GetExtensionsFromHardCodedMappings(kPrimaryMappings, mime_type, false, |
| &unique_extensions); |
| - GetExtensionsFromHardCodedMappings(kSecondaryMappings, |
| - arraysize(kSecondaryMappings), mime_type, |
| + GetExtensionsFromHardCodedMappings(kSecondaryMappings, mime_type, false, |
| &unique_extensions); |
| } |