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

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

Issue 10917167: Refactor the P2PSocketDispatcher to be created on the RenderThread instead of the RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary destruction callback. Removed remaining routing_id. Created 8 years, 3 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
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 // P2PSocketDispatcher is a per-renderer object that dispatchers all 5 // P2PSocketDispatcher is a per-renderer object that dispatchers all
6 // P2P messages received from the browser and relays all P2P messages 6 // P2P messages received from the browser and relays all P2P messages
7 // sent to the browser. P2PSocketClient instances register themselves 7 // sent to the browser. P2PSocketClient instances register themselves
8 // with the dispatcher using RegisterClient() and UnregisterClient(). 8 // with the dispatcher using RegisterClient() and UnregisterClient().
9 // 9 //
10 // Relationship of classes. 10 // Relationship of classes.
11 // 11 //
12 // P2PSocketHost P2PSocketClient 12 // P2PSocketHost P2PSocketClient
13 // ^ ^ 13 // ^ ^
14 // | | 14 // | |
15 // v IPC v 15 // v IPC v
16 // P2PSocketDispatcherHost <---------> P2PSocketDispatcher 16 // P2PSocketDispatcherHost <---------> P2PSocketDispatcher
17 // 17 //
18 // P2PSocketDispatcher receives and dispatches messages on the 18 // P2PSocketDispatcher receives and dispatches messages on the
19 // renderer thread. 19 // IO thread.
20 20
21 #ifndef CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ 21 #ifndef CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_
22 #define CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ 22 #define CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_
23 23
24 #include <vector> 24 #include <vector>
25 25
26 #include "base/callback_forward.h" 26 #include "base/callback_forward.h"
27 #include "base/compiler_specific.h" 27 #include "base/compiler_specific.h"
28 #include "base/id_map.h" 28 #include "base/id_map.h"
29 #include "base/observer_list_threadsafe.h" 29 #include "base/observer_list_threadsafe.h"
30 #include "base/synchronization/lock.h" 30 #include "base/synchronization/lock.h"
31 #include "content/common/content_export.h" 31 #include "content/common/content_export.h"
32 #include "content/common/p2p_sockets.h" 32 #include "content/common/p2p_sockets.h"
33 #include "content/public/renderer/render_view_observer.h" 33 #include "ipc/ipc_channel_proxy.h"
34 #include "net/base/net_util.h" 34 #include "net/base/net_util.h"
35 35
36 class RenderViewImpl; 36 class RenderViewImpl;
37 37
38 namespace base { 38 namespace base {
39 class MessageLoopProxy; 39 class MessageLoopProxy;
40 } // namespace base 40 } // namespace base
41 41
42 namespace net { 42 namespace net {
43 class IPEndPoint; 43 class IPEndPoint;
44 } // namespace net 44 } // namespace net
45 45
46 namespace webkit_glue { 46 namespace webkit_glue {
47 class NetworkListObserver; 47 class NetworkListObserver;
48 } // webkit_glue 48 } // webkit_glue
49 49
50 namespace content { 50 namespace content {
51 51
52 class P2PHostAddressRequest; 52 class P2PHostAddressRequest;
53 class P2PSocketClient; 53 class P2PSocketClient;
54 54
55 // Callback interface that allows the implementor to be notified before a 55 class CONTENT_EXPORT P2PSocketDispatcher
56 // P2PSocketDispatcher is destroyed. 56 : public IPC::ChannelProxy::MessageFilter{
tommi (sloooow) - chröme 2012/09/11 12:09:09 space before {
perkj_chrome 2012/09/11 14:27:30 Done.
57 // P2PSocketDispatcher requires that all NetworkListObservers are
58 // unregistered when SocketDispatcherGone is called.
59 class P2PSocketDispatcherDestructionObserver {
60 public: 57 public:
61 virtual void OnSocketDispatcherDestroyed() = 0; 58 P2PSocketDispatcher(base::MessageLoopProxy* ipc_message_loop);
62
63 protected:
64 virtual ~P2PSocketDispatcherDestructionObserver() {}
65 };
66
67 class CONTENT_EXPORT P2PSocketDispatcher : public content::RenderViewObserver {
68 public:
69 explicit P2PSocketDispatcher(RenderViewImpl* render_view);
70 virtual ~P2PSocketDispatcher();
71 59
72 // Add a new network list observer. Each observer is called 60 // Add a new network list observer. Each observer is called
73 // immidiately after it is registered and then later whenever 61 // immidiately after it is registered and then later whenever
74 // network configuration changes. Can be called on any thread. The 62 // network configuration changes. Can be called on any thread. The
75 // observer is always called on the thread it was added. 63 // observer is always called on the thread it was added.
76 void AddNetworkListObserver( 64 void AddNetworkListObserver(
77 webkit_glue::NetworkListObserver* network_list_observer); 65 webkit_glue::NetworkListObserver* network_list_observer);
78 66
79 // Removes network list observer. Must be called on the thread on 67 // Removes network list observer. Must be called on the thread on
80 // which the observer was added. 68 // which the observer was added.
81 void RemoveNetworkListObserver( 69 void RemoveNetworkListObserver(
82 webkit_glue::NetworkListObserver* network_list_observer); 70 webkit_glue::NetworkListObserver* network_list_observer);
83 71
84 void AddDestructionObserver(P2PSocketDispatcherDestructionObserver* observer); 72 protected:
85 void RemoveDestructionObserver( 73 virtual ~P2PSocketDispatcher();
86 P2PSocketDispatcherDestructionObserver* observer);
87
88 // RenderViewObserver overrides.
89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
90 74
91 private: 75 private:
92 friend class P2PHostAddressRequest; 76 friend class P2PHostAddressRequest;
93 friend class P2PSocketClient; 77 friend class P2PSocketClient;
94 class AsyncMessageSender; 78 class AsyncMessageSender;
95 79
80 // Send a message asynchronously. Must be called on the IO thread.
81 virtual void Send(IPC::Message* message);
82
83 // IPC::ChannelProxy::MessageFilter override. Called on IO thread.
84 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
85 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
86 virtual void OnFilterRemoved() OVERRIDE;
87 virtual void OnChannelClosing() OVERRIDE;
88
89 // Returns the IO message loop.
96 base::MessageLoopProxy* message_loop(); 90 base::MessageLoopProxy* message_loop();
97 91
98 // Called by P2PSocketClient. 92 // Called by P2PSocketClient.
99 int RegisterClient(P2PSocketClient* client); 93 int RegisterClient(P2PSocketClient* client);
100 void UnregisterClient(int id); 94 void UnregisterClient(int id);
101 void SendP2PMessage(IPC::Message* msg); 95 void SendP2PMessage(IPC::Message* msg);
102 96
103 // Called by DnsRequest. 97 // Called by DnsRequest.
104 int RegisterHostAddressRequest(P2PHostAddressRequest* request); 98 int RegisterHostAddressRequest(P2PHostAddressRequest* request);
105 void UnregisterHostAddressRequest(int id); 99 void UnregisterHostAddressRequest(int id);
(...skipping 14 matching lines...) Expand all
120 IDMap<P2PSocketClient> clients_; 114 IDMap<P2PSocketClient> clients_;
121 115
122 IDMap<P2PHostAddressRequest> host_address_requests_; 116 IDMap<P2PHostAddressRequest> host_address_requests_;
123 117
124 bool network_notifications_started_; 118 bool network_notifications_started_;
125 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> > 119 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> >
126 network_list_observers_; 120 network_list_observers_;
127 121
128 scoped_refptr<AsyncMessageSender> async_message_sender_; 122 scoped_refptr<AsyncMessageSender> async_message_sender_;
129 123
130 ObserverList<P2PSocketDispatcherDestructionObserver> destruction_observer_; 124 IPC::Channel* channel_;
131 125
132 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); 126 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher);
133 }; 127 };
134 128
135 } // namespace content 129 } // namespace content
136 130
137 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ 131 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698