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

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: mmenke@ review Created 4 years, 8 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 request_handlers_.push_back(callback); 289 request_handlers_.push_back(callback);
290 } 290 }
291 291
292 void EmbeddedTestServer::RegisterDefaultHandler( 292 void EmbeddedTestServer::RegisterDefaultHandler(
293 const HandleRequestCallback& callback) { 293 const HandleRequestCallback& callback) {
294 // TODO(svaldez): Add check to prevent RegisterHandler from being called 294 // TODO(svaldez): Add check to prevent RegisterHandler from being called
295 // after the server has started. https://crbug.com/546060 295 // after the server has started. https://crbug.com/546060
296 default_request_handlers_.push_back(callback); 296 default_request_handlers_.push_back(callback);
297 } 297 }
298 298
299 bool EmbeddedTestServer::FlushAllSocketsAndConnectionsOnUIThread() {
300 bool r = PostTaskToIOThreadAndWait(
301 base::Bind(&EmbeddedTestServer::FlushAllSocketsAndConnections,
302 base::Unretained(this)));
303 return r;
304 }
305
306 void EmbeddedTestServer::FlushAllSocketsAndConnections() {
307 STLDeleteContainerPairSecondPointers(connections_.begin(),
308 connections_.end());
309 connections_.clear();
310 }
311
299 std::unique_ptr<StreamSocket> EmbeddedTestServer::DoSSLUpgrade( 312 std::unique_ptr<StreamSocket> EmbeddedTestServer::DoSSLUpgrade(
300 std::unique_ptr<StreamSocket> connection) { 313 std::unique_ptr<StreamSocket> connection) {
301 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); 314 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread());
302 315
303 return context_->CreateSSLServerSocket(std::move(connection)); 316 return context_->CreateSSLServerSocket(std::move(connection));
304 } 317 }
305 318
306 void EmbeddedTestServer::DoAcceptLoop() { 319 void EmbeddedTestServer::DoAcceptLoop() {
307 int rv = OK; 320 int rv = OK;
308 while (rv == OK) { 321 while (rv == OK) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 382
370 void EmbeddedTestServer::OnReadCompleted(HttpConnection* connection, int rv) { 383 void EmbeddedTestServer::OnReadCompleted(HttpConnection* connection, int rv) {
371 DCHECK_NE(ERR_IO_PENDING, rv); 384 DCHECK_NE(ERR_IO_PENDING, rv);
372 if (HandleReadResult(connection, rv)) 385 if (HandleReadResult(connection, rv))
373 ReadData(connection); 386 ReadData(connection);
374 } 387 }
375 388
376 bool EmbeddedTestServer::HandleReadResult(HttpConnection* connection, int rv) { 389 bool EmbeddedTestServer::HandleReadResult(HttpConnection* connection, int rv) {
377 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); 390 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread());
378 if (connection_listener_) 391 if (connection_listener_)
379 connection_listener_->ReadFromSocket(*connection->socket_); 392 connection_listener_->ReadFromSocket(*connection->socket_, rv);
380 if (rv <= 0) { 393 if (rv <= 0) {
381 DidClose(connection); 394 DidClose(connection);
382 return false; 395 return false;
383 } 396 }
384 397
385 // Once a single complete request has been received, there is no further need 398 // 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. 399 // for the connection and it may be destroyed once the response has been sent.
387 if (connection->ConsumeData(rv)) 400 if (connection->ConsumeData(rv))
388 return false; 401 return false;
389 402
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 run_loop.QuitClosure())) { 443 run_loop.QuitClosure())) {
431 return false; 444 return false;
432 } 445 }
433 run_loop.Run(); 446 run_loop.Run();
434 447
435 return true; 448 return true;
436 } 449 }
437 450
438 } // namespace test_server 451 } // namespace test_server
439 } // namespace net 452 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698