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 #include "ipc/ipc_channel_posix.h" | 5 #include "ipc/ipc_channel_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 #endif | 176 #endif |
177 | 177 |
178 //------------------------------------------------------------------------------ | 178 //------------------------------------------------------------------------------ |
179 | 179 |
180 #if defined(OS_LINUX) | 180 #if defined(OS_LINUX) |
181 int ChannelPosix::global_pid_ = 0; | 181 int ChannelPosix::global_pid_ = 0; |
182 #endif // OS_LINUX | 182 #endif // OS_LINUX |
183 | 183 |
184 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, | 184 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, |
185 Mode mode, Listener* listener) | 185 Mode mode, |
| 186 Listener* listener, |
| 187 AttachmentBroker* broker) |
186 : ChannelReader(listener), | 188 : ChannelReader(listener), |
187 mode_(mode), | 189 mode_(mode), |
188 peer_pid_(base::kNullProcessId), | 190 peer_pid_(base::kNullProcessId), |
189 is_blocked_on_write_(false), | 191 is_blocked_on_write_(false), |
190 waiting_connect_(true), | 192 waiting_connect_(true), |
191 message_send_bytes_written_(0), | 193 message_send_bytes_written_(0), |
192 pipe_name_(channel_handle.name), | 194 pipe_name_(channel_handle.name), |
193 in_dtor_(false), | 195 in_dtor_(false), |
194 must_unlink_(false) { | 196 must_unlink_(false), |
| 197 broker_(broker) { |
195 if (!CreatePipe(channel_handle)) { | 198 if (!CreatePipe(channel_handle)) { |
196 // The pipe may have been closed already. | 199 // The pipe may have been closed already. |
197 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; | 200 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; |
198 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name | 201 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name |
199 << "\" in " << modestr << " mode"; | 202 << "\" in " << modestr << " mode"; |
200 } | 203 } |
201 } | 204 } |
202 | 205 |
203 ChannelPosix::~ChannelPosix() { | 206 ChannelPosix::~ChannelPosix() { |
204 in_dtor_ = true; | 207 in_dtor_ = true; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 513 |
511 message->TraceMessageBegin(); | 514 message->TraceMessageBegin(); |
512 output_queue_.push(message); | 515 output_queue_.push(message); |
513 if (!is_blocked_on_write_ && !waiting_connect_) { | 516 if (!is_blocked_on_write_ && !waiting_connect_) { |
514 return ProcessOutgoingMessages(); | 517 return ProcessOutgoingMessages(); |
515 } | 518 } |
516 | 519 |
517 return true; | 520 return true; |
518 } | 521 } |
519 | 522 |
| 523 AttachmentBroker* ChannelPosix::GetAttachmentBroker() { |
| 524 return broker_; |
| 525 } |
| 526 |
520 int ChannelPosix::GetClientFileDescriptor() const { | 527 int ChannelPosix::GetClientFileDescriptor() const { |
521 base::AutoLock lock(client_pipe_lock_); | 528 base::AutoLock lock(client_pipe_lock_); |
522 return client_pipe_.get(); | 529 return client_pipe_.get(); |
523 } | 530 } |
524 | 531 |
525 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() { | 532 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() { |
526 base::AutoLock lock(client_pipe_lock_); | 533 base::AutoLock lock(client_pipe_lock_); |
527 if (!client_pipe_.is_valid()) | 534 if (!client_pipe_.is_valid()) |
528 return base::ScopedFD(); | 535 return base::ScopedFD(); |
529 PipeMap::GetInstance()->Remove(pipe_name_); | 536 PipeMap::GetInstance()->Remove(pipe_name_); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 if (-1 != fd_to_close) { | 995 if (-1 != fd_to_close) { |
989 int rv = IGNORE_EINTR(close(fd_to_close)); | 996 int rv = IGNORE_EINTR(close(fd_to_close)); |
990 DPCHECK(0 == rv); | 997 DPCHECK(0 == rv); |
991 } | 998 } |
992 } | 999 } |
993 | 1000 |
994 //------------------------------------------------------------------------------ | 1001 //------------------------------------------------------------------------------ |
995 // Channel's methods | 1002 // Channel's methods |
996 | 1003 |
997 // static | 1004 // static |
998 scoped_ptr<Channel> Channel::Create( | 1005 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, |
999 const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { | 1006 Mode mode, |
1000 return make_scoped_ptr(new ChannelPosix(channel_handle, mode, listener)); | 1007 Listener* listener, |
| 1008 AttachmentBroker* broker) { |
| 1009 return make_scoped_ptr( |
| 1010 new ChannelPosix(channel_handle, mode, listener, broker)); |
1001 } | 1011 } |
1002 | 1012 |
1003 // static | 1013 // static |
1004 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { | 1014 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { |
1005 // A random name is sufficient validation on posix systems, so we don't need | 1015 // A random name is sufficient validation on posix systems, so we don't need |
1006 // an additional shared secret. | 1016 // an additional shared secret. |
1007 | 1017 |
1008 std::string id = prefix; | 1018 std::string id = prefix; |
1009 if (!id.empty()) | 1019 if (!id.empty()) |
1010 id.append("."); | 1020 id.append("."); |
1011 | 1021 |
1012 return id.append(GenerateUniqueRandomChannelID()); | 1022 return id.append(GenerateUniqueRandomChannelID()); |
1013 } | 1023 } |
1014 | 1024 |
1015 bool Channel::IsNamedServerInitialized( | 1025 bool Channel::IsNamedServerInitialized( |
1016 const std::string& channel_id) { | 1026 const std::string& channel_id) { |
1017 return ChannelPosix::IsNamedServerInitialized(channel_id); | 1027 return ChannelPosix::IsNamedServerInitialized(channel_id); |
1018 } | 1028 } |
1019 | 1029 |
1020 #if defined(OS_LINUX) | 1030 #if defined(OS_LINUX) |
1021 // static | 1031 // static |
1022 void Channel::SetGlobalPid(int pid) { | 1032 void Channel::SetGlobalPid(int pid) { |
1023 ChannelPosix::SetGlobalPid(pid); | 1033 ChannelPosix::SetGlobalPid(pid); |
1024 } | 1034 } |
1025 #endif // OS_LINUX | 1035 #endif // OS_LINUX |
1026 | 1036 |
1027 } // namespace IPC | 1037 } // namespace IPC |
OLD | NEW |