diff options
-rw-r--r-- | base/string_split.cc | 19 | ||||
-rw-r--r-- | base/string_split_unittest.cc | 21 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api.cc | 2 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api_unittest.cc | 1 | ||||
-rw-r--r-- | net/base/mime_util.cc | 71 | ||||
-rw-r--r-- | net/base/mime_util_unittest.cc | 18 |
6 files changed, 62 insertions, 70 deletions
diff --git a/base/string_split.cc b/base/string_split.cc index ea694d5..cdf708b 100644 --- a/base/string_split.cc +++ b/base/string_split.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,16 +17,19 @@ static void SplitStringT(const STR& str, bool trim_whitespace, std::vector<STR>* r) { size_t last = 0; + size_t i; size_t c = str.size(); - for (size_t i = 0; i <= c; ++i) { + for (i = 0; i <= c; ++i) { if (i == c || str[i] == s) { - STR tmp(str, last, i - last); - if (trim_whitespace) - TrimWhitespace(tmp, TRIM_ALL, &tmp); - // Avoid converting an empty or all-whitespace source string into a vector - // of one empty string. - if (i != c || !r->empty() || !tmp.empty()) + size_t len = i - last; + STR tmp = str.substr(last, len); + if (trim_whitespace) { + STR t_tmp; + TrimWhitespace(tmp, TRIM_ALL, &t_tmp); + r->push_back(t_tmp); + } else { r->push_back(tmp); + } last = i + 1; } } diff --git a/base/string_split_unittest.cc b/base/string_split_unittest.cc index 5d4dafe..83e4d74 100644 --- a/base/string_split_unittest.cc +++ b/base/string_split_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -163,7 +163,8 @@ TEST(StringUtilTest, SplitString) { std::vector<std::wstring> r; SplitString(L"", L',', &r); - EXPECT_EQ(0U, r.size()); + ASSERT_EQ(1U, r.size()); + EXPECT_EQ(r[0], L""); r.clear(); SplitString(L"a,b,c", L',', &r); @@ -187,8 +188,9 @@ TEST(StringUtilTest, SplitString) { EXPECT_EQ(r[2], L"c"); r.clear(); - SplitString(L" ", L'*', &r); - EXPECT_EQ(0U, r.size()); + SplitString(L"", L'*', &r); + ASSERT_EQ(1U, r.size()); + EXPECT_EQ(r[0], L""); r.clear(); SplitString(L"foo", L'*', &r); @@ -264,17 +266,12 @@ TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) { TEST(StringSplitTest, StringSplitDontTrim) { std::vector<std::string> r; - SplitStringDontTrim(" ", '*', &r); - ASSERT_EQ(1U, r.size()); - EXPECT_EQ(r[0], " "); - r.clear(); - - SplitStringDontTrim("\t \ta\t ", '\t', &r); + SplitStringDontTrim("\t\ta\t", '\t', &r); ASSERT_EQ(4U, r.size()); EXPECT_EQ(r[0], ""); - EXPECT_EQ(r[1], " "); + EXPECT_EQ(r[1], ""); EXPECT_EQ(r[2], "a"); - EXPECT_EQ(r[3], " "); + EXPECT_EQ(r[3], ""); r.clear(); SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r); diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc index 3178975..6bbd8df 100644 --- a/chrome/common/extensions/api/extension_api.cc +++ b/chrome/common/extensions/api/extension_api.cc @@ -268,12 +268,10 @@ bool ExtensionAPI::IsPrivileged(const std::string& full_name) { std::vector<std::string> split; base::SplitString(full_name, '.', &split); std::reverse(split.begin(), split.end()); - CHECK(!split.empty()); // |full_name| was empty or only whitespace. api_name = split.back(); split.pop_back(); if (api_name == "experimental") { - CHECK(!split.empty()); // |full_name| was "experimental" alone. api_name += "." + split.back(); split.pop_back(); } diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc index 1c5a22e3..bf240e1 100644 --- a/chrome/common/extensions/api/extension_api_unittest.cc +++ b/chrome/common/extensions/api/extension_api_unittest.cc @@ -26,6 +26,7 @@ TEST(ExtensionAPI, IsPrivileged) { EXPECT_TRUE(extension_api.IsPrivileged("extension.lastError")); // Default unknown names to privileged for paranoia's sake. + EXPECT_TRUE(extension_api.IsPrivileged("")); EXPECT_TRUE(extension_api.IsPrivileged("<unknown-namespace>")); EXPECT_TRUE(extension_api.IsPrivileged("extension.<unknown-member>")); diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc index 6a5bf73..f9e72a4 100644 --- a/net/base/mime_util.cc +++ b/net/base/mime_util.cc @@ -55,24 +55,18 @@ class MimeUtil : public PlatformMimeUtil { private: friend struct base::DefaultLazyInstanceTraits<MimeUtil>; - - typedef base::hash_set<std::string> MimeMappings; - typedef std::map<std::string, MimeMappings> StrictMappings; - - MimeUtil(); - - // Returns true if |codecs| is nonempty and all the items in it are present in - // |supported_codecs|. - static bool AreSupportedCodecs(const MimeMappings& supported_codecs, - const std::vector<std::string>& codecs); + MimeUtil() { + InitializeMimeTypeMaps(); + } // For faster lookup, keep hash sets. void InitializeMimeTypeMaps(); - bool GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext, - bool include_platform_types, - std::string* mime_type) const; + bool GetMimeTypeFromExtensionHelper( + const FilePath::StringType& ext, bool include_platform_types, + std::string* mime_type) const; + typedef base::hash_set<std::string> MimeMappings; MimeMappings image_map_; MimeMappings media_map_; MimeMappings non_image_map_; @@ -80,6 +74,7 @@ class MimeUtil : public PlatformMimeUtil { MimeMappings view_source_map_; MimeMappings codecs_map_; + typedef std::map<std::string, base::hash_set<std::string> > StrictMappings; StrictMappings strict_format_map_; }; // class MimeUtil @@ -163,8 +158,7 @@ bool MimeUtil::GetMimeTypeFromExtension(const FilePath::StringType& ext, } bool MimeUtil::GetWellKnownMimeTypeFromExtension( - const FilePath::StringType& ext, - string* result) const { + const FilePath::StringType& ext, string* result) const { return GetMimeTypeFromExtensionHelper(ext, false, result); } @@ -176,9 +170,9 @@ bool MimeUtil::GetMimeTypeFromFile(const FilePath& file_path, return GetMimeTypeFromExtension(file_name_str.substr(1), result); } -bool MimeUtil::GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext, - bool include_platform_types, - string* result) const { +bool MimeUtil::GetMimeTypeFromExtensionHelper( + const FilePath::StringType& ext, bool include_platform_types, + string* result) const { // Avoids crash when unable to handle a long file path. See crbug.com/48733. const unsigned kMaxFilePathSize = 65536; if (ext.length() > kMaxFilePathSize) @@ -352,20 +346,6 @@ static const MediaFormatStrict format_codec_mappings[] = { { "audio/wav", "1" } }; -MimeUtil::MimeUtil() { - InitializeMimeTypeMaps(); -} - -// static -bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, - const std::vector<std::string>& codecs) { - for (size_t i = 0; i < codecs.size(); ++i) { - if (supported_codecs.find(codecs[i]) == supported_codecs.end()) - return false; - } - return !codecs.empty(); -} - void MimeUtil::InitializeMimeTypeMaps() { for (size_t i = 0; i < arraysize(supported_image_types); ++i) image_map_.insert(supported_image_types[i]); @@ -432,8 +412,8 @@ bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { IsSupportedNonImageMimeType(mime_type.c_str()); } -bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, - const std::string& mime_type) const { +bool MimeUtil::MatchesMimeType(const std::string &mime_type_pattern, + const std::string &mime_type) const { // verify caller is passing lowercase DCHECK_EQ(StringToLowerASCII(mime_type_pattern), mime_type_pattern); DCHECK_EQ(StringToLowerASCII(mime_type), mime_type); @@ -471,7 +451,12 @@ bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, bool MimeUtil::AreSupportedMediaCodecs( const std::vector<std::string>& codecs) const { - return AreSupportedCodecs(codecs_map_, codecs); + for (size_t i = 0; i < codecs.size(); ++i) { + if (codecs_map_.find(codecs[i]) == codecs_map_.end()) { + return false; + } + } + return true; } void MimeUtil::ParseCodecString(const std::string& codecs, @@ -500,12 +485,20 @@ bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { return true; } -bool MimeUtil::IsSupportedStrictMediaMimeType( - const std::string& mime_type, +bool MimeUtil::IsSupportedStrictMediaMimeType(const std::string& mime_type, const std::vector<std::string>& codecs) const { StrictMappings::const_iterator it = strict_format_map_.find(mime_type); - return (it != strict_format_map_.end()) && - AreSupportedCodecs(it->second, codecs); + + if (it == strict_format_map_.end()) + return false; + + const MimeMappings strict_codecs_map = it->second; + for (size_t i = 0; i < codecs.size(); ++i) { + if (strict_codecs_map.find(codecs[i]) == strict_codecs_map.end()) { + return false; + } + } + return true; } //---------------------------------------------------------------------------- diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc index c647294..a63c39e 100644 --- a/net/base/mime_util_unittest.cc +++ b/net/base/mime_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -104,26 +104,26 @@ TEST(MimeUtilTest, ParseCodecString) { { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, - { "", 0, { } }, - { "\"\"", 0, { } }, - { "\" \"", 0, { } }, + { "", 1, { "" } }, + { "\"\"", 1, { "" } }, { ",", 2, { "", "" } }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { std::vector<std::string> codecs_out; ParseCodecString(tests[i].original, &codecs_out, true); - ASSERT_EQ(tests[i].expected_size, codecs_out.size()); - for (size_t j = 0; j < tests[i].expected_size; ++j) + EXPECT_EQ(tests[i].expected_size, codecs_out.size()); + for (size_t j = 0; j < tests[i].expected_size; ++j) { EXPECT_EQ(tests[i].results[j], codecs_out[j]); + } } // Test without stripping the codec type. std::vector<std::string> codecs_out; ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); - ASSERT_EQ(2u, codecs_out.size()); - EXPECT_EQ("avc1.42E01E", codecs_out[0]); - EXPECT_EQ("mp4a.40.2", codecs_out[1]); + EXPECT_EQ(2u, codecs_out.size()); + EXPECT_STREQ("avc1.42E01E", codecs_out[0].c_str()); + EXPECT_STREQ("mp4a.40.2", codecs_out[1].c_str()); } } // namespace net |