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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server.cc

Issue 1881463003: Add a browsertest suite for net predictor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT that we get the right number of accepted connections after waiting Created 4 years, 7 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
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 "net/test/embedded_test_server/embedded_test_server.h" 5 #include "net/test/embedded_test_server/embedded_test_server.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 while (rv == OK) { 308 while (rv == OK) {
309 rv = listen_socket_->Accept( 309 rv = listen_socket_->Accept(
310 &accepted_socket_, base::Bind(&EmbeddedTestServer::OnAcceptCompleted, 310 &accepted_socket_, base::Bind(&EmbeddedTestServer::OnAcceptCompleted,
311 base::Unretained(this))); 311 base::Unretained(this)));
312 if (rv == ERR_IO_PENDING) 312 if (rv == ERR_IO_PENDING)
313 return; 313 return;
314 HandleAcceptResult(std::move(accepted_socket_)); 314 HandleAcceptResult(std::move(accepted_socket_));
315 } 315 }
316 } 316 }
317 317
318 bool EmbeddedTestServer::FlushAllSocketsAndConnectionsOnUIThread() {
319 return PostTaskToIOThreadAndWait(
320 base::Bind(&EmbeddedTestServer::FlushAllSocketsAndConnections,
321 base::Unretained(this)));
322 }
323
324 void EmbeddedTestServer::FlushAllSocketsAndConnections() {
325 STLDeleteContainerPairSecondPointers(connections_.begin(),
326 connections_.end());
327 connections_.clear();
328 }
329
318 void EmbeddedTestServer::OnAcceptCompleted(int rv) { 330 void EmbeddedTestServer::OnAcceptCompleted(int rv) {
319 DCHECK_NE(ERR_IO_PENDING, rv); 331 DCHECK_NE(ERR_IO_PENDING, rv);
320 HandleAcceptResult(std::move(accepted_socket_)); 332 HandleAcceptResult(std::move(accepted_socket_));
321 DoAcceptLoop(); 333 DoAcceptLoop();
322 } 334 }
323 335
324 void EmbeddedTestServer::OnHandshakeDone(HttpConnection* connection, int rv) { 336 void EmbeddedTestServer::OnHandshakeDone(HttpConnection* connection, int rv) {
325 if (connection->socket_->IsConnected()) 337 if (connection->socket_->IsConnected())
326 ReadData(connection); 338 ReadData(connection);
327 else 339 else
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 381
370 void EmbeddedTestServer::OnReadCompleted(HttpConnection* connection, int rv) { 382 void EmbeddedTestServer::OnReadCompleted(HttpConnection* connection, int rv) {
371 DCHECK_NE(ERR_IO_PENDING, rv); 383 DCHECK_NE(ERR_IO_PENDING, rv);
372 if (HandleReadResult(connection, rv)) 384 if (HandleReadResult(connection, rv))
373 ReadData(connection); 385 ReadData(connection);
374 } 386 }
375 387
376 bool EmbeddedTestServer::HandleReadResult(HttpConnection* connection, int rv) { 388 bool EmbeddedTestServer::HandleReadResult(HttpConnection* connection, int rv) {
377 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); 389 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread());
378 if (connection_listener_) 390 if (connection_listener_)
379 connection_listener_->ReadFromSocket(*connection->socket_); 391 connection_listener_->ReadFromSocket(*connection->socket_, rv);
380 if (rv <= 0) { 392 if (rv <= 0) {
381 DidClose(connection); 393 DidClose(connection);
382 return false; 394 return false;
383 } 395 }
384 396
385 // Once a single complete request has been received, there is no further need 397 // Once a single complete request has been received, there is no further need
386 // for the connection and it may be destroyed once the response has been sent. 398 // for the connection and it may be destroyed once the response has been sent.
387 if (connection->ConsumeData(rv)) 399 if (connection->ConsumeData(rv))
388 return false; 400 return false;
389 401
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 run_loop.QuitClosure())) { 442 run_loop.QuitClosure())) {
431 return false; 443 return false;
432 } 444 }
433 run_loop.Run(); 445 run_loop.Run();
434 446
435 return true; 447 return true;
436 } 448 }
437 449
438 } // namespace test_server 450 } // namespace test_server
439 } // namespace net 451 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698