Commit 4f213b39 authored by Maksim Sadym's avatar Maksim Sadym Committed by Commit Bot

[devtools] Use `ExecuteJavaScriptMethod` in DevTools

rebase CL 2044170 part 2.
part 1 was merged in CL 2431864.

DevTools uses `ExecuteJavaScriptMethod` instead of `ExecuteJavaScript`, which should reduce serialisation/deserialisation overhead.

Loading Chrome DevTools on the page https://www.facebook.com/Shakira:
Before:
  V8.CompileCode, 130.326 ms, 2227 times
  V8.ParseProgram, 49.329 ms, 1878 times

After:
  V8.CompileCode, 18.571 ms, 343 times
  V8.ParseProgram, 0.053ms, 2 times

Loading Chrome DevTools on Chrome DevTools on the page https://www.facebook.com/Shakira:
DevTools on DevTools
Before:
  V8.CompileCode, 180.928 ms, 3708
  V8.ParseProgram, 59.535 ms, 3700
After:
  V8.CompileCode, 4.956 ms, 92
  V8.ParseFunction, 1.945 ms, 92


Bug: chromium:1029427
Change-Id: I78011c8f80a99c85d65354fb4a8a776491ac4f3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442012
Commit-Queue: Maksim Sadym <sadym@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813641}
parent cb971089
......@@ -397,5 +397,5 @@ void PortForwardingStatusSerializer::PortStatusChanged(
sit->first->serial().c_str());
result.Set(device_id, std::move(device_status_dict));
}
callback_.Run(result);
callback_.Run(std::move(result));
}
......@@ -68,7 +68,7 @@ class DevToolsTargetsUIHandler {
class PortForwardingStatusSerializer
: private DevToolsAndroidBridge::PortForwardingListener {
public:
typedef base::Callback<void(const base::Value&)> Callback;
typedef base::Callback<void(base::Value)> Callback;
PortForwardingStatusSerializer(const Callback& callback, Profile* profile);
~PortForwardingStatusSerializer() override;
......
......@@ -15,7 +15,6 @@
#include "base/command_line.h"
#include "base/guid.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
#include "base/macros.h"
#include "base/metrics/histogram_functions.h"
......@@ -519,7 +518,7 @@ class DevToolsUIBindings::NetworkResourceLoader
}
bindings_->CallClientMethod("DevToolsAPI", "streamWrite",
base::Value(stream_id_), chunkValue,
base::Value(stream_id_), std::move(chunkValue),
base::Value(encoded));
std::move(resume).Run();
}
......@@ -767,11 +766,13 @@ void DevToolsUIBindings::DispatchProtocolMessage(
for (size_t pos = 0; pos < message_sp.length(); pos += kMaxMessageChunkSize) {
base::Value message_value(message_sp.substr(pos, kMaxMessageChunkSize));
if (pos == 0) {
CallClientMethod("DevToolsAPI", "dispatchMessageChunk", message_value,
CallClientMethod("DevToolsAPI", "dispatchMessageChunk",
std::move(message_value),
base::Value(static_cast<int>(message_sp.length())));
} else {
CallClientMethod("DevToolsAPI", "dispatchMessageChunk", message_value);
CallClientMethod("DevToolsAPI", "dispatchMessageChunk",
std::move(message_value));
}
}
}
......@@ -787,7 +788,7 @@ void DevToolsUIBindings::SendMessageAck(int request_id,
const base::Value* arg) {
if (arg) {
CallClientMethod("DevToolsAPI", "embedderMessageAck",
base::Value(request_id), *arg);
base::Value(request_id), arg->Clone());
} else {
CallClientMethod("DevToolsAPI", "embedderMessageAck",
base::Value(request_id));
......@@ -981,7 +982,8 @@ void DevToolsUIBindings::RequestFileSystems() {
base::ListValue file_systems_value;
for (auto const& file_system : file_helper_->GetFileSystems())
file_systems_value.Append(CreateFileSystemValue(file_system));
CallClientMethod("DevToolsAPI", "fileSystemsLoaded", file_systems_value);
CallClientMethod("DevToolsAPI", "fileSystemsLoaded",
std::move(file_systems_value));
}
void DevToolsUIBindings::AddFileSystem(const std::string& type) {
......@@ -1146,11 +1148,13 @@ void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() {
->FindPreference(prefs::kDevToolsTCPDiscoveryConfig)
->GetValue()
->CreateDeepCopy());
CallClientMethod("DevToolsAPI", "devicesDiscoveryConfigChanged", config);
CallClientMethod("DevToolsAPI", "devicesDiscoveryConfigChanged",
std::move(config));
}
void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) {
CallClientMethod("DevToolsAPI", "devicesPortForwardingStatusChanged", status);
void DevToolsUIBindings::SendPortForwardingStatus(base::Value status) {
CallClientMethod("DevToolsAPI", "devicesPortForwardingStatusChanged",
std::move(status));
}
void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) {
......@@ -1363,7 +1367,7 @@ void DevToolsUIBindings::DeviceCountChanged(int count) {
void DevToolsUIBindings::DevicesUpdated(
const std::string& source,
const base::ListValue& targets) {
CallClientMethod("DevToolsAPI", "devicesUpdated", targets);
CallClientMethod("DevToolsAPI", "devicesUpdated", targets.Clone());
}
void DevToolsUIBindings::FileSavedAs(const std::string& url,
......@@ -1425,7 +1429,7 @@ void DevToolsUIBindings::FilePathsChanged(
--budget;
}
CallClientMethod("DevToolsAPI", "fileSystemFilesChangedAddedRemoved",
changed, added, removed);
std::move(changed), std::move(added), std::move(removed));
}
}
......@@ -1464,7 +1468,7 @@ void DevToolsUIBindings::SearchCompleted(
for (auto const& file_path : file_paths)
file_paths_value.AppendString(file_path);
CallClientMethod("DevToolsAPI", "searchCompleted", base::Value(request_id),
base::Value(file_system_path), file_paths_value);
base::Value(file_system_path), std::move(file_paths_value));
}
void DevToolsUIBindings::ShowDevToolsInfoBar(
......@@ -1513,7 +1517,7 @@ void DevToolsUIBindings::AddDevToolsExtensionsToClient() {
results.Append(std::move(extension_info));
}
CallClientMethod("DevToolsAPI", "addExtensions", results);
CallClientMethod("DevToolsAPI", "addExtensions", std::move(results));
}
void DevToolsUIBindings::RegisterExtensionsAPI(const std::string& origin,
......@@ -1552,30 +1556,26 @@ bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) {
void DevToolsUIBindings::CallClientMethod(
const std::string& object_name,
const std::string& method_name,
const base::Value& arg1,
const base::Value& arg2,
const base::Value& arg3,
base::Value arg1,
base::Value arg2,
base::Value arg3,
base::OnceCallback<void(base::Value)> completion_callback) {
// If we're not exposing bindings, we shouldn't call functions either.
if (!frontend_host_)
return;
std::string javascript = object_name + "." + method_name + "(";
base::Value arguments(base::Value::Type::LIST);
if (!arg1.is_none()) {
std::string json;
base::JSONWriter::Write(arg1, &json);
javascript.append(json);
arguments.Append(std::move(arg1));
if (!arg2.is_none()) {
base::JSONWriter::Write(arg2, &json);
javascript.append(", ").append(json);
arguments.Append(std::move(arg2));
if (!arg3.is_none()) {
base::JSONWriter::Write(arg3, &json);
javascript.append(", ").append(json);
arguments.Append(std::move(arg3));
}
}
}
javascript.append(");");
web_contents_->GetMainFrame()->ExecuteJavaScript(
base::UTF8ToUTF16(javascript), std::move(completion_callback));
web_contents_->GetMainFrame()->ExecuteJavaScriptMethod(
base::ASCIIToUTF16(object_name), base::ASCIIToUTF16(method_name),
std::move(arguments), std::move(completion_callback));
}
void DevToolsUIBindings::ReadyToCommitNavigation(
......
......@@ -83,9 +83,9 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate,
void CallClientMethod(
const std::string& object_name,
const std::string& method_name,
const base::Value& arg1 = {},
const base::Value& arg2 = {},
const base::Value& arg3 = {},
base::Value arg1 = {},
base::Value arg2 = {},
base::Value arg3 = {},
base::OnceCallback<void(base::Value)> completion_callback =
base::OnceCallback<void(base::Value)>());
void AttachTo(const scoped_refptr<content::DevToolsAgentHost>& agent_host);
......@@ -195,7 +195,7 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate,
int result,
const std::string& message);
void DevicesDiscoveryConfigUpdated();
void SendPortForwardingStatus(const base::Value& status);
void SendPortForwardingStatus(base::Value status);
// DevToolsFileHelper::Delegate overrides.
void FileSystemAdded(
......
......@@ -320,7 +320,7 @@ bool DevToolsEventForwarder::ForwardEvent(
event_data.SetIntKey("keyCode", key_code);
event_data.SetIntKey("modifiers", modifiers);
devtools_window_->bindings_->CallClientMethod(
"DevToolsAPI", "keyEventUnhandled", event_data);
"DevToolsAPI", "keyEventUnhandled", std::move(event_data));
return true;
}
......@@ -1469,7 +1469,8 @@ void DevToolsWindow::ColorPickedInEyeDropper(int r, int g, int b, int a) {
color.SetInteger("g", g);
color.SetInteger("b", b);
color.SetInteger("a", a);
bindings_->CallClientMethod("DevToolsAPI", "eyeDropperPickedColor", color);
bindings_->CallClientMethod("DevToolsAPI", "eyeDropperPickedColor",
std::move(color));
}
void DevToolsWindow::InspectedContentsClosing() {
......
......@@ -671,8 +671,9 @@ void InspectUI::PopulateAdditionalTargets(const base::Value& targets) {
web_ui()->CallJavascriptFunctionUnsafe("populateAdditionalTargets", targets);
}
void InspectUI::PopulatePortStatus(const base::Value& status) {
web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status);
void InspectUI::PopulatePortStatus(base::Value status) {
web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus",
std::move(status));
}
void InspectUI::ShowIncognitoWarning() {
......
......@@ -89,7 +89,7 @@ class InspectUI : public content::WebUIController,
void PopulateAdditionalTargets(const base::Value& targets);
void PopulatePortStatus(const base::Value& status);
void PopulatePortStatus(base::Value status);
void ShowIncognitoWarning();
......
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