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

Side by Side Diff: ipc/ipc_channel_win.cc

Issue 9150030: Initialize IPC:ChannelHandle from existing HANDLE (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: use #elif Created 8 years, 11 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_handle.h ('k') | ipc/ipc_message_utils.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) 2011 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_win.h" 5 #include "ipc/ipc_channel_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // static 107 // static
108 const std::wstring Channel::ChannelImpl::PipeName( 108 const std::wstring Channel::ChannelImpl::PipeName(
109 const std::string& channel_id) { 109 const std::string& channel_id) {
110 std::string name("\\\\.\\pipe\\chrome."); 110 std::string name("\\\\.\\pipe\\chrome.");
111 return ASCIIToWide(name.append(channel_id)); 111 return ASCIIToWide(name.append(channel_id));
112 } 112 }
113 113
114 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, 114 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle,
115 Mode mode) { 115 Mode mode) {
116 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); 116 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_);
117 const std::wstring pipe_name = PipeName(channel_handle.name); 117 std::wstring pipe_name;
118 if (mode & MODE_SERVER_FLAG) { 118 // If we already have a valid pipe for channel just copy it.
119 if (channel_handle.pipe.handle) {
120 DCHECK(channel_handle.name.empty());
121 pipe_name = L"Not Available"; // Just used for LOG
122 if (!DuplicateHandle(GetCurrentProcess(),
123 channel_handle.pipe.handle,
124 GetCurrentProcess(),
125 &pipe_,
126 0,
127 FALSE,
128 DUPLICATE_SAME_ACCESS)) {
129 LOG(WARNING) << "DuplicateHandle failed. Error :" << GetLastError();
130 return false;
131 }
132 #ifndef NDEBUG
133 // Check that the given pipe confirms to the specified mode. We can
134 // only check for PIPE_TYPE_MESSAGE & PIPE_SERVER_END flags since the
135 // other flags (PIPE_TYPE_BYTE, and PIPE_CLIENT_END) are defined as 0.
136 DWORD flags = 0;
137 GetNamedPipeInfo(channel_handle.pipe.handle, &flags, NULL, NULL, NULL);
138 DCHECK(!(flags & PIPE_TYPE_MESSAGE));
139 if (mode & MODE_SERVER_FLAG) {
140 DCHECK(flags & PIPE_SERVER_END);
cpu_(ooo_6.6-7.5) 2012/01/23 18:55:34 This should be return false; here and in line 142.
amit 2012/01/23 19:58:41 Done.
141 } else if (mode & MODE_CLIENT_FLAG) {
142 DCHECK(!(flags & PIPE_SERVER_END));
143 }
144 #endif // NDEBUG
145 } else if (mode & MODE_SERVER_FLAG) {
146 DCHECK(!channel_handle.pipe.handle);
147 const DWORD open_mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
148 FILE_FLAG_FIRST_PIPE_INSTANCE;
149 pipe_name = PipeName(channel_handle.name);
119 pipe_ = CreateNamedPipeW(pipe_name.c_str(), 150 pipe_ = CreateNamedPipeW(pipe_name.c_str(),
120 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | 151 open_mode,
121 FILE_FLAG_FIRST_PIPE_INSTANCE,
122 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 152 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
123 1, 153 1,
124 Channel::kReadBufferSize, 154 Channel::kReadBufferSize,
125 Channel::kReadBufferSize, 155 Channel::kReadBufferSize,
126 5000, 156 5000,
127 NULL); 157 NULL);
128 } else if (mode & MODE_CLIENT_FLAG) { 158 } else if (mode & MODE_CLIENT_FLAG) {
159 DCHECK(!channel_handle.pipe.handle);
160 pipe_name = PipeName(channel_handle.name);
129 pipe_ = CreateFileW(pipe_name.c_str(), 161 pipe_ = CreateFileW(pipe_name.c_str(),
130 GENERIC_READ | GENERIC_WRITE, 162 GENERIC_READ | GENERIC_WRITE,
131 0, 163 0,
132 NULL, 164 NULL,
133 OPEN_EXISTING, 165 OPEN_EXISTING,
134 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | 166 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION |
135 FILE_FLAG_OVERLAPPED, 167 FILE_FLAG_OVERLAPPED,
136 NULL); 168 NULL);
137 } else { 169 } else {
138 NOTREACHED(); 170 NOTREACHED();
139 } 171 }
172
140 if (pipe_ == INVALID_HANDLE_VALUE) { 173 if (pipe_ == INVALID_HANDLE_VALUE) {
141 // If this process is being closed, the pipe may be gone already. 174 // If this process is being closed, the pipe may be gone already.
142 LOG(WARNING) << "Unable to create pipe \"" << pipe_name << 175 LOG(WARNING) << "Unable to create pipe \"" << pipe_name <<
143 "\" in " << (mode == 0 ? "server" : "client") 176 "\" in " << (mode == 0 ? "server" : "client")
144 << " mode. Error :" << GetLastError(); 177 << " mode. Error :" << GetLastError();
145 return false; 178 return false;
146 } 179 }
147 180
148 // Create the Hello message to be sent when Connect is called 181 // Create the Hello message to be sent when Connect is called
149 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, 182 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 bool Channel::Send(Message* message) { 457 bool Channel::Send(Message* message) {
425 return channel_impl_->Send(message); 458 return channel_impl_->Send(message);
426 } 459 }
427 460
428 // static 461 // static
429 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { 462 bool Channel::IsNamedServerInitialized(const std::string& channel_id) {
430 return ChannelImpl::IsNamedServerInitialized(channel_id); 463 return ChannelImpl::IsNamedServerInitialized(channel_id);
431 } 464 }
432 465
433 } // namespace IPC 466 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_handle.h ('k') | ipc/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698