| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef IPC_IPC_CHANNEL_PROXY_H__ | 5 #ifndef IPC_IPC_CHANNEL_PROXY_H__ |
| 6 #define IPC_IPC_CHANNEL_PROXY_H__ | 6 #define IPC_IPC_CHANNEL_PROXY_H__ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 virtual bool Send(Message* message); | 110 virtual bool Send(Message* message); |
| 111 | 111 |
| 112 // Used to intercept messages as they are received on the background thread. | 112 // Used to intercept messages as they are received on the background thread. |
| 113 // | 113 // |
| 114 // Ordinarily, messages sent to the ChannelProxy are routed to the matching | 114 // Ordinarily, messages sent to the ChannelProxy are routed to the matching |
| 115 // listener on the worker thread. This API allows code to intercept messages | 115 // listener on the worker thread. This API allows code to intercept messages |
| 116 // before they are sent to the worker thread. | 116 // before they are sent to the worker thread. |
| 117 void AddFilter(MessageFilter* filter); | 117 void AddFilter(MessageFilter* filter); |
| 118 void RemoveFilter(MessageFilter* filter); | 118 void RemoveFilter(MessageFilter* filter); |
| 119 | 119 |
| 120 // Called to clear the pointer to the IPC message loop when it's going away. |
| 121 void ClearIPCMessageLoop(); |
| 122 |
| 120 #if defined(OS_POSIX) | 123 #if defined(OS_POSIX) |
| 121 // Calls through to the underlying channel's methods. | 124 // Calls through to the underlying channel's methods. |
| 122 // TODO(playmobil): For now this is only implemented in the case of | 125 // TODO(playmobil): For now this is only implemented in the case of |
| 123 // create_pipe_now = true, we need to figure this out for the latter case. | 126 // create_pipe_now = true, we need to figure this out for the latter case. |
| 124 int GetClientFileDescriptor() const; | 127 int GetClientFileDescriptor() const; |
| 125 #endif // defined(OS_POSIX) | 128 #endif // defined(OS_POSIX) |
| 126 | 129 |
| 127 protected: | 130 protected: |
| 128 class Context; | 131 class Context; |
| 129 // A subclass uses this constructor if it needs to add more information | 132 // A subclass uses this constructor if it needs to add more information |
| 130 // to the internal state. If create_pipe_now is true, the pipe is created | 133 // to the internal state. If create_pipe_now is true, the pipe is created |
| 131 // immediately. Otherwise it's created on the IO thread. | 134 // immediately. Otherwise it's created on the IO thread. |
| 132 ChannelProxy(const std::string& channel_id, Channel::Mode mode, | 135 ChannelProxy(const std::string& channel_id, Channel::Mode mode, |
| 133 MessageLoop* ipc_thread_loop, Context* context, | 136 MessageLoop* ipc_thread_loop, Context* context, |
| 134 bool create_pipe_now); | 137 bool create_pipe_now); |
| 135 | 138 |
| 136 // Used internally to hold state that is referenced on the IPC thread. | 139 // Used internally to hold state that is referenced on the IPC thread. |
| 137 class Context : public base::RefCountedThreadSafe<Context>, | 140 class Context : public base::RefCountedThreadSafe<Context>, |
| 138 public Channel::Listener { | 141 public Channel::Listener { |
| 139 public: | 142 public: |
| 140 Context(Channel::Listener* listener, MessageFilter* filter, | 143 Context(Channel::Listener* listener, MessageFilter* filter, |
| 141 MessageLoop* ipc_thread); | 144 MessageLoop* ipc_thread); |
| 142 virtual ~Context() { } | 145 virtual ~Context() { } |
| 146 void ClearIPCMessageLoop() { ipc_message_loop_ = NULL; } |
| 143 MessageLoop* ipc_message_loop() const { return ipc_message_loop_; } | 147 MessageLoop* ipc_message_loop() const { return ipc_message_loop_; } |
| 144 const std::string& channel_id() const { return channel_id_; } | 148 const std::string& channel_id() const { return channel_id_; } |
| 145 | 149 |
| 146 // Dispatches a message on the listener thread. | 150 // Dispatches a message on the listener thread. |
| 147 void OnDispatchMessage(const Message& message); | 151 void OnDispatchMessage(const Message& message); |
| 148 | 152 |
| 149 protected: | 153 protected: |
| 150 // IPC::Channel::Listener methods: | 154 // IPC::Channel::Listener methods: |
| 151 virtual void OnMessageReceived(const Message& message); | 155 virtual void OnMessageReceived(const Message& message); |
| 152 virtual void OnChannelConnected(int32 peer_pid); | 156 virtual void OnChannelConnected(int32 peer_pid); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 204 |
| 201 // By maintaining this indirection (ref-counted) to our internal state, we | 205 // By maintaining this indirection (ref-counted) to our internal state, we |
| 202 // can safely be destroyed while the background thread continues to do stuff | 206 // can safely be destroyed while the background thread continues to do stuff |
| 203 // that involves this data. | 207 // that involves this data. |
| 204 scoped_refptr<Context> context_; | 208 scoped_refptr<Context> context_; |
| 205 }; | 209 }; |
| 206 | 210 |
| 207 } // namespace IPC | 211 } // namespace IPC |
| 208 | 212 |
| 209 #endif // IPC_IPC_CHANNEL_PROXY_H__ | 213 #endif // IPC_IPC_CHANNEL_PROXY_H__ |
| OLD | NEW |