Chromium Code Reviews| Index: chrome/test/chromedriver/devtools_client_impl.cc |
| diff --git a/chrome/test/chromedriver/devtools_client_impl.cc b/chrome/test/chromedriver/devtools_client_impl.cc |
| index a5cb79fda45f39d8649708e64ac842ee132cb330..336c2d169d8f4176e8956c09c764dedb2ace0111 100644 |
| --- a/chrome/test/chromedriver/devtools_client_impl.cc |
| +++ b/chrome/test/chromedriver/devtools_client_impl.cc |
| @@ -48,9 +48,11 @@ InspectorCommandResponse::~InspectorCommandResponse() {} |
| DevToolsClientImpl::DevToolsClientImpl( |
| const SyncWebSocketFactory& factory, |
| - const std::string& url) |
| + const std::string& url, |
| + const FrontendCloserFunc& frontend_closer_func) |
| : socket_(factory.Run().Pass()), |
| url_(url), |
| + frontend_closer_func_(frontend_closer_func), |
| parser_func_(base::Bind(&internal::ParseInspectorMessage)), |
| connected_(false), |
| next_id_(1) {} |
| @@ -58,9 +60,11 @@ DevToolsClientImpl::DevToolsClientImpl( |
| DevToolsClientImpl::DevToolsClientImpl( |
| const SyncWebSocketFactory& factory, |
| const std::string& url, |
| + const FrontendCloserFunc& frontend_closer_func, |
| const ParserFunc& parser_func) |
| : socket_(factory.Run().Pass()), |
| url_(url), |
| + frontend_closer_func_(frontend_closer_func), |
| parser_func_(parser_func), |
| connected_(false), |
| next_id_(1) {} |
| @@ -118,10 +122,11 @@ Status DevToolsClientImpl::HandleEventsUntil( |
| return Status(kOk); |
| } |
| -Status DevToolsClientImpl::SendCommandInternal( |
| +Status DevToolsClientImpl::SendCommandToDevTools( |
|
kkania
2013/02/22 01:35:24
the naming of SendCommandToDevTools and SendComman
chrisgao (Use stgao instead)
2013/02/27 19:29:44
Change SendCommandInternal to SendCommandWithRetry
|
| const std::string& method, |
| const base::DictionaryValue& params, |
| - scoped_ptr<base::DictionaryValue>* result) { |
| + scoped_ptr<base::DictionaryValue>* result, |
| + int* command_id) { |
| if (!connected_) { |
| if (!socket_->Connect(url_)) |
| return Status(kDisconnected, "unable to connect to renderer"); |
| @@ -131,17 +136,35 @@ Status DevToolsClientImpl::SendCommandInternal( |
| listeners_for_on_connected_ = listeners_; |
| } |
| - int command_id = next_id_++; |
| + int command_id_tmp = next_id_++; |
| base::DictionaryValue command; |
| - command.SetInteger("id", command_id); |
| + command.SetInteger("id", command_id_tmp); |
| command.SetString("method", method); |
| command.Set("params", params.DeepCopy()); |
| std::string message; |
| base::JSONWriter::Write(&command, &message); |
| if (!socket_->Send(message)) { |
| - connected_ = false; |
| - return Status(kDisconnected, "unable to send message to renderer"); |
| + connected_ = false; |
| + return Status(kDisconnected, "unable to send message to renderer"); |
| } |
| + *command_id = command_id_tmp; |
| + return Status(kOk); |
| +} |
| + |
| +Status DevToolsClientImpl::SendCommandInternal( |
| + const std::string& method, |
| + const base::DictionaryValue& params, |
| + scoped_ptr<base::DictionaryValue>* result) { |
| + int command_id = -1; |
| + Status status = SendCommandToDevTools(method, params, result, &command_id); |
|
kkania
2013/02/22 01:35:24
have you tried this manually? can you try sending
chrisgao (Use stgao instead)
2013/02/27 19:29:44
If DevTools frontend is opened during re-connectio
|
| + if (status.code() == kDisconnected) { |
| + // Try to close devtools frontend UI and then reconnect. |
| + status = frontend_closer_func_.Run(); |
| + if (status.IsOk()) |
| + status = SendCommandToDevTools(method, params, result, &command_id); |
| + } |
| + if (status.IsError()) |
| + return Status(kDisconnected, "failed to reconnect to DevTools"); |
|
kkania
2013/02/22 01:35:24
this error message may not be accurate, right? thi
chrisgao (Use stgao instead)
2013/02/27 19:29:44
Oh, yes. Updated message and including the old sta
|
| return ReceiveCommandResponse(command_id, result); |
| } |