| OLD | NEW |
| 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 #ifndef IPC_IPC_CHANNEL_H_ | 5 #ifndef IPC_IPC_CHANNEL_H_ |
| 6 #define IPC_IPC_CHANNEL_H_ | 6 #define IPC_IPC_CHANNEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #if defined(OS_POSIX) | 11 #if defined(OS_POSIX) |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "ipc/ipc_channel_handle.h" | 17 #include "ipc/ipc_channel_handle.h" |
| 18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 19 #include "ipc/ipc_sender.h" |
| 20 |
| 21 // TODO(brettw) remove this when the "typedef Sender" is removed below. |
| 22 #include "ipc/ipc_listener.h" |
| 19 | 23 |
| 20 namespace IPC { | 24 namespace IPC { |
| 21 | 25 |
| 26 class Listener; |
| 27 |
| 22 //------------------------------------------------------------------------------ | 28 //------------------------------------------------------------------------------ |
| 23 // See | 29 // See |
| 24 // http://www.chromium.org/developers/design-documents/inter-process-communicati
on | 30 // http://www.chromium.org/developers/design-documents/inter-process-communicati
on |
| 25 // for overview of IPC in Chromium. | 31 // for overview of IPC in Chromium. |
| 26 | 32 |
| 27 // Channels are implemented using named pipes on Windows, and | 33 // Channels are implemented using named pipes on Windows, and |
| 28 // socket pairs (or in some special cases unix domain sockets) on POSIX. | 34 // socket pairs (or in some special cases unix domain sockets) on POSIX. |
| 29 // On Windows we access pipes in various processes by name. | 35 // On Windows we access pipes in various processes by name. |
| 30 // On POSIX we pass file descriptors to child processes and assign names to them | 36 // On POSIX we pass file descriptors to child processes and assign names to them |
| 31 // in a lookup table. | 37 // in a lookup table. |
| 32 // In general on POSIX we do not use unix domain sockets due to security | 38 // In general on POSIX we do not use unix domain sockets due to security |
| 33 // concerns and the fact that they can leave garbage around the file system | 39 // concerns and the fact that they can leave garbage around the file system |
| 34 // (MacOS does not support abstract named unix domain sockets). | 40 // (MacOS does not support abstract named unix domain sockets). |
| 35 // You can use unix domain sockets if you like on POSIX by constructing the | 41 // You can use unix domain sockets if you like on POSIX by constructing the |
| 36 // the channel with the mode set to one of the NAMED modes. NAMED modes are | 42 // the channel with the mode set to one of the NAMED modes. NAMED modes are |
| 37 // currently used by automation and service processes. | 43 // currently used by automation and service processes. |
| 38 | 44 |
| 39 class IPC_EXPORT Channel : public Message::Sender { | 45 class IPC_EXPORT Channel : public Sender { |
| 40 // Security tests need access to the pipe handle. | 46 // Security tests need access to the pipe handle. |
| 41 friend class ChannelTest; | 47 friend class ChannelTest; |
| 42 | 48 |
| 43 public: | 49 public: |
| 44 // Implemented by consumers of a Channel to receive messages. | 50 // IPC::Listener used to be IPC::Channel::Listener which prevented forward |
| 45 class IPC_EXPORT Listener { | 51 // declarations. To keep existing code compiling, we provide this |
| 46 public: | 52 // backwards-compatible definition. New code should use IPC::Listener. |
| 47 virtual ~Listener() {} | 53 // TODO(brettw) converto users of this and delete. |
| 48 | 54 typedef IPC::Listener Listener; |
| 49 // Called when a message is received. Returns true iff the message was | |
| 50 // handled. | |
| 51 virtual bool OnMessageReceived(const Message& message) = 0; | |
| 52 | |
| 53 // Called when the channel is connected and we have received the internal | |
| 54 // Hello message from the peer. | |
| 55 virtual void OnChannelConnected(int32 peer_pid) {} | |
| 56 | |
| 57 // Called when an error is detected that causes the channel to close. | |
| 58 // This method is not called when a channel is closed normally. | |
| 59 virtual void OnChannelError() {} | |
| 60 | |
| 61 #if defined(OS_POSIX) | |
| 62 // Called on the server side when a channel that listens for connections | |
| 63 // denies an attempt to connect. | |
| 64 virtual void OnChannelDenied() {} | |
| 65 | |
| 66 // Called on the server side when a channel that listens for connections | |
| 67 // has an error that causes the listening channel to close. | |
| 68 virtual void OnChannelListenError() {} | |
| 69 #endif // OS_POSIX | |
| 70 }; | |
| 71 | 55 |
| 72 // Flags to test modes | 56 // Flags to test modes |
| 73 enum ModeFlags { | 57 enum ModeFlags { |
| 74 MODE_NO_FLAG = 0x0, | 58 MODE_NO_FLAG = 0x0, |
| 75 MODE_SERVER_FLAG = 0x1, | 59 MODE_SERVER_FLAG = 0x1, |
| 76 MODE_CLIENT_FLAG = 0x2, | 60 MODE_CLIENT_FLAG = 0x2, |
| 77 MODE_NAMED_FLAG = 0x4, | 61 MODE_NAMED_FLAG = 0x4, |
| 78 #if defined(OS_POSIX) | 62 #if defined(OS_POSIX) |
| 79 MODE_OPEN_ACCESS_FLAG = 0x8, // Don't restrict access based on client UID. | 63 MODE_OPEN_ACCESS_FLAG = 0x8, // Don't restrict access based on client UID. |
| 80 #endif | 64 #endif |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 210 |
| 227 private: | 211 private: |
| 228 // PIMPL to which all channel calls are delegated. | 212 // PIMPL to which all channel calls are delegated. |
| 229 class ChannelImpl; | 213 class ChannelImpl; |
| 230 ChannelImpl *channel_impl_; | 214 ChannelImpl *channel_impl_; |
| 231 }; | 215 }; |
| 232 | 216 |
| 233 } // namespace IPC | 217 } // namespace IPC |
| 234 | 218 |
| 235 #endif // IPC_IPC_CHANNEL_H_ | 219 #endif // IPC_IPC_CHANNEL_H_ |
| OLD | NEW |