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

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

Issue 7599003: Add IPC for DNS host address resolution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/p2p/socket_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/socket_dispatcher.h" 5 #include "content/renderer/p2p/socket_dispatcher.h"
6 6
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "content/common/p2p_messages.h" 8 #include "content/common/p2p_messages.h"
9 #include "content/renderer/p2p/host_address_request.h"
10 #include "content/renderer/p2p/socket_client.h"
9 11
10 P2PSocketDispatcher::P2PSocketDispatcher(RenderView* render_view) 12 P2PSocketDispatcher::P2PSocketDispatcher(RenderView* render_view)
11 : RenderViewObserver(render_view), 13 : RenderViewObserver(render_view),
12 message_loop_(base::MessageLoopProxy::CreateForCurrentThread()), 14 message_loop_(base::MessageLoopProxy::CreateForCurrentThread()),
13 network_notifications_started_(false), 15 network_notifications_started_(false),
14 network_list_observers_( 16 network_list_observers_(
15 new ObserverListThreadSafe<NetworkListObserver>()) { 17 new ObserverListThreadSafe<NetworkListObserver>()) {
16 } 18 }
17 19
18 P2PSocketDispatcher::~P2PSocketDispatcher() { 20 P2PSocketDispatcher::~P2PSocketDispatcher() {
(...skipping 16 matching lines...) Expand all
35 NetworkListObserver* network_list_observer) { 37 NetworkListObserver* network_list_observer) {
36 network_list_observers_->RemoveObserver(network_list_observer); 38 network_list_observers_->RemoveObserver(network_list_observer);
37 network_notifications_started_ = false; 39 network_notifications_started_ = false;
38 Send(new P2PHostMsg_StopNetworkNotifications(routing_id())); 40 Send(new P2PHostMsg_StopNetworkNotifications(routing_id()));
39 } 41 }
40 42
41 bool P2PSocketDispatcher::OnMessageReceived(const IPC::Message& message) { 43 bool P2PSocketDispatcher::OnMessageReceived(const IPC::Message& message) {
42 bool handled = true; 44 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP(P2PSocketDispatcher, message) 45 IPC_BEGIN_MESSAGE_MAP(P2PSocketDispatcher, message)
44 IPC_MESSAGE_HANDLER(P2PMsg_NetworkListChanged, OnNetworkListChanged) 46 IPC_MESSAGE_HANDLER(P2PMsg_NetworkListChanged, OnNetworkListChanged)
47 IPC_MESSAGE_HANDLER(P2PMsg_GetHostAddressResult, OnGetHostAddressResult)
45 IPC_MESSAGE_HANDLER(P2PMsg_OnSocketCreated, OnSocketCreated) 48 IPC_MESSAGE_HANDLER(P2PMsg_OnSocketCreated, OnSocketCreated)
46 IPC_MESSAGE_HANDLER(P2PMsg_OnIncomingTcpConnection, OnIncomingTcpConnection) 49 IPC_MESSAGE_HANDLER(P2PMsg_OnIncomingTcpConnection, OnIncomingTcpConnection)
47 IPC_MESSAGE_HANDLER(P2PMsg_OnError, OnError) 50 IPC_MESSAGE_HANDLER(P2PMsg_OnError, OnError)
48 IPC_MESSAGE_HANDLER(P2PMsg_OnDataReceived, OnDataReceived) 51 IPC_MESSAGE_HANDLER(P2PMsg_OnDataReceived, OnDataReceived)
49 IPC_MESSAGE_UNHANDLED(handled = false) 52 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP() 53 IPC_END_MESSAGE_MAP()
51 return handled; 54 return handled;
52 } 55 }
53 56
57 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() {
58 return message_loop_;
59 }
60
54 int P2PSocketDispatcher::RegisterClient(P2PSocketClient* client) { 61 int P2PSocketDispatcher::RegisterClient(P2PSocketClient* client) {
55 return clients_.Add(client); 62 return clients_.Add(client);
56 } 63 }
57 64
58 void P2PSocketDispatcher::UnregisterClient(int id) { 65 void P2PSocketDispatcher::UnregisterClient(int id) {
59 clients_.Remove(id); 66 clients_.Remove(id);
60 } 67 }
61 68
62 void P2PSocketDispatcher::SendP2PMessage(IPC::Message* msg) { 69 void P2PSocketDispatcher::SendP2PMessage(IPC::Message* msg) {
63 msg->set_routing_id(routing_id()); 70 msg->set_routing_id(routing_id());
64 Send(msg); 71 Send(msg);
65 } 72 }
66 73
67 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() { 74 int P2PSocketDispatcher::RegisterHostAddressRequest(
68 return message_loop_; 75 P2PHostAddressRequest* request) {
76 return host_address_requests_.Add(request);
77 }
78
79 void P2PSocketDispatcher::UnregisterHostAddressRequest(int id) {
80 host_address_requests_.Remove(id);
69 } 81 }
70 82
71 void P2PSocketDispatcher::OnNetworkListChanged( 83 void P2PSocketDispatcher::OnNetworkListChanged(
72 const net::NetworkInterfaceList& networks) { 84 const net::NetworkInterfaceList& networks) {
73 network_list_observers_->Notify(&NetworkListObserver::OnNetworkListChanged, 85 network_list_observers_->Notify(&NetworkListObserver::OnNetworkListChanged,
74 networks); 86 networks);
75 } 87 }
76 88
89 void P2PSocketDispatcher::OnGetHostAddressResult(
90 int32 request_id,
91 const net::IPAddressNumber& address) {
92 P2PHostAddressRequest* request = host_address_requests_.Lookup(request_id);
93 if (!request) {
94 VLOG(1) << "Received P2P message for socket that doesn't exist.";
95 return;
96 }
97
98 request->OnResponse(address);
99 }
100
77 void P2PSocketDispatcher::OnSocketCreated( 101 void P2PSocketDispatcher::OnSocketCreated(
78 int socket_id, const net::IPEndPoint& address) { 102 int socket_id, const net::IPEndPoint& address) {
79 P2PSocketClient* client = GetClient(socket_id); 103 P2PSocketClient* client = GetClient(socket_id);
80 if (client) { 104 if (client) {
81 client->OnSocketCreated(address); 105 client->OnSocketCreated(address);
82 } 106 }
83 } 107 }
84 108
85 void P2PSocketDispatcher::OnIncomingTcpConnection( 109 void P2PSocketDispatcher::OnIncomingTcpConnection(
86 int socket_id, const net::IPEndPoint& address) { 110 int socket_id, const net::IPEndPoint& address) {
(...skipping 24 matching lines...) Expand all
111 if (client == NULL) { 135 if (client == NULL) {
112 // This may happen if the socket was closed, but the browser side 136 // This may happen if the socket was closed, but the browser side
113 // hasn't processed the close message by the time it sends the 137 // hasn't processed the close message by the time it sends the
114 // message to the renderer. 138 // message to the renderer.
115 VLOG(1) << "Received P2P message for socket that doesn't exist."; 139 VLOG(1) << "Received P2P message for socket that doesn't exist.";
116 return NULL; 140 return NULL;
117 } 141 }
118 142
119 return client; 143 return client;
120 } 144 }
OLDNEW
« no previous file with comments | « content/renderer/p2p/socket_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698