| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "ipc/ipc_channel_win.h" | 5 #include "ipc/ipc_channel_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <sddl.h> | 8 #include <sddl.h> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 //------------------------------------------------------------------------------ | 98 //------------------------------------------------------------------------------ |
| 99 | 99 |
| 100 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, | 100 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, |
| 101 Mode mode, Listener* listener) | 101 Mode mode, Listener* listener) |
| 102 : ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), | 102 : ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), |
| 103 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), | 103 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), |
| 104 pipe_(INVALID_HANDLE_VALUE), | 104 pipe_(INVALID_HANDLE_VALUE), |
| 105 listener_(listener), | 105 listener_(listener), |
| 106 waiting_connect_(mode == MODE_SERVER || mode == MODE_NAMED_SERVER), | 106 waiting_connect_(mode & MODE_SERVER_FLAG), |
| 107 processing_incoming_(false), | 107 processing_incoming_(false), |
| 108 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { | 108 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { |
| 109 switch(mode) { | |
| 110 case MODE_NONE: | |
| 111 LOG(FATAL) << "Bad mode for " << channel_handle.name; | |
| 112 break; | |
| 113 case MODE_SERVER: | |
| 114 case MODE_CLIENT: | |
| 115 break; | |
| 116 case MODE_NAMED_SERVER: | |
| 117 mode = MODE_SERVER; | |
| 118 break; | |
| 119 case MODE_NAMED_CLIENT: | |
| 120 mode = MODE_CLIENT; | |
| 121 break; | |
| 122 // Intentionally no default case here so that the compiler | |
| 123 // will check that we handle all the cases in the enum. | |
| 124 } | |
| 125 if (!CreatePipe(channel_handle, mode)) { | 109 if (!CreatePipe(channel_handle, mode)) { |
| 126 // The pipe may have been closed already. | 110 // The pipe may have been closed already. |
| 127 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name << | 111 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name << |
| 128 "\" in " << (mode == 0 ? "server" : "client") << " mode."; | 112 "\" in " << (mode == 0 ? "server" : "client") << " mode."; |
| 129 } | 113 } |
| 130 } | 114 } |
| 131 | 115 |
| 132 Channel::ChannelImpl::~ChannelImpl() { | 116 Channel::ChannelImpl::~ChannelImpl() { |
| 133 Close(); | 117 Close(); |
| 134 } | 118 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 std::wostringstream ss; | 172 std::wostringstream ss; |
| 189 // XXX(darin): get application name from somewhere else | 173 // XXX(darin): get application name from somewhere else |
| 190 ss << L"\\\\.\\pipe\\chrome." << ASCIIToWide(channel_id); | 174 ss << L"\\\\.\\pipe\\chrome." << ASCIIToWide(channel_id); |
| 191 return ss.str(); | 175 return ss.str(); |
| 192 } | 176 } |
| 193 | 177 |
| 194 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, | 178 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, |
| 195 Mode mode) { | 179 Mode mode) { |
| 196 DCHECK(pipe_ == INVALID_HANDLE_VALUE); | 180 DCHECK(pipe_ == INVALID_HANDLE_VALUE); |
| 197 const std::wstring pipe_name = PipeName(channel_handle.name); | 181 const std::wstring pipe_name = PipeName(channel_handle.name); |
| 198 if (mode == MODE_SERVER) { | 182 if (mode & MODE_SERVER_FLAG) { |
| 199 SECURITY_ATTRIBUTES security_attributes = {0}; | 183 SECURITY_ATTRIBUTES security_attributes = {0}; |
| 200 security_attributes.bInheritHandle = FALSE; | 184 security_attributes.bInheritHandle = FALSE; |
| 201 security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); | 185 security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); |
| 202 if (!GetLogonSessionOnlyDACL( | 186 if (!GetLogonSessionOnlyDACL( |
| 203 reinterpret_cast<SECURITY_DESCRIPTOR**>( | 187 reinterpret_cast<SECURITY_DESCRIPTOR**>( |
| 204 &security_attributes.lpSecurityDescriptor))) { | 188 &security_attributes.lpSecurityDescriptor))) { |
| 205 NOTREACHED(); | 189 NOTREACHED(); |
| 206 } | 190 } |
| 207 | 191 |
| 208 pipe_ = CreateNamedPipeW(pipe_name.c_str(), | 192 pipe_ = CreateNamedPipeW(pipe_name.c_str(), |
| 209 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | | 193 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | |
| 210 FILE_FLAG_FIRST_PIPE_INSTANCE, | 194 FILE_FLAG_FIRST_PIPE_INSTANCE, |
| 211 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | 195 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, |
| 212 1, // number of pipe instances | 196 1, // number of pipe instances |
| 213 // output buffer size (XXX tune) | 197 // output buffer size (XXX tune) |
| 214 Channel::kReadBufferSize, | 198 Channel::kReadBufferSize, |
| 215 // input buffer size (XXX tune) | 199 // input buffer size (XXX tune) |
| 216 Channel::kReadBufferSize, | 200 Channel::kReadBufferSize, |
| 217 5000, // timeout in milliseconds (XXX tune) | 201 5000, // timeout in milliseconds (XXX tune) |
| 218 &security_attributes); | 202 &security_attributes); |
| 219 LocalFree(security_attributes.lpSecurityDescriptor); | 203 LocalFree(security_attributes.lpSecurityDescriptor); |
| 220 } else { | 204 } else if (mode & MODE_CLIENT_FLAG) { |
| 221 pipe_ = CreateFileW(pipe_name.c_str(), | 205 pipe_ = CreateFileW(pipe_name.c_str(), |
| 222 GENERIC_READ | GENERIC_WRITE, | 206 GENERIC_READ | GENERIC_WRITE, |
| 223 0, | 207 0, |
| 224 NULL, | 208 NULL, |
| 225 OPEN_EXISTING, | 209 OPEN_EXISTING, |
| 226 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | | 210 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | |
| 227 FILE_FLAG_OVERLAPPED, | 211 FILE_FLAG_OVERLAPPED, |
| 228 NULL); | 212 NULL); |
| 213 } else { |
| 214 NOTREACHED(); |
| 229 } | 215 } |
| 230 if (pipe_ == INVALID_HANDLE_VALUE) { | 216 if (pipe_ == INVALID_HANDLE_VALUE) { |
| 231 // If this process is being closed, the pipe may be gone already. | 217 // If this process is being closed, the pipe may be gone already. |
| 232 LOG(WARNING) << "failed to create pipe: " << GetLastError(); | 218 LOG(WARNING) << "failed to create pipe: " << GetLastError(); |
| 233 return false; | 219 return false; |
| 234 } | 220 } |
| 235 | 221 |
| 236 // Create the Hello message to be sent when Connect is called | 222 // Create the Hello message to be sent when Connect is called |
| 237 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, | 223 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, |
| 238 HELLO_MESSAGE_TYPE, | 224 HELLO_MESSAGE_TYPE, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 491 |
| 506 void Channel::set_listener(Listener* listener) { | 492 void Channel::set_listener(Listener* listener) { |
| 507 channel_impl_->set_listener(listener); | 493 channel_impl_->set_listener(listener); |
| 508 } | 494 } |
| 509 | 495 |
| 510 bool Channel::Send(Message* message) { | 496 bool Channel::Send(Message* message) { |
| 511 return channel_impl_->Send(message); | 497 return channel_impl_->Send(message); |
| 512 } | 498 } |
| 513 | 499 |
| 514 } // namespace IPC | 500 } // namespace IPC |
| OLD | NEW |