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

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: added dchecks 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
cpu_(ooo_6.6-7.5) 2012/01/20 22:22:25 2012
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;
cpu_(ooo_6.6-7.5) 2012/01/20 22:22:25 How do you feel about calling GetNamedPipeInfo an
131 }
132 } else if (mode & MODE_SERVER_FLAG) {
133 DCHECK(!channel_handle.pipe.handle);
134 const DWORD open_mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
135 FILE_FLAG_FIRST_PIPE_INSTANCE;
136 pipe_name = PipeName(channel_handle.name);
119 pipe_ = CreateNamedPipeW(pipe_name.c_str(), 137 pipe_ = CreateNamedPipeW(pipe_name.c_str(),
120 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | 138 open_mode,
121 FILE_FLAG_FIRST_PIPE_INSTANCE,
122 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 139 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
123 1, 140 1,
124 Channel::kReadBufferSize, 141 Channel::kReadBufferSize,
125 Channel::kReadBufferSize, 142 Channel::kReadBufferSize,
126 5000, 143 5000,
127 NULL); 144 NULL);
128 } else if (mode & MODE_CLIENT_FLAG) { 145 } else if (mode & MODE_CLIENT_FLAG) {
146 DCHECK(!channel_handle.pipe.handle);
147 pipe_name = PipeName(channel_handle.name);
129 pipe_ = CreateFileW(pipe_name.c_str(), 148 pipe_ = CreateFileW(pipe_name.c_str(),
130 GENERIC_READ | GENERIC_WRITE, 149 GENERIC_READ | GENERIC_WRITE,
131 0, 150 0,
132 NULL, 151 NULL,
133 OPEN_EXISTING, 152 OPEN_EXISTING,
134 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | 153 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION |
135 FILE_FLAG_OVERLAPPED, 154 FILE_FLAG_OVERLAPPED,
136 NULL); 155 NULL);
137 } else { 156 } else {
138 NOTREACHED(); 157 NOTREACHED();
139 } 158 }
159
140 if (pipe_ == INVALID_HANDLE_VALUE) { 160 if (pipe_ == INVALID_HANDLE_VALUE) {
141 // If this process is being closed, the pipe may be gone already. 161 // If this process is being closed, the pipe may be gone already.
142 LOG(WARNING) << "Unable to create pipe \"" << pipe_name << 162 LOG(WARNING) << "Unable to create pipe \"" << pipe_name <<
143 "\" in " << (mode == 0 ? "server" : "client") 163 "\" in " << (mode == 0 ? "server" : "client")
144 << " mode. Error :" << GetLastError(); 164 << " mode. Error :" << GetLastError();
145 return false; 165 return false;
146 } 166 }
147 167
148 // Create the Hello message to be sent when Connect is called 168 // Create the Hello message to be sent when Connect is called
149 scoped_ptr<Message> m(new Message(MSG_ROUTING_NONE, 169 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) { 444 bool Channel::Send(Message* message) {
425 return channel_impl_->Send(message); 445 return channel_impl_->Send(message);
426 } 446 }
427 447
428 // static 448 // static
429 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { 449 bool Channel::IsNamedServerInitialized(const std::string& channel_id) {
430 return ChannelImpl::IsNamedServerInitialized(channel_id); 450 return ChannelImpl::IsNamedServerInitialized(channel_id);
431 } 451 }
432 452
433 } // namespace IPC 453 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698