Commit 2d4dc3ad authored by loislo@chromium.org's avatar loislo@chromium.org

DevTools: eliminate 1k lines of generated code in InspectorBackendDispatcher.cpp

and reduce binary footprint by 5% ~25kb of 587k (clang x64 release)

BUG=382569
R=yurys@chromium.org

Review URL: https://codereview.chromium.org/325833002

git-svn-id: svn://svn.chromium.org/blink/trunk@175877 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8873e7e1
......@@ -1902,7 +1902,7 @@ class Generator:
Generator.method_name_enum_list.append(" %s," % cmd_enum_name)
Generator.method_handler_list.append(" &InspectorBackendDispatcherImpl::%s_%s," % (domain_name, json_command_name))
Generator.backend_method_declaration_list.append(" void %s_%s(long callId, JSONObject* requestMessageObject);" % (domain_name, json_command_name))
Generator.backend_method_declaration_list.append(" void %s_%s(long callId, JSONObject* requestMessageObject, JSONArray* protocolErrors);" % (domain_name, json_command_name))
backend_agent_interface_list = [] if "redirect" in json_command else Generator.backend_agent_interface_list
......@@ -1914,10 +1914,11 @@ class Generator:
method_in_code = ""
method_out_code = ""
result_object_declaration = ""
agent_call_param_list = []
send_response_call_params_list = ["error"]
request_message_param = ""
normal_response_cook_text = ""
error_response_cook_text = ""
error_type_binding = None
if "error" in json_command:
json_error = json_command["error"]
......@@ -1927,17 +1928,7 @@ class Generator:
agent_call_param_list.append(", %serrorData" % error_type_model.get_command_return_pass_model().get_output_argument_prefix())
backend_agent_interface_list.append(", %s errorData" % error_annotated_type)
method_in_code += " %s errorData;\n" % error_type_model.get_command_return_pass_model().get_return_var_type()
setter_argument = error_type_model.get_command_return_pass_model().get_output_to_raw_expression() % "errorData"
if error_type_binding.get_setter_value_expression_pattern():
setter_argument = error_type_binding.get_setter_value_expression_pattern() % setter_argument
error_assigment_value = error_type_binding.reduce_to_raw_type().get_constructor_pattern() % setter_argument
cook = " resultErrorData = %s;\n" % error_assigment_value
error_condition_pattern = error_type_model.get_command_return_pass_model().get_set_return_condition()
cook = (" if (%s)\n " % (error_condition_pattern % "errorData")) + cook
error_response_cook_text = " if (error.length()) {\n" + cook + " }\n"
send_response_call_params_list.append("errorData")
if "parameters" in json_command:
json_params = json_command["parameters"]
......@@ -1962,13 +1953,13 @@ class Generator:
if optional:
code = (" bool %s_valueFound = false;\n"
" %s in_%s = get%s(paramsContainerPtr, \"%s\", &%s_valueFound, protocolErrorsPtr);\n" %
" %s in_%s = get%s(paramsContainerPtr, \"%s\", &%s_valueFound, protocolErrors);\n" %
(json_param_name, non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_param_name, json_param_name))
param = ", %s_valueFound ? &in_%s : 0" % (json_param_name, json_param_name)
# FIXME: pass optional refptr-values as PassRefPtr
formal_param_type_pattern = "const %s*"
else:
code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0, protocolErrorsPtr);\n" %
code = (" %s in_%s = get%s(paramsContainerPtr, \"%s\", 0, protocolErrors);\n" %
(non_optional_type_model.get_command_return_pass_model().get_return_var_type(), json_param_name, getter_name, json_param_name))
param = ", in_%s" % json_param_name
# FIXME: pass not-optional refptr-values as NonNullPassRefPtr
......@@ -2015,19 +2006,19 @@ class Generator:
parameter=annotated_type + " errorData",
argument=assigment_value))
ad_hoc_type_output.append(callback_output)
method_out_code += " RefPtr<" + agent_interface_name + "::" + callback_name + "> callback = adoptRef(new " + agent_interface_name + "::" + callback_name + "(this, callId));\n"
agent_call_param_list.append(", callback")
normal_response_cook_text += " if (!error.length()) \n"
normal_response_cook_text += " return;\n"
normal_response_cook_text += " callback->disable();\n"
normal_response_cook_text += " if (!error.length()) \n"
normal_response_cook_text += " return;\n"
normal_response_cook_text += " callback->disable();\n"
backend_agent_interface_list.append(", PassRefPtr<%s> callback" % callback_name)
else:
if "returns" in json_command:
method_out_code += "\n"
result_object_declaration = "\n RefPtr<JSONObject> result = JSONObject::create();"
send_response_call_params_list.append("result")
response_cook_list = []
for json_return in json_command["returns"]:
......@@ -2052,12 +2043,12 @@ class Generator:
if return_type_binding.get_setter_value_expression_pattern():
setter_argument = return_type_binding.get_setter_value_expression_pattern() % setter_argument
cook = " result->set%s(\"%s\", %s);\n" % (setter_type, json_return_name,
cook = " result->set%s(\"%s\", %s);\n" % (setter_type, json_return_name,
setter_argument)
set_condition_pattern = type_model.get_command_return_pass_model().get_set_return_condition()
if set_condition_pattern:
cook = (" if (%s)\n " % (set_condition_pattern % var_name)) + cook
cook = (" if (%s)\n " % (set_condition_pattern % var_name)) + cook
annotated_type = type_model.get_command_return_pass_model().get_output_parameter_type()
param_name = var_name
......@@ -2073,7 +2064,7 @@ class Generator:
normal_response_cook_text += "".join(response_cook_list)
if len(normal_response_cook_text) != 0:
normal_response_cook_text = " if (!error.length()) {\n" + normal_response_cook_text + " }"
normal_response_cook_text = " if (!error.length()) {\n" + normal_response_cook_text + " }"
# Redirect to another agent's implementation.
agent_field = "m_" + agent_field_name
......@@ -2084,12 +2075,11 @@ class Generator:
Generator.backend_method_implementation_list.append(Templates.backend_method.substitute(None,
domainName=domain_name, methodName=json_command_name,
agentField=agent_field,
methodInCode=method_in_code,
methodOutCode=method_out_code,
methodCode="".join([method_in_code, method_out_code, result_object_declaration]),
agentCallParams="".join(agent_call_param_list),
requestMessageObject=request_message_param,
responseCook=normal_response_cook_text,
errorCook=error_response_cook_text,
sendResponseCallParams=", ".join(send_response_call_params_list),
commandNameIndex=cmd_enum_name))
declaration_command_name = "%s.%s\\0" % (domain_name, json_command_name)
Generator.backend_method_name_declaration_list.append(" \"%s\"" % declaration_command_name)
......
......@@ -44,23 +44,19 @@ ${frontendDomainMethodDeclarations}
""")
backend_method = (
"""void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, JSONObject*$requestMessageObject)
"""void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, JSONObject*$requestMessageObject, JSONArray* protocolErrors)
{
RefPtr<JSONArray> protocolErrors = JSONArray::create();
if (!$agentField)
protocolErrors->pushString("${domainName} handler is not available.");
$methodOutCode
$methodInCode
RefPtr<JSONObject> result = JSONObject::create();
RefPtr<JSONValue> resultErrorData;
ErrorString error;
if (!protocolErrors->length()) {
$agentField->$methodName(&error$agentCallParams);
$errorCook${responseCook}
$methodCode
if (protocolErrors->length()) {
reportProtocolError(&callId, InvalidParams, String::format(InvalidParamsFormatString, commandName($commandNameIndex)), protocolErrors);
return;
}
sendResponse(callId, result, commandName($commandNameIndex), protocolErrors, error, resultErrorData);
ErrorString error;
$agentField->$methodName(&error$agentCallParams);
$responseCook
sendResponse(callId, $sendResponseCallParams);
}
""")
......@@ -247,7 +243,7 @@ $constructorInit
virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const;
using InspectorBackendDispatcher::reportProtocolError;
void sendResponse(long callId, PassRefPtr<JSONObject> result, const ErrorString&invocationError, PassRefPtr<JSONValue> errorData);
void sendResponse(long callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result);
bool isActive() { return m_inspectorFrontendChannel; }
$setters
......@@ -267,10 +263,19 @@ $fieldDeclarations
static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors);
static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors);
void sendResponse(long callId, PassRefPtr<JSONObject> result, const char* commandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, PassRefPtr<JSONValue> errorData);
void sendResponse(long callId, ErrorString invocationError, PassRefPtr<JSONObject> result)
{
sendResponse(callId, invocationError, RefPtr<JSONValue>(), result);
}
void sendResponse(long callId, ErrorString invocationError)
{
sendResponse(callId, invocationError, RefPtr<JSONValue>(), JSONObject::create());
}
static const char InvalidParamsFormatString[];
};
const char InspectorBackendDispatcherImpl::InvalidParamsFormatString[] = "Some arguments of method '%s' can't be processed";
$methods
PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(InspectorFrontendChannel* inspectorFrontendChannel)
......@@ -282,7 +287,7 @@ PassRefPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::create(Inspec
void InspectorBackendDispatcherImpl::dispatch(const String& message)
{
RefPtr<InspectorBackendDispatcher> protect = this;
typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSONObject* messageObject);
typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSONObject* messageObject, JSONArray* protocolErrors);
typedef HashMap<String, CallHandler> DispatchMap;
DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );
long callId = 0;
......@@ -336,20 +341,11 @@ $messageHandlers
return;
}
((*this).*it->value)(callId, messageObject.get());
}
void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONObject> result, const char* commandName, PassRefPtr<JSONArray> protocolErrors, ErrorString invocationError, PassRefPtr<JSONValue> errorData)
{
if (protocolErrors->length()) {
String errorMessage = String::format("Some arguments of method '%s' can't be processed", commandName);
reportProtocolError(&callId, InvalidParams, errorMessage, protocolErrors);
return;
}
sendResponse(callId, result, invocationError, errorData);
RefPtr<JSONArray> protocolErrors = JSONArray::create();
((*this).*it->value)(callId, messageObject.get(), protocolErrors.get());
}
void InspectorBackendDispatcherImpl::sendResponse(long callId, PassRefPtr<JSONObject> result, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData)
void InspectorBackendDispatcherImpl::sendResponse(long callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result)
{
if (invocationError.length()) {
reportProtocolError(&callId, ServerError, invocationError, errorData);
......@@ -508,7 +504,7 @@ void InspectorBackendDispatcher::CallbackBase::sendIfActive(PassRefPtr<JSONObjec
{
if (m_alreadySent)
return;
m_backendImpl->sendResponse(m_id, partialMessage, invocationError, errorData);
m_backendImpl->sendResponse(m_id, invocationError, errorData, partialMessage);
m_alreadySent = true;
}
......@@ -901,7 +897,6 @@ $validatorCode
param_container_access_code = """
RefPtr<JSONObject> paramsContainer = requestMessageObject->getObject("params");
JSONObject* paramsContainerPtr = paramsContainer.get();
JSONArray* protocolErrorsPtr = protocolErrors.get();
"""
class_binding_builder_part_1 = (
......
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