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 19 matching lines...) Expand all Loading... |
30 #include "base/logging.h" | 30 #include "base/logging.h" |
31 #include "base/memory/scoped_ptr.h" | 31 #include "base/memory/scoped_ptr.h" |
32 #include "base/memory/singleton.h" | 32 #include "base/memory/singleton.h" |
33 #include "base/posix/eintr_wrapper.h" | 33 #include "base/posix/eintr_wrapper.h" |
34 #include "base/posix/global_descriptors.h" | 34 #include "base/posix/global_descriptors.h" |
35 #include "base/process/process_handle.h" | 35 #include "base/process/process_handle.h" |
36 #include "base/rand_util.h" | 36 #include "base/rand_util.h" |
37 #include "base/stl_util.h" | 37 #include "base/stl_util.h" |
38 #include "base/strings/string_util.h" | 38 #include "base/strings/string_util.h" |
39 #include "base/synchronization/lock.h" | 39 #include "base/synchronization/lock.h" |
| 40 #include "ipc/attachment_broker.h" |
40 #include "ipc/ipc_descriptors.h" | 41 #include "ipc/ipc_descriptors.h" |
41 #include "ipc/ipc_listener.h" | 42 #include "ipc/ipc_listener.h" |
42 #include "ipc/ipc_logging.h" | 43 #include "ipc/ipc_logging.h" |
43 #include "ipc/ipc_message_attachment_set.h" | 44 #include "ipc/ipc_message_attachment_set.h" |
44 #include "ipc/ipc_message_utils.h" | 45 #include "ipc/ipc_message_utils.h" |
45 #include "ipc/ipc_platform_file_attachment_posix.h" | 46 #include "ipc/ipc_platform_file_attachment_posix.h" |
46 #include "ipc/ipc_switches.h" | 47 #include "ipc/ipc_switches.h" |
47 #include "ipc/unix_domain_socket_util.h" | 48 #include "ipc/unix_domain_socket_util.h" |
48 | 49 |
49 namespace IPC { | 50 namespace IPC { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 #endif | 177 #endif |
177 | 178 |
178 //------------------------------------------------------------------------------ | 179 //------------------------------------------------------------------------------ |
179 | 180 |
180 #if defined(OS_LINUX) | 181 #if defined(OS_LINUX) |
181 int ChannelPosix::global_pid_ = 0; | 182 int ChannelPosix::global_pid_ = 0; |
182 #endif // OS_LINUX | 183 #endif // OS_LINUX |
183 | 184 |
184 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, | 185 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, |
185 Mode mode, | 186 Mode mode, |
186 Listener* listener, | 187 Listener* listener) |
187 AttachmentBroker* broker) | |
188 : ChannelReader(listener), | 188 : ChannelReader(listener), |
189 mode_(mode), | 189 mode_(mode), |
190 peer_pid_(base::kNullProcessId), | 190 peer_pid_(base::kNullProcessId), |
191 is_blocked_on_write_(false), | 191 is_blocked_on_write_(false), |
192 waiting_connect_(true), | 192 waiting_connect_(true), |
193 message_send_bytes_written_(0), | 193 message_send_bytes_written_(0), |
194 pipe_name_(channel_handle.name), | 194 pipe_name_(channel_handle.name), |
195 in_dtor_(false), | 195 in_dtor_(false), |
196 must_unlink_(false), | 196 must_unlink_(false) { |
197 broker_(broker) { | |
198 if (!CreatePipe(channel_handle)) { | 197 if (!CreatePipe(channel_handle)) { |
199 // The pipe may have been closed already. | 198 // The pipe may have been closed already. |
200 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; | 199 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; |
201 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name | 200 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name |
202 << "\" in " << modestr << " mode"; | 201 << "\" in " << modestr << " mode"; |
203 } | 202 } |
204 } | 203 } |
205 | 204 |
206 ChannelPosix::~ChannelPosix() { | 205 ChannelPosix::~ChannelPosix() { |
207 in_dtor_ = true; | 206 in_dtor_ = true; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 TRACE_EVENT_FLAG_FLOW_OUT); | 517 TRACE_EVENT_FLAG_FLOW_OUT); |
519 output_queue_.push(message); | 518 output_queue_.push(message); |
520 if (!is_blocked_on_write_ && !waiting_connect_) { | 519 if (!is_blocked_on_write_ && !waiting_connect_) { |
521 return ProcessOutgoingMessages(); | 520 return ProcessOutgoingMessages(); |
522 } | 521 } |
523 | 522 |
524 return true; | 523 return true; |
525 } | 524 } |
526 | 525 |
527 AttachmentBroker* ChannelPosix::GetAttachmentBroker() { | 526 AttachmentBroker* ChannelPosix::GetAttachmentBroker() { |
528 return broker_; | 527 return AttachmentBroker::GetGlobal(); |
529 } | 528 } |
530 | 529 |
531 int ChannelPosix::GetClientFileDescriptor() const { | 530 int ChannelPosix::GetClientFileDescriptor() const { |
532 base::AutoLock lock(client_pipe_lock_); | 531 base::AutoLock lock(client_pipe_lock_); |
533 return client_pipe_.get(); | 532 return client_pipe_.get(); |
534 } | 533 } |
535 | 534 |
536 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() { | 535 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() { |
537 base::AutoLock lock(client_pipe_lock_); | 536 base::AutoLock lock(client_pipe_lock_); |
538 if (!client_pipe_.is_valid()) | 537 if (!client_pipe_.is_valid()) |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1016 |
1018 //------------------------------------------------------------------------------ | 1017 //------------------------------------------------------------------------------ |
1019 // Channel's methods | 1018 // Channel's methods |
1020 | 1019 |
1021 // static | 1020 // static |
1022 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, | 1021 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, |
1023 Mode mode, | 1022 Mode mode, |
1024 Listener* listener, | 1023 Listener* listener, |
1025 AttachmentBroker* broker) { | 1024 AttachmentBroker* broker) { |
1026 return make_scoped_ptr( | 1025 return make_scoped_ptr( |
1027 new ChannelPosix(channel_handle, mode, listener, broker)); | 1026 new ChannelPosix(channel_handle, mode, listener)); |
1028 } | 1027 } |
1029 | 1028 |
1030 // static | 1029 // static |
1031 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { | 1030 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { |
1032 // A random name is sufficient validation on posix systems, so we don't need | 1031 // A random name is sufficient validation on posix systems, so we don't need |
1033 // an additional shared secret. | 1032 // an additional shared secret. |
1034 | 1033 |
1035 std::string id = prefix; | 1034 std::string id = prefix; |
1036 if (!id.empty()) | 1035 if (!id.empty()) |
1037 id.append("."); | 1036 id.append("."); |
1038 | 1037 |
1039 return id.append(GenerateUniqueRandomChannelID()); | 1038 return id.append(GenerateUniqueRandomChannelID()); |
1040 } | 1039 } |
1041 | 1040 |
1042 bool Channel::IsNamedServerInitialized( | 1041 bool Channel::IsNamedServerInitialized( |
1043 const std::string& channel_id) { | 1042 const std::string& channel_id) { |
1044 return ChannelPosix::IsNamedServerInitialized(channel_id); | 1043 return ChannelPosix::IsNamedServerInitialized(channel_id); |
1045 } | 1044 } |
1046 | 1045 |
1047 #if defined(OS_LINUX) | 1046 #if defined(OS_LINUX) |
1048 // static | 1047 // static |
1049 void Channel::SetGlobalPid(int pid) { | 1048 void Channel::SetGlobalPid(int pid) { |
1050 ChannelPosix::SetGlobalPid(pid); | 1049 ChannelPosix::SetGlobalPid(pid); |
1051 } | 1050 } |
1052 #endif // OS_LINUX | 1051 #endif // OS_LINUX |
1053 | 1052 |
1054 } // namespace IPC | 1053 } // namespace IPC |
OLD | NEW |