| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "headless/lib/browser/headless_devtools_client_impl.h" | 5 #include "headless/lib/browser/headless_devtools_client_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bool HeadlessDevToolsClientImpl::DispatchMessageReply( | 95 bool HeadlessDevToolsClientImpl::DispatchMessageReply( |
| 96 const base::DictionaryValue& message_dict) { | 96 const base::DictionaryValue& message_dict) { |
| 97 int id = 0; | 97 int id = 0; |
| 98 if (!message_dict.GetInteger("id", &id)) | 98 if (!message_dict.GetInteger("id", &id)) |
| 99 return false; | 99 return false; |
| 100 auto it = pending_messages_.find(id); | 100 auto it = pending_messages_.find(id); |
| 101 if (it == pending_messages_.end()) { | 101 if (it == pending_messages_.end()) { |
| 102 NOTREACHED() << "Unexpected reply"; | 102 NOTREACHED() << "Unexpected reply"; |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 if (!it->second.callback_with_result.is_null()) { | 105 Callback callback = std::move(it->second); |
| 106 pending_messages_.erase(it); |
| 107 if (!callback.callback_with_result.is_null()) { |
| 106 const base::DictionaryValue* result_dict; | 108 const base::DictionaryValue* result_dict; |
| 107 if (!message_dict.GetDictionary("result", &result_dict)) { | 109 if (!message_dict.GetDictionary("result", &result_dict)) { |
| 108 NOTREACHED() << "Badly formed reply result"; | 110 NOTREACHED() << "Badly formed reply result"; |
| 109 return false; | 111 return false; |
| 110 } | 112 } |
| 111 it->second.callback_with_result.Run(*result_dict); | 113 callback.callback_with_result.Run(*result_dict); |
| 112 } else if (!it->second.callback.is_null()) { | 114 } else if (!callback.callback.is_null()) { |
| 113 it->second.callback.Run(); | 115 callback.callback.Run(); |
| 114 } | 116 } |
| 115 pending_messages_.erase(it); | |
| 116 return true; | 117 return true; |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool HeadlessDevToolsClientImpl::DispatchEvent( | 120 bool HeadlessDevToolsClientImpl::DispatchEvent( |
| 120 const base::DictionaryValue& message_dict) { | 121 const base::DictionaryValue& message_dict) { |
| 121 std::string method; | 122 std::string method; |
| 122 if (!message_dict.GetString("method", &method)) | 123 if (!message_dict.GetString("method", &method)) |
| 123 return false; | 124 return false; |
| 124 auto it = event_handlers_.find(method); | 125 auto it = event_handlers_.find(method); |
| 125 if (it == event_handlers_.end()) { | 126 if (it == event_handlers_.end()) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 HeadlessDevToolsClientImpl::Callback::Callback( | 337 HeadlessDevToolsClientImpl::Callback::Callback( |
| 337 base::Callback<void(const base::Value&)> callback) | 338 base::Callback<void(const base::Value&)> callback) |
| 338 : callback_with_result(callback) {} | 339 : callback_with_result(callback) {} |
| 339 | 340 |
| 340 HeadlessDevToolsClientImpl::Callback::~Callback() {} | 341 HeadlessDevToolsClientImpl::Callback::~Callback() {} |
| 341 | 342 |
| 342 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: | 343 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: |
| 343 operator=(Callback&& other) = default; | 344 operator=(Callback&& other) = default; |
| 344 | 345 |
| 345 } // namespace headless | 346 } // namespace headless |
| OLD | NEW |