Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/devtools_client_impl.h" | 5 #include "chrome/test/chromedriver/devtools_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 DevToolsClientImpl::DevToolsClientImpl( | 37 DevToolsClientImpl::DevToolsClientImpl( |
| 38 const SyncWebSocketFactory& factory, | 38 const SyncWebSocketFactory& factory, |
| 39 const std::string& url, | 39 const std::string& url, |
| 40 const ParserFunc& parser_func) | 40 const ParserFunc& parser_func) |
| 41 : socket_(factory.Run().Pass()), | 41 : socket_(factory.Run().Pass()), |
| 42 url_(url), | 42 url_(url), |
| 43 parser_func_(parser_func), | 43 parser_func_(parser_func), |
| 44 connected_(false), | 44 connected_(false), |
| 45 next_id_(1) {} | 45 next_id_(1) {} |
| 46 | 46 |
| 47 DevToolsClientImpl::~DevToolsClientImpl() {} | 47 DevToolsClientImpl::~DevToolsClientImpl() { |
| 48 for (ResponseMap::iterator iter = cmd_response_map_.begin(); | |
| 49 iter != cmd_response_map_.end(); ++iter) { | |
| 50 LOG(WARNING) << "Finished with no response for command " << iter->first; | |
| 51 delete iter->second; | |
| 52 } | |
| 53 } | |
| 48 | 54 |
| 49 Status DevToolsClientImpl::SendCommand( | 55 Status DevToolsClientImpl::SendCommand( |
| 50 const std::string& method, | 56 const std::string& method, |
| 51 const base::DictionaryValue& params) { | 57 const base::DictionaryValue& params) { |
| 52 scoped_ptr<base::DictionaryValue> result; | 58 scoped_ptr<base::DictionaryValue> result; |
| 53 return SendCommandInternal(method, params, &result); | 59 return SendCommandInternal(method, params, &result); |
| 54 } | 60 } |
| 55 | 61 |
| 56 Status DevToolsClientImpl::SendCommandAndGetResult( | 62 Status DevToolsClientImpl::SendCommandAndGetResult( |
| 57 const std::string& method, | 63 const std::string& method, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 119 |
| 114 return ReceiveCommandResponse(command_id, result); | 120 return ReceiveCommandResponse(command_id, result); |
| 115 } | 121 } |
| 116 | 122 |
| 117 Status DevToolsClientImpl::ReceiveCommandResponse( | 123 Status DevToolsClientImpl::ReceiveCommandResponse( |
| 118 int command_id, | 124 int command_id, |
| 119 scoped_ptr<base::DictionaryValue>* result) { | 125 scoped_ptr<base::DictionaryValue>* result) { |
| 120 internal::InspectorMessageType type; | 126 internal::InspectorMessageType type; |
| 121 internal::InspectorEvent event; | 127 internal::InspectorEvent event; |
| 122 internal::InspectorCommandResponse response; | 128 internal::InspectorCommandResponse response; |
| 123 while (true) { | 129 cmd_response_map_[command_id] = NULL; |
|
kkania
2013/01/30 22:36:05
what's this about?
craigdh
2013/01/30 23:05:21
The overarching idea is that we support overlappin
| |
| 130 while (cmd_response_map_[command_id] == NULL) { | |
| 124 Status status = ReceiveNextMessage(command_id, &type, &event, &response); | 131 Status status = ReceiveNextMessage(command_id, &type, &event, &response); |
| 125 if (status.IsError()) { | 132 if (status.IsError()) { |
| 126 return status; | 133 return status; |
| 127 } else if (type == internal::kCommandResponseMessageType) { | 134 } else if (type == internal::kCommandResponseMessageType) { |
| 128 if (response.id != command_id) { | 135 if (cmd_response_map_.count(response.id) == 0) { |
| 129 return Status(kUnknownError, | 136 return Status(kUnknownError, |
| 130 "received response for unknown command ID"); | 137 "received response for unknown command ID"); |
| 138 } else if (response.result) { | |
| 139 cmd_response_map_[response.id] = response.result.release(); | |
| 140 } else { | |
| 141 return Status(kUnknownError, "inspector error: " + response.error); | |
| 131 } | 142 } |
| 132 if (response.result) { | |
| 133 result->reset(response.result.release()); | |
| 134 return Status(kOk); | |
| 135 } | |
| 136 return Status(kUnknownError, "inspector error: " + response.error); | |
| 137 } | 143 } |
| 138 } | 144 } |
| 145 result->reset(cmd_response_map_[command_id]); | |
| 146 cmd_response_map_.erase(command_id); | |
| 147 return Status(kOk); | |
| 139 } | 148 } |
| 140 | 149 |
| 141 Status DevToolsClientImpl::ReceiveNextMessage( | 150 Status DevToolsClientImpl::ReceiveNextMessage( |
| 142 int expected_id, | 151 int expected_id, |
| 143 internal::InspectorMessageType* type, | 152 internal::InspectorMessageType* type, |
| 144 internal::InspectorEvent* event, | 153 internal::InspectorEvent* event, |
| 145 internal::InspectorCommandResponse* response) { | 154 internal::InspectorCommandResponse* response) { |
| 146 std::string message; | 155 std::string message; |
| 147 if (!socket_->ReceiveNextMessage(&message)) { | 156 if (!socket_->ReceiveNextMessage(&message)) { |
| 148 connected_ = false; | 157 connected_ = false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 if (unscoped_result) | 219 if (unscoped_result) |
| 211 command_response->result.reset(unscoped_result->DeepCopy()); | 220 command_response->result.reset(unscoped_result->DeepCopy()); |
| 212 else | 221 else |
| 213 base::JSONWriter::Write(unscoped_error, &command_response->error); | 222 base::JSONWriter::Write(unscoped_error, &command_response->error); |
| 214 return true; | 223 return true; |
| 215 } | 224 } |
| 216 return false; | 225 return false; |
| 217 } | 226 } |
| 218 | 227 |
| 219 } // namespace internal | 228 } // namespace internal |
| OLD | NEW |