Chromium Code Reviews| Index: content/browser/devtools/devtools_session.cc |
| diff --git a/content/browser/devtools/devtools_session.cc b/content/browser/devtools/devtools_session.cc |
| index 8783f1723c2ff77a19c1524491e513fe2315a34f..cfd8f18ef2bfd14dfc56de3db7a1a5d537c14b18 100644 |
| --- a/content/browser/devtools/devtools_session.cc |
| +++ b/content/browser/devtools/devtools_session.cc |
| @@ -13,16 +13,15 @@ |
| namespace content { |
| -DevToolsSession::DevToolsSession( |
| - DevToolsAgentHostImpl* agent_host, |
| - DevToolsAgentHostClient* client, |
| - int session_id) |
| +DevToolsSession::DevToolsSession(DevToolsAgentHostImpl* agent_host, |
| + DevToolsAgentHostClient* client, |
| + int session_id) |
| : agent_host_(agent_host), |
| client_(client), |
| session_id_(session_id), |
| host_(nullptr), |
| - dispatcher_(new protocol::UberDispatcher(this)) { |
| -} |
| + dispatcher_(new protocol::UberDispatcher(this)), |
| + weak_factory_(this) {} |
| DevToolsSession::~DevToolsSession() { |
| dispatcher_.reset(); |
| @@ -48,6 +47,13 @@ void DevToolsSession::SetFallThroughForNotFound(bool value) { |
| dispatcher_->setFallThroughForNotFound(value); |
| } |
| +void DevToolsSession::sendResponse( |
| + std::unique_ptr<base::DictionaryValue> response) { |
| + std::string json; |
| + base::JSONWriter::Write(*response.get(), &json); |
| + agent_host_->SendMessageToClient(session_id_, json); |
| +} |
| + |
| protocol::Response::Status DevToolsSession::Dispatch( |
| const std::string& message, |
| int* call_id, |
| @@ -61,11 +67,15 @@ protocol::Response::Status DevToolsSession::Dispatch( |
| agent_host_, |
| static_cast<base::DictionaryValue*>(value.get()))); |
|
pfeldman
2017/02/21 19:10:24
nit: extract variable.
|
| if (response) { |
| - std::string json; |
| - base::JSONWriter::Write(*response.get(), &json); |
| - agent_host_->SendMessageToClient(session_id_, json); |
| + sendResponse(std::move(response)); |
| return protocol::Response::kSuccess; |
| } |
| + if (delegate->HandleAsyncCommand( |
| + agent_host_, static_cast<base::DictionaryValue*>(value.get()), |
| + base::Bind(&DevToolsSession::sendResponse, |
| + weak_factory_.GetWeakPtr()))) { |
| + return protocol::Response::kAsync; |
| + } |
| } |
| return dispatcher_->dispatch(protocol::toProtocolValue(value.get(), 1000), |