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

Side by Side Diff: blimp/net/tcp_engine_transport.cc

Issue 2236093002: Decouple Blimp transport output from BlimpConnections using MessagePort. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@statistics-singleton
Patch Set: wez feedback Created 4 years, 4 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
« no previous file with comments | « blimp/net/tcp_engine_transport.h ('k') | blimp/net/tcp_transport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "blimp/net/tcp_engine_transport.h" 5 #include "blimp/net/tcp_engine_transport.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
16 #include "blimp/net/stream_socket_connection.h" 15 #include "blimp/net/message_port.h"
17 #include "net/socket/stream_socket.h" 16 #include "net/socket/stream_socket.h"
18 #include "net/socket/tcp_server_socket.h" 17 #include "net/socket/tcp_server_socket.h"
19 18
20 namespace blimp { 19 namespace blimp {
21 20
22 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, 21 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address,
23 net::NetLog* net_log) 22 net::NetLog* net_log)
24 : address_(address), net_log_(net_log) {} 23 : address_(address), net_log_(net_log) {}
25 24
26 TCPEngineTransport::~TCPEngineTransport() {} 25 TCPEngineTransport::~TCPEngineTransport() {}
(...skipping 17 matching lines...) Expand all
44 net::CompletionCallback accept_callback = base::Bind( 43 net::CompletionCallback accept_callback = base::Bind(
45 &TCPEngineTransport::OnTCPConnectAccepted, base::Unretained(this)); 44 &TCPEngineTransport::OnTCPConnectAccepted, base::Unretained(this));
46 45
47 int result = server_socket_->Accept(&accepted_socket_, accept_callback); 46 int result = server_socket_->Accept(&accepted_socket_, accept_callback);
48 if (result == net::ERR_IO_PENDING) { 47 if (result == net::ERR_IO_PENDING) {
49 connect_callback_ = callback; 48 connect_callback_ = callback;
50 return; 49 return;
51 } 50 }
52 51
53 if (result != net::OK) { 52 if (result != net::OK) {
54 // TODO(haibinlu): investigate when we can keep using this server socket.
55 server_socket_.reset(); 53 server_socket_.reset();
56 } 54 }
57 55
58 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 56 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
59 base::Bind(callback, result)); 57 base::Bind(callback, result));
60 } 58 }
61 59
62 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { 60 std::unique_ptr<MessagePort> TCPEngineTransport::TakeMessagePort() {
63 DCHECK(connect_callback_.is_null()); 61 DCHECK(connect_callback_.is_null());
64 DCHECK(accepted_socket_); 62 DCHECK(accepted_socket_);
65 return base::MakeUnique<StreamSocketConnection>(std::move(accepted_socket_)); 63 return MessagePort::CreateForStreamSocketWithCompression(
64 std::move(accepted_socket_));
66 } 65 }
67 66
68 const char* TCPEngineTransport::GetName() const { 67 const char* TCPEngineTransport::GetName() const {
69 return "TCP"; 68 return "TCP";
70 } 69 }
71 70
72 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { 71 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const {
73 DCHECK(server_socket_); 72 DCHECK(server_socket_);
74 return server_socket_->GetLocalAddress(address); 73 return server_socket_->GetLocalAddress(address);
75 } 74 }
76 75
77 void TCPEngineTransport::OnTCPConnectAccepted(int result) { 76 void TCPEngineTransport::OnTCPConnectAccepted(int result) {
78 DCHECK_NE(net::ERR_IO_PENDING, result); 77 DCHECK_NE(net::ERR_IO_PENDING, result);
79 DCHECK(accepted_socket_); 78 DCHECK(accepted_socket_);
80 if (result != net::OK) { 79 if (result != net::OK) {
81 accepted_socket_.reset(); 80 accepted_socket_.reset();
82 } 81 }
83 base::ResetAndReturn(&connect_callback_).Run(result); 82 base::ResetAndReturn(&connect_callback_).Run(result);
84 } 83 }
85 84
86 } // namespace blimp 85 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/tcp_engine_transport.h ('k') | blimp/net/tcp_transport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698