Chromium Code Reviews| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 return false; | 119 return false; |
| 120 auto it = pending_messages_.find(id); | 120 auto it = pending_messages_.find(id); |
| 121 if (it == pending_messages_.end()) { | 121 if (it == pending_messages_.end()) { |
| 122 NOTREACHED() << "Unexpected reply"; | 122 NOTREACHED() << "Unexpected reply"; |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 Callback callback = std::move(it->second); | 125 Callback callback = std::move(it->second); |
| 126 pending_messages_.erase(it); | 126 pending_messages_.erase(it); |
| 127 if (!callback.callback_with_result.is_null()) { | 127 if (!callback.callback_with_result.is_null()) { |
| 128 const base::DictionaryValue* result_dict; | 128 const base::DictionaryValue* result_dict; |
| 129 if (!message_dict.GetDictionary("result", &result_dict)) { | 129 if (message_dict.GetDictionary("result", &result_dict)) { |
| 130 NOTREACHED() << "Badly formed reply result"; | 130 callback.callback_with_result.Run(*result_dict); |
| 131 } else if (message_dict.GetDictionary("error", &result_dict)) { | |
| 132 DLOG(ERROR) << "Error in method call result: " << *result_dict; | |
| 133 callback.callback_with_result.Run(*base::Value::CreateNullValue()); | |
|
altimin
2016/11/29 17:43:27
I don't really like creating a temporary unique po
tmarek
2016/11/30 09:01:08
Done.
| |
| 134 } else { | |
| 135 NOTREACHED() << "Replay has neither result nor error"; | |
|
altimin
2016/11/29 17:43:27
nit: reply?
tmarek
2016/11/30 09:01:08
Done.
| |
| 131 return false; | 136 return false; |
| 132 } | 137 } |
| 133 callback.callback_with_result.Run(*result_dict); | |
| 134 } else if (!callback.callback.is_null()) { | 138 } else if (!callback.callback.is_null()) { |
| 135 callback.callback.Run(); | 139 callback.callback.Run(); |
| 136 } | 140 } |
| 137 return true; | 141 return true; |
| 138 } | 142 } |
| 139 | 143 |
| 140 bool HeadlessDevToolsClientImpl::DispatchEvent( | 144 bool HeadlessDevToolsClientImpl::DispatchEvent( |
| 141 std::unique_ptr<base::Value> owning_message, | 145 std::unique_ptr<base::Value> owning_message, |
| 142 const base::DictionaryValue& message_dict) { | 146 const base::DictionaryValue& message_dict) { |
| 143 std::string method; | 147 std::string method; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 HeadlessDevToolsClientImpl::Callback::Callback( | 383 HeadlessDevToolsClientImpl::Callback::Callback( |
| 380 base::Callback<void(const base::Value&)> callback) | 384 base::Callback<void(const base::Value&)> callback) |
| 381 : callback_with_result(callback) {} | 385 : callback_with_result(callback) {} |
| 382 | 386 |
| 383 HeadlessDevToolsClientImpl::Callback::~Callback() {} | 387 HeadlessDevToolsClientImpl::Callback::~Callback() {} |
| 384 | 388 |
| 385 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: | 389 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: |
| 386 operator=(Callback&& other) = default; | 390 operator=(Callback&& other) = default; |
| 387 | 391 |
| 388 } // namespace headless | 392 } // namespace headless |
| OLD | NEW |