Commit 92940c99 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Clean up manifest parsing algorithm implementation.

This cleanup refactors content::ParseManifest(). The main outcome is
separating low-level string manipulation (previously using C-style
pointers) from the higher-level logic for interpreting manifest data.
The desired benefit is being able to easily reason about the (standard
and proprietary) AppCache features that Chrome supports.

The CL relies heavily on base::StringPiece for string parsing, which
uses a (start, length) representation. Updating this requires more work
than the previous (start, end) representation. The extra work should be
outweighed by the performance savings of the new approach.

* URLs are not re-encoded from std::wstring to UTF16.
* Keywords are encoded as static base::StringPiece instances, avoiding
  some strlen() calls.

Bug: 879224
Change-Id: Ia8ecdb9453a103b7c6bfed8bc80ecf159095afc5
Reviewed-on: https://chromium-review.googlesource.com/1192985
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588251}
parent fc6eae27
...@@ -61,12 +61,11 @@ enum ParseMode { ...@@ -61,12 +61,11 @@ enum ParseMode {
PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES
}; };
CONTENT_EXPORT bool ParseManifest( CONTENT_EXPORT bool ParseManifest(const GURL& manifest_url,
const GURL& manifest_url, const char* manifest_bytes,
const char* data, int manifest_size,
int length, ParseMode parse_mode,
ParseMode parse_mode, AppCacheManifest& manifest);
AppCacheManifest& manifest);
} // namespace content } // namespace content
......
...@@ -447,7 +447,8 @@ TEST(AppCacheManifestParserTest, UnusualUtf8) { ...@@ -447,7 +447,8 @@ TEST(AppCacheManifestParserTest, UnusualUtf8) {
PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES, PARSE_MANIFEST_ALLOWING_DANGEROUS_FEATURES,
manifest)); manifest));
base::hash_set<std::string> urls = manifest.explicit_urls; base::hash_set<std::string> urls = manifest.explicit_urls;
EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end()); EXPECT_TRUE(urls.find("http://bad.com/%EF%BF%BDinvalidutf8") != urls.end())
<< "manifest byte stream was passed through, not UTF-8-decoded";
EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end()); EXPECT_TRUE(urls.find("http://bad.com/nonbmp%F1%84%AB%BC") != urls.end());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment