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

Side by Side Diff: content/child/npapi/np_channel_base.cc

Issue 1184523003: attachment broker wip (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor comments. Created 5 years, 6 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 | « content/child/npapi/np_channel_base.h ('k') | content/common/child_process_host_impl.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/child/npapi/np_channel_base.h" 5 #include "content/child/npapi/np_channel_base.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/files/scoped_file.h" 9 #include "base/files/scoped_file.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 NPChannelBase* NPChannelBase::GetChannel( 65 NPChannelBase* NPChannelBase::GetChannel(
66 const IPC::ChannelHandle& channel_handle, 66 const IPC::ChannelHandle& channel_handle,
67 IPC::Channel::Mode mode, 67 IPC::Channel::Mode mode,
68 ChannelFactory factory, 68 ChannelFactory factory,
69 base::SingleThreadTaskRunner* ipc_task_runner, 69 base::SingleThreadTaskRunner* ipc_task_runner,
70 bool create_pipe_now, 70 bool create_pipe_now,
71 base::WaitableEvent* shutdown_event) { 71 base::WaitableEvent* shutdown_event,
72 IPC::AttachmentBroker* broker) {
72 #if defined(OS_POSIX) 73 #if defined(OS_POSIX)
73 // On POSIX the channel_handle conveys an FD (socket) which is duped by the 74 // On POSIX the channel_handle conveys an FD (socket) which is duped by the
74 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism). 75 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism).
75 // Ensure we do not leak this FD. 76 // Ensure we do not leak this FD.
76 base::ScopedFD fd(channel_handle.socket.auto_close ? 77 base::ScopedFD fd(channel_handle.socket.auto_close ?
77 channel_handle.socket.fd : -1); 78 channel_handle.socket.fd : -1);
78 #endif 79 #endif
79 80
80 scoped_refptr<NPChannelBase> channel; 81 scoped_refptr<NPChannelBase> channel;
81 std::string channel_key = channel_handle.name; 82 std::string channel_key = channel_handle.name;
82 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); 83 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key);
83 if (iter == GetChannelMap()->end()) { 84 if (iter == GetChannelMap()->end()) {
84 channel = factory(); 85 channel = factory();
85 } else { 86 } else {
86 channel = iter->second; 87 channel = iter->second;
87 } 88 }
88 89
89 DCHECK(channel.get() != NULL); 90 DCHECK(channel.get() != NULL);
90 91
91 if (!channel->channel_valid()) { 92 if (!channel->channel_valid()) {
92 channel->channel_handle_ = channel_handle; 93 channel->channel_handle_ = channel_handle;
93 #if defined(OS_POSIX) 94 #if defined(OS_POSIX)
94 ignore_result(fd.release()); 95 ignore_result(fd.release());
95 #endif 96 #endif
96 if (mode & IPC::Channel::MODE_SERVER_FLAG) { 97 if (mode & IPC::Channel::MODE_SERVER_FLAG) {
97 channel->channel_handle_.name = 98 channel->channel_handle_.name =
98 IPC::Channel::GenerateVerifiedChannelID(channel_key); 99 IPC::Channel::GenerateVerifiedChannelID(channel_key);
99 } 100 }
100 channel->mode_ = mode; 101 channel->mode_ = mode;
101 if (channel->Init(ipc_task_runner, create_pipe_now, shutdown_event)) { 102 if (channel->Init(ipc_task_runner, create_pipe_now, shutdown_event,
103 broker)) {
102 (*GetChannelMap())[channel_key] = channel; 104 (*GetChannelMap())[channel_key] = channel;
103 } else { 105 } else {
104 channel = NULL; 106 channel = NULL;
105 } 107 }
106 } 108 }
107 109
108 return channel.get(); 110 return channel.get();
109 } 111 }
110 112
111 void NPChannelBase::Broadcast(IPC::Message* message) { 113 void NPChannelBase::Broadcast(IPC::Message* message) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 169 }
168 return iter->second; 170 return iter->second;
169 } 171 }
170 172
171 base::WaitableEvent* NPChannelBase::GetModalDialogEvent(int render_view_id) { 173 base::WaitableEvent* NPChannelBase::GetModalDialogEvent(int render_view_id) {
172 return NULL; 174 return NULL;
173 } 175 }
174 176
175 bool NPChannelBase::Init(base::SingleThreadTaskRunner* ipc_task_runner, 177 bool NPChannelBase::Init(base::SingleThreadTaskRunner* ipc_task_runner,
176 bool create_pipe_now, 178 bool create_pipe_now,
177 base::WaitableEvent* shutdown_event) { 179 base::WaitableEvent* shutdown_event,
180 IPC::AttachmentBroker* broker) {
178 #if defined(OS_POSIX) 181 #if defined(OS_POSIX)
179 // Attempting to initialize with an invalid channel handle. 182 // Attempting to initialize with an invalid channel handle.
180 // See http://crbug.com/97285 for details. 183 // See http://crbug.com/97285 for details.
181 if (mode_ == IPC::Channel::MODE_CLIENT && -1 == channel_handle_.socket.fd) 184 if (mode_ == IPC::Channel::MODE_CLIENT && -1 == channel_handle_.socket.fd)
182 return false; 185 return false;
183 #endif 186 #endif
184 187
185 channel_ = 188 channel_ =
186 IPC::SyncChannel::Create(channel_handle_, mode_, this, ipc_task_runner, 189 IPC::SyncChannel::Create(channel_handle_, mode_, this, ipc_task_runner,
187 create_pipe_now, shutdown_event); 190 create_pipe_now, shutdown_event, broker);
188 191
189 #if defined(OS_POSIX) 192 #if defined(OS_POSIX)
190 // Check the validity of fd for bug investigation. Remove after fixed. 193 // Check the validity of fd for bug investigation. Remove after fixed.
191 // See crbug.com/97285 for details. 194 // See crbug.com/97285 for details.
192 if (mode_ == IPC::Channel::MODE_SERVER) 195 if (mode_ == IPC::Channel::MODE_SERVER)
193 CHECK_NE(-1, channel_->GetClientFileDescriptor()); 196 CHECK_NE(-1, channel_->GetClientFileDescriptor());
194 #endif 197 #endif
195 198
196 channel_valid_ = true; 199 channel_valid_ = true;
197 return true; 200 return true;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); 384 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id);
382 return iter != route_to_owner_.end() ? iter->second : default_owner_; 385 return iter != route_to_owner_.end() ? iter->second : default_owner_;
383 } 386 }
384 387
385 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { 388 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) {
386 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); 389 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner);
387 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; 390 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE;
388 } 391 }
389 392
390 } // namespace content 393 } // namespace content
OLDNEW
« no previous file with comments | « content/child/npapi/np_channel_base.h ('k') | content/common/child_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698