| 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_WIN_H_ | 5 #ifndef IPC_IPC_CHANNEL_WIN_H_ |
| 6 #define IPC_IPC_CHANNEL_WIN_H_ | 6 #define IPC_IPC_CHANNEL_WIN_H_ |
| 7 | 7 |
| 8 #include "ipc/ipc_channel.h" | 8 #include "ipc/ipc_channel.h" |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "ipc/ipc_channel_reader.h" | 16 #include "ipc/ipc_channel_reader.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class ThreadChecker; | 19 class ThreadChecker; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace IPC { | 22 namespace IPC { |
| 23 | 23 |
| 24 class Channel::ChannelImpl : public internal::ChannelReader, | 24 class ChannelWin : public Channel, |
| 25 public base::MessageLoopForIO::IOHandler { | 25 public internal::ChannelReader, |
| 26 public base::MessageLoopForIO::IOHandler { |
| 26 public: | 27 public: |
| 27 // Mirror methods of Channel, see ipc_channel.h for description. | 28 // Mirror methods of Channel, see ipc_channel.h for description. |
| 28 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode, | 29 ChannelWin(const IPC::ChannelHandle &channel_handle, Mode mode, |
| 29 Listener* listener); | 30 Listener* listener); |
| 30 ~ChannelImpl(); | 31 ~ChannelWin(); |
| 31 bool Connect(); | 32 |
| 32 void Close(); | 33 // Channel implementation |
| 33 bool Send(Message* message); | 34 virtual bool Connect() OVERRIDE; |
| 35 virtual void Close() OVERRIDE; |
| 36 virtual bool Send(Message* message) OVERRIDE; |
| 37 virtual base::ProcessId GetPeerPID() const OVERRIDE; |
| 38 |
| 34 static bool IsNamedServerInitialized(const std::string& channel_id); | 39 static bool IsNamedServerInitialized(const std::string& channel_id); |
| 35 base::ProcessId peer_pid() const { return peer_pid_; } | 40 |
| 36 | 41 |
| 37 private: | 42 private: |
| 38 // ChannelReader implementation. | 43 // ChannelReader implementation. |
| 39 virtual ReadState ReadData(char* buffer, | 44 virtual ReadState ReadData(char* buffer, |
| 40 int buffer_len, | 45 int buffer_len, |
| 41 int* bytes_read) OVERRIDE; | 46 int* bytes_read) OVERRIDE; |
| 42 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE; | 47 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE; |
| 43 bool DidEmptyInputBuffers() OVERRIDE; | 48 bool DidEmptyInputBuffers() OVERRIDE; |
| 44 virtual void HandleInternalMessage(const Message& msg) OVERRIDE; | 49 virtual void HandleInternalMessage(const Message& msg) OVERRIDE; |
| 45 | 50 |
| 46 static const base::string16 PipeName(const std::string& channel_id, | 51 static const base::string16 PipeName(const std::string& channel_id, |
| 47 int32* secret); | 52 int32* secret); |
| 48 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode); | 53 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode); |
| 49 | 54 |
| 50 bool ProcessConnection(); | 55 bool ProcessConnection(); |
| 51 bool ProcessOutgoingMessages(base::MessageLoopForIO::IOContext* context, | 56 bool ProcessOutgoingMessages(base::MessageLoopForIO::IOContext* context, |
| 52 DWORD bytes_written); | 57 DWORD bytes_written); |
| 53 | 58 |
| 54 // MessageLoop::IOHandler implementation. | 59 // MessageLoop::IOHandler implementation. |
| 55 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 60 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 56 DWORD bytes_transfered, | 61 DWORD bytes_transfered, |
| 57 DWORD error); | 62 DWORD error); |
| 58 | 63 |
| 59 private: | 64 private: |
| 60 struct State { | 65 struct State { |
| 61 explicit State(ChannelImpl* channel); | 66 explicit State(ChannelWin* channel); |
| 62 ~State(); | 67 ~State(); |
| 63 base::MessageLoopForIO::IOContext context; | 68 base::MessageLoopForIO::IOContext context; |
| 64 bool is_pending; | 69 bool is_pending; |
| 65 }; | 70 }; |
| 66 | 71 |
| 67 State input_state_; | 72 State input_state_; |
| 68 State output_state_; | 73 State output_state_; |
| 69 | 74 |
| 70 HANDLE pipe_; | 75 HANDLE pipe_; |
| 71 | 76 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 87 // Determines if we should validate a client's secret on connection. | 92 // Determines if we should validate a client's secret on connection. |
| 88 bool validate_client_; | 93 bool validate_client_; |
| 89 | 94 |
| 90 // This is a unique per-channel value used to authenticate the client end of | 95 // This is a unique per-channel value used to authenticate the client end of |
| 91 // a connection. If the value is non-zero, the client passes it in the hello | 96 // a connection. If the value is non-zero, the client passes it in the hello |
| 92 // and the host validates. (We don't send the zero value fto preserve IPC | 97 // and the host validates. (We don't send the zero value fto preserve IPC |
| 93 // compatability with existing clients that don't validate the channel.) | 98 // compatability with existing clients that don't validate the channel.) |
| 94 int32 client_secret_; | 99 int32 client_secret_; |
| 95 | 100 |
| 96 | 101 |
| 97 base::WeakPtrFactory<ChannelImpl> weak_factory_; | 102 base::WeakPtrFactory<ChannelWin> weak_factory_; |
| 98 | 103 |
| 99 scoped_ptr<base::ThreadChecker> thread_check_; | 104 scoped_ptr<base::ThreadChecker> thread_check_; |
| 100 | 105 |
| 101 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); | 106 DISALLOW_COPY_AND_ASSIGN(ChannelWin); |
| 102 }; | 107 }; |
| 103 | 108 |
| 104 } // namespace IPC | 109 } // namespace IPC |
| 105 | 110 |
| 106 #endif // IPC_IPC_CHANNEL_WIN_H_ | 111 #endif // IPC_IPC_CHANNEL_WIN_H_ |
| OLD | NEW |