Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: chrome/test/chromedriver/devtools_client_impl.cc

Issue 12230021: [chromedriver] Send all OnConnected before any OnEvent when connected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 10 #include "base/logging.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 Status DevToolsClientImpl::SendCommandInternal( 121 Status DevToolsClientImpl::SendCommandInternal(
122 const std::string& method, 122 const std::string& method,
123 const base::DictionaryValue& params, 123 const base::DictionaryValue& params,
124 scoped_ptr<base::DictionaryValue>* result) { 124 scoped_ptr<base::DictionaryValue>* result) {
125 if (!connected_) { 125 if (!connected_) {
126 if (!socket_->Connect(url_)) 126 if (!socket_->Connect(url_))
127 return Status(kDisconnected, "unable to connect to renderer"); 127 return Status(kDisconnected, "unable to connect to renderer");
128 connected_ = true; 128 connected_ = true;
129 for (std::list<DevToolsEventListener*>::iterator iter = listeners_.begin(); 129
130 iter != listeners_.end(); ++iter) { 130 // OnConnected notification will be sent out in method ReceiveNextMessage.
131 Status status = (*iter)->OnConnected(); 131 listeners_for_on_connected_ = listeners_;
craigdh 2013/02/13 19:19:39 Instead of copying the list, why not just have a b
kkania 2013/02/13 20:57:34 then you'd also have to keep track of what listene
craigdh 2013/02/13 21:45:45 Ah, I see the issue. Agreed.
chrisgao (Use stgao instead) 2013/02/14 03:49:45 I also think list copy is easier and simpler.
132 if (status.IsError())
133 return status;
134 }
135 } 132 }
136 133
137 int command_id = next_id_++; 134 int command_id = next_id_++;
138 base::DictionaryValue command; 135 base::DictionaryValue command;
139 command.SetInteger("id", command_id); 136 command.SetInteger("id", command_id);
140 command.SetString("method", method); 137 command.SetString("method", method);
141 command.Set("params", params.DeepCopy()); 138 command.Set("params", params.DeepCopy());
142 std::string message; 139 std::string message;
143 base::JSONWriter::Write(&command, &message); 140 base::JSONWriter::Write(&command, &message);
144 if (!socket_->Send(message)) { 141 if (!socket_->Send(message)) {
(...skipping 18 matching lines...) Expand all
163 result->reset(cmd_response_map_[command_id]); 160 result->reset(cmd_response_map_[command_id]);
164 cmd_response_map_.erase(command_id); 161 cmd_response_map_.erase(command_id);
165 return Status(kOk); 162 return Status(kOk);
166 } 163 }
167 164
168 Status DevToolsClientImpl::ReceiveNextMessage( 165 Status DevToolsClientImpl::ReceiveNextMessage(
169 int expected_id, 166 int expected_id,
170 internal::InspectorMessageType* type, 167 internal::InspectorMessageType* type,
171 internal::InspectorEvent* event, 168 internal::InspectorEvent* event,
172 internal::InspectorCommandResponse* response) { 169 internal::InspectorCommandResponse* response) {
170 while (!listeners_for_on_connected_.empty()) {
171 DevToolsEventListener* listener = listeners_for_on_connected_.front();
172 listeners_for_on_connected_.pop_front();
173 Status status = listener->OnConnected();
174 if (status.IsError())
175 return status;
176 }
177 // The message might be received already when processing other commands sent
178 // from DevToolsEventListener::OnConnected.
179 if (cmd_response_map_.find(expected_id) != cmd_response_map_.end()
craigdh 2013/02/13 19:19:39 Consider making this a private function, something
chrisgao (Use stgao instead) 2013/02/14 03:49:45 Good idea.
180 && cmd_response_map_[expected_id])
181 return Status(kOk);
182
173 std::string message; 183 std::string message;
174 if (!socket_->ReceiveNextMessage(&message)) { 184 if (!socket_->ReceiveNextMessage(&message)) {
175 connected_ = false; 185 connected_ = false;
176 return Status(kDisconnected, 186 return Status(kDisconnected,
177 "unable to receive message from renderer"); 187 "unable to receive message from renderer");
178 } 188 }
179 if (!parser_func_.Run(message, expected_id, type, event, response)) 189 if (!parser_func_.Run(message, expected_id, type, event, response))
180 return Status(kUnknownError, "bad inspector message: " + message); 190 return Status(kUnknownError, "bad inspector message: " + message);
181 if (*type == internal::kEventMessageType) 191 if (*type == internal::kEventMessageType)
182 return NotifyEventListeners(event->method, *event->params); 192 return NotifyEventListeners(event->method, *event->params);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (unscoped_result) 257 if (unscoped_result)
248 command_response->result.reset(unscoped_result->DeepCopy()); 258 command_response->result.reset(unscoped_result->DeepCopy());
249 else 259 else
250 base::JSONWriter::Write(unscoped_error, &command_response->error); 260 base::JSONWriter::Write(unscoped_error, &command_response->error);
251 return true; 261 return true;
252 } 262 }
253 return false; 263 return false;
254 } 264 }
255 265
256 } // namespace internal 266 } // namespace internal
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/devtools_client_impl.h ('k') | chrome/test/chromedriver/dom_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698