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

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

Powered by Google App Engine
This is Rietveld 408576698