Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 1292263003: ipc: Use a global for the process's attachment broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_message2
Patch Set: Comments from avi. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_channel_posix.h ('k') | ipc/ipc_channel_posix_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 10 #include <stdint.h>
(...skipping 20 matching lines...) Expand all
31 #include "base/logging.h" 31 #include "base/logging.h"
32 #include "base/memory/scoped_ptr.h" 32 #include "base/memory/scoped_ptr.h"
33 #include "base/memory/singleton.h" 33 #include "base/memory/singleton.h"
34 #include "base/posix/eintr_wrapper.h" 34 #include "base/posix/eintr_wrapper.h"
35 #include "base/posix/global_descriptors.h" 35 #include "base/posix/global_descriptors.h"
36 #include "base/process/process_handle.h" 36 #include "base/process/process_handle.h"
37 #include "base/rand_util.h" 37 #include "base/rand_util.h"
38 #include "base/stl_util.h" 38 #include "base/stl_util.h"
39 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
40 #include "base/synchronization/lock.h" 40 #include "base/synchronization/lock.h"
41 #include "ipc/attachment_broker.h"
41 #include "ipc/ipc_descriptors.h" 42 #include "ipc/ipc_descriptors.h"
42 #include "ipc/ipc_listener.h" 43 #include "ipc/ipc_listener.h"
43 #include "ipc/ipc_logging.h" 44 #include "ipc/ipc_logging.h"
44 #include "ipc/ipc_message_attachment_set.h" 45 #include "ipc/ipc_message_attachment_set.h"
45 #include "ipc/ipc_message_utils.h" 46 #include "ipc/ipc_message_utils.h"
46 #include "ipc/ipc_platform_file_attachment_posix.h" 47 #include "ipc/ipc_platform_file_attachment_posix.h"
47 #include "ipc/ipc_switches.h" 48 #include "ipc/ipc_switches.h"
48 #include "ipc/unix_domain_socket_util.h" 49 #include "ipc/unix_domain_socket_util.h"
49 50
50 namespace IPC { 51 namespace IPC {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 #endif 176 #endif
176 177
177 //------------------------------------------------------------------------------ 178 //------------------------------------------------------------------------------
178 179
179 #if defined(OS_LINUX) 180 #if defined(OS_LINUX)
180 int ChannelPosix::global_pid_ = 0; 181 int ChannelPosix::global_pid_ = 0;
181 #endif // OS_LINUX 182 #endif // OS_LINUX
182 183
183 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, 184 ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle,
184 Mode mode, 185 Mode mode,
185 Listener* listener, 186 Listener* listener)
186 AttachmentBroker* broker)
187 : ChannelReader(listener), 187 : ChannelReader(listener),
188 mode_(mode), 188 mode_(mode),
189 peer_pid_(base::kNullProcessId), 189 peer_pid_(base::kNullProcessId),
190 is_blocked_on_write_(false), 190 is_blocked_on_write_(false),
191 waiting_connect_(true), 191 waiting_connect_(true),
192 message_send_bytes_written_(0), 192 message_send_bytes_written_(0),
193 pipe_name_(channel_handle.name), 193 pipe_name_(channel_handle.name),
194 in_dtor_(false), 194 in_dtor_(false),
195 must_unlink_(false), 195 must_unlink_(false) {
196 broker_(broker) {
197 if (!CreatePipe(channel_handle)) { 196 if (!CreatePipe(channel_handle)) {
198 // The pipe may have been closed already. 197 // The pipe may have been closed already.
199 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; 198 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client";
200 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name 199 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name
201 << "\" in " << modestr << " mode"; 200 << "\" in " << modestr << " mode";
202 } 201 }
203 } 202 }
204 203
205 ChannelPosix::~ChannelPosix() { 204 ChannelPosix::~ChannelPosix() {
206 in_dtor_ = true; 205 in_dtor_ = true;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 TRACE_EVENT_FLAG_FLOW_OUT); 516 TRACE_EVENT_FLAG_FLOW_OUT);
518 output_queue_.push(message); 517 output_queue_.push(message);
519 if (!is_blocked_on_write_ && !waiting_connect_) { 518 if (!is_blocked_on_write_ && !waiting_connect_) {
520 return ProcessOutgoingMessages(); 519 return ProcessOutgoingMessages();
521 } 520 }
522 521
523 return true; 522 return true;
524 } 523 }
525 524
526 AttachmentBroker* ChannelPosix::GetAttachmentBroker() { 525 AttachmentBroker* ChannelPosix::GetAttachmentBroker() {
527 return broker_; 526 return AttachmentBroker::GetGlobal();
528 } 527 }
529 528
530 int ChannelPosix::GetClientFileDescriptor() const { 529 int ChannelPosix::GetClientFileDescriptor() const {
531 base::AutoLock lock(client_pipe_lock_); 530 base::AutoLock lock(client_pipe_lock_);
532 return client_pipe_.get(); 531 return client_pipe_.get();
533 } 532 }
534 533
535 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() { 534 base::ScopedFD ChannelPosix::TakeClientFileDescriptor() {
536 base::AutoLock lock(client_pipe_lock_); 535 base::AutoLock lock(client_pipe_lock_);
537 if (!client_pipe_.is_valid()) 536 if (!client_pipe_.is_valid())
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 1015
1017 //------------------------------------------------------------------------------ 1016 //------------------------------------------------------------------------------
1018 // Channel's methods 1017 // Channel's methods
1019 1018
1020 // static 1019 // static
1021 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle, 1020 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle,
1022 Mode mode, 1021 Mode mode,
1023 Listener* listener, 1022 Listener* listener,
1024 AttachmentBroker* broker) { 1023 AttachmentBroker* broker) {
1025 return make_scoped_ptr( 1024 return make_scoped_ptr(
1026 new ChannelPosix(channel_handle, mode, listener, broker)); 1025 new ChannelPosix(channel_handle, mode, listener));
1027 } 1026 }
1028 1027
1029 // static 1028 // static
1030 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { 1029 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) {
1031 // A random name is sufficient validation on posix systems, so we don't need 1030 // A random name is sufficient validation on posix systems, so we don't need
1032 // an additional shared secret. 1031 // an additional shared secret.
1033 1032
1034 std::string id = prefix; 1033 std::string id = prefix;
1035 if (!id.empty()) 1034 if (!id.empty())
1036 id.append("."); 1035 id.append(".");
1037 1036
1038 return id.append(GenerateUniqueRandomChannelID()); 1037 return id.append(GenerateUniqueRandomChannelID());
1039 } 1038 }
1040 1039
1041 bool Channel::IsNamedServerInitialized( 1040 bool Channel::IsNamedServerInitialized(
1042 const std::string& channel_id) { 1041 const std::string& channel_id) {
1043 return ChannelPosix::IsNamedServerInitialized(channel_id); 1042 return ChannelPosix::IsNamedServerInitialized(channel_id);
1044 } 1043 }
1045 1044
1046 #if defined(OS_LINUX) 1045 #if defined(OS_LINUX)
1047 // static 1046 // static
1048 void Channel::SetGlobalPid(int pid) { 1047 void Channel::SetGlobalPid(int pid) {
1049 ChannelPosix::SetGlobalPid(pid); 1048 ChannelPosix::SetGlobalPid(pid);
1050 } 1049 }
1051 #endif // OS_LINUX 1050 #endif // OS_LINUX
1052 1051
1053 } // namespace IPC 1052 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.h ('k') | ipc/ipc_channel_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698