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

Side by Side Diff: content/renderer/p2p/ipc_socket_factory.cc

Issue 45183002: Expose the p2p client in content/public (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missed a file Created 7 years, 1 month 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 "content/renderer/p2p/ipc_socket_factory.h" 5 #include "content/renderer/p2p/ipc_socket_factory.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 talk_base::DiffServCodePoint dscp) OVERRIDE; 55 talk_base::DiffServCodePoint dscp) OVERRIDE;
56 virtual int Close() OVERRIDE; 56 virtual int Close() OVERRIDE;
57 virtual State GetState() const OVERRIDE; 57 virtual State GetState() const OVERRIDE;
58 virtual int GetOption(talk_base::Socket::Option opt, int* value) OVERRIDE; 58 virtual int GetOption(talk_base::Socket::Option opt, int* value) OVERRIDE;
59 virtual int SetOption(talk_base::Socket::Option opt, int value) OVERRIDE; 59 virtual int SetOption(talk_base::Socket::Option opt, int value) OVERRIDE;
60 virtual int GetError() const OVERRIDE; 60 virtual int GetError() const OVERRIDE;
61 virtual void SetError(int error) OVERRIDE; 61 virtual void SetError(int error) OVERRIDE;
62 62
63 // P2PSocketClient::Delegate implementation. 63 // P2PSocketClient::Delegate implementation.
64 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; 64 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE;
65 virtual void OnIncomingTcpConnection(const net::IPEndPoint& address, 65 virtual void OnIncomingTcpConnection(
66 P2PSocketClient* client) OVERRIDE; 66 const net::IPEndPoint& address,
67 P2PSocketClientInterface* client) OVERRIDE;
67 virtual void OnSendComplete() OVERRIDE; 68 virtual void OnSendComplete() OVERRIDE;
68 virtual void OnError() OVERRIDE; 69 virtual void OnError() OVERRIDE;
69 virtual void OnDataReceived(const net::IPEndPoint& address, 70 virtual void OnDataReceived(const net::IPEndPoint& address,
70 const std::vector<char>& data) OVERRIDE; 71 const std::vector<char>& data) OVERRIDE;
71 72
72 private: 73 private:
73 enum InternalState { 74 enum InternalState {
74 IS_UNINITIALIZED, 75 IS_UNINITIALIZED,
75 IS_OPENING, 76 IS_OPENING,
76 IS_OPEN, 77 IS_OPEN,
77 IS_CLOSED, 78 IS_CLOSED,
78 IS_ERROR, 79 IS_ERROR,
79 }; 80 };
80 81
81 // Update trace of send throttling internal state. This should be called 82 // Update trace of send throttling internal state. This should be called
82 // immediately after any changes to |send_bytes_available_| and/or 83 // immediately after any changes to |send_bytes_available_| and/or
83 // |in_flight_packet_sizes_|. 84 // |in_flight_packet_sizes_|.
84 void TraceSendThrottlingState() const; 85 void TraceSendThrottlingState() const;
85 86
86 void InitAcceptedTcp(P2PSocketClient* client, 87 void InitAcceptedTcp(P2PSocketClientInterface* client,
87 const talk_base::SocketAddress& local_address, 88 const talk_base::SocketAddress& local_address,
88 const talk_base::SocketAddress& remote_address); 89 const talk_base::SocketAddress& remote_address);
89 P2PSocketType type_; 90 P2PSocketType type_;
90 91
91 // Message loop on which this socket was created and being used. 92 // Message loop on which this socket was created and being used.
92 base::MessageLoop* message_loop_; 93 base::MessageLoop* message_loop_;
93 94
94 // Corresponding P2P socket client. 95 // Corresponding P2P socket client.
95 scoped_refptr<P2PSocketClient> client_; 96 scoped_refptr<P2PSocketClientInterface> client_;
96 97
97 // Local address is allocated by the browser process, and the 98 // Local address is allocated by the browser process, and the
98 // renderer side doesn't know the address until it receives OnOpen() 99 // renderer side doesn't know the address until it receives OnOpen()
99 // event from the browser. 100 // event from the browser.
100 talk_base::SocketAddress local_address_; 101 talk_base::SocketAddress local_address_;
101 102
102 // Remote address for client TCP connections. 103 // Remote address for client TCP connections.
103 talk_base::SocketAddress remote_address_; 104 talk_base::SocketAddress remote_address_;
104 105
105 // Current state of the object. 106 // Current state of the object.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 remote_address, &remote_endpoint)) { 173 remote_address, &remote_endpoint)) {
173 return false; 174 return false;
174 } 175 }
175 176
176 client_->Init(type, local_endpoint, remote_endpoint, this); 177 client_->Init(type, local_endpoint, remote_endpoint, this);
177 178
178 return true; 179 return true;
179 } 180 }
180 181
181 void IpcPacketSocket::InitAcceptedTcp( 182 void IpcPacketSocket::InitAcceptedTcp(
182 P2PSocketClient* client, 183 P2PSocketClientInterface* client,
183 const talk_base::SocketAddress& local_address, 184 const talk_base::SocketAddress& local_address,
184 const talk_base::SocketAddress& remote_address) { 185 const talk_base::SocketAddress& remote_address) {
185 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 186 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
186 DCHECK_EQ(state_, IS_UNINITIALIZED); 187 DCHECK_EQ(state_, IS_UNINITIALIZED);
187 188
188 client_ = client; 189 client_ = client;
189 local_address_ = local_address; 190 local_address_ = local_address;
190 remote_address_ = remote_address; 191 remote_address_ = remote_address;
191 state_ = IS_OPEN; 192 state_ = IS_OPEN;
192 TraceSendThrottlingState(); 193 TraceSendThrottlingState();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 state_ = IS_OPEN; 333 state_ = IS_OPEN;
333 TraceSendThrottlingState(); 334 TraceSendThrottlingState();
334 335
335 SignalAddressReady(this, local_address_); 336 SignalAddressReady(this, local_address_);
336 if (IsTcpClientSocket(type_)) 337 if (IsTcpClientSocket(type_))
337 SignalConnect(this); 338 SignalConnect(this);
338 } 339 }
339 340
340 void IpcPacketSocket::OnIncomingTcpConnection( 341 void IpcPacketSocket::OnIncomingTcpConnection(
341 const net::IPEndPoint& address, 342 const net::IPEndPoint& address,
342 P2PSocketClient* client) { 343 P2PSocketClientInterface* client) {
343 DCHECK_EQ(base::MessageLoop::current(), message_loop_); 344 DCHECK_EQ(base::MessageLoop::current(), message_loop_);
344 345
345 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); 346 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket());
346 347
347 talk_base::SocketAddress remote_address; 348 talk_base::SocketAddress remote_address;
348 if (!jingle_glue::IPEndPointToSocketAddress(address, &remote_address)) { 349 if (!jingle_glue::IPEndPointToSocketAddress(address, &remote_address)) {
349 // Always expect correct IPv4 address to be allocated. 350 // Always expect correct IPv4 address to be allocated.
350 NOTREACHED(); 351 NOTREACHED();
351 } 352 }
352 socket->InitAcceptedTcp(client, local_address_, remote_address); 353 socket->InitAcceptedTcp(client, local_address_, remote_address);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 450 }
450 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_); 451 P2PSocketClient* socket_client = new P2PSocketClient(socket_dispatcher_);
451 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket()); 452 scoped_ptr<IpcPacketSocket> socket(new IpcPacketSocket());
452 if (!socket->Init(type, socket_client, local_address, 453 if (!socket->Init(type, socket_client, local_address,
453 remote_address)) 454 remote_address))
454 return NULL; 455 return NULL;
455 return socket.release(); 456 return socket.release();
456 } 457 }
457 458
458 } // namespace content 459 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698