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

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: Fixed nits 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
« no previous file with comments | « content/renderer/p2p/socket_client.cc ('k') | content/renderer/p2p/socket_dispatcher.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 (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 {
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;
95 78
79 // Send a message asynchronously.
80 virtual void Send(IPC::Message* message);
81
82 // IPC::ChannelProxy::MessageFilter override. Called on IO thread.
83 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
84 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
85 virtual void OnFilterRemoved() OVERRIDE;
86 virtual void OnChannelClosing() OVERRIDE;
87
88 // Returns the IO message loop.
96 base::MessageLoopProxy* message_loop(); 89 base::MessageLoopProxy* message_loop();
97 90
98 // Called by P2PSocketClient. 91 // Called by P2PSocketClient.
99 int RegisterClient(P2PSocketClient* client); 92 int RegisterClient(P2PSocketClient* client);
100 void UnregisterClient(int id); 93 void UnregisterClient(int id);
101 void SendP2PMessage(IPC::Message* msg); 94 void SendP2PMessage(IPC::Message* msg);
102 95
103 // Called by DnsRequest. 96 // Called by DnsRequest.
104 int RegisterHostAddressRequest(P2PHostAddressRequest* request); 97 int RegisterHostAddressRequest(P2PHostAddressRequest* request);
105 void UnregisterHostAddressRequest(int id); 98 void UnregisterHostAddressRequest(int id);
(...skipping 12 matching lines...) Expand all
118 111
119 scoped_refptr<base::MessageLoopProxy> message_loop_; 112 scoped_refptr<base::MessageLoopProxy> message_loop_;
120 IDMap<P2PSocketClient> clients_; 113 IDMap<P2PSocketClient> clients_;
121 114
122 IDMap<P2PHostAddressRequest> host_address_requests_; 115 IDMap<P2PHostAddressRequest> host_address_requests_;
123 116
124 bool network_notifications_started_; 117 bool network_notifications_started_;
125 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> > 118 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> >
126 network_list_observers_; 119 network_list_observers_;
127 120
128 scoped_refptr<AsyncMessageSender> async_message_sender_; 121 IPC::Channel* channel_;
129
130 ObserverList<P2PSocketDispatcherDestructionObserver> destruction_observer_;
131 122
132 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); 123 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher);
133 }; 124 };
134 125
135 } // namespace content 126 } // namespace content
136 127
137 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ 128 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_
OLDNEW
« no previous file with comments | « content/renderer/p2p/socket_client.cc ('k') | content/renderer/p2p/socket_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698