Commit de26faac authored by lazyboy's avatar lazyboy Committed by Commit bot

Make GreasemonkeyApiJsString truly singleton.

Before this change, ::GetSource() would create a new string from
StringPiece every time.

BUG=622464

Review-Url: https://codereview.chromium.org/2258183003
Cr-Commit-Position: refs/heads/master@{#413478}
parent c0bfd647
......@@ -65,19 +65,21 @@ struct GreasemonkeyApiJsString {
blink::WebScriptSource GetSource() const;
private:
std::string source_;
blink::WebString source_;
};
// The below constructor, monstrous as it is, just makes a WebScriptSource from
// the GreasemonkeyApiJs resource.
GreasemonkeyApiJsString::GreasemonkeyApiJsString()
: source_(ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_GREASEMONKEY_API_JS)
.as_string()) {
GreasemonkeyApiJsString::GreasemonkeyApiJsString() {
base::StringPiece source_piece =
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_GREASEMONKEY_API_JS);
source_ =
blink::WebString::fromUTF8(source_piece.data(), source_piece.length());
}
blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const {
return blink::WebScriptSource(blink::WebString::fromUTF8(source_));
return blink::WebScriptSource(source_);
}
base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api =
......
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