OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/gpu/gpu_channel.h" | 5 #include "chrome/gpu/gpu_channel.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/lock.h" | 12 #include "base/lock.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "chrome/common/child_process.h" | 15 #include "chrome/common/child_process.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/gpu_messages.h" | 18 #include "chrome/common/gpu_messages.h" |
19 #include "chrome/gpu/gpu_thread.h" | 19 #include "chrome/gpu/gpu_thread.h" |
20 #include "chrome/gpu/gpu_video_service.h" | 20 #include "chrome/gpu/gpu_video_service.h" |
21 | 21 |
22 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
23 #include "ipc/ipc_channel_posix.h" | 23 #include "ipc/ipc_channel_posix.h" |
24 #endif | 24 #endif |
25 | 25 |
26 GpuChannel::GpuChannel(int renderer_id) | 26 GpuChannel::GpuChannel(int renderer_id) |
27 : renderer_id_(renderer_id) | 27 : renderer_id_(renderer_id) { |
28 #if defined(OS_POSIX) | |
29 , renderer_fd_(-1) | |
30 #endif | |
31 { | |
32 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 28 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
33 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 29 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
34 } | 30 } |
35 | 31 |
36 GpuChannel::~GpuChannel() { | 32 GpuChannel::~GpuChannel() { |
37 #if defined(OS_POSIX) | |
38 IPC::RemoveAndCloseChannelSocket(GetChannelName()); | |
39 | |
40 // If we still have the renderer FD, close it. | |
41 if (renderer_fd_ != -1) { | |
42 close(renderer_fd_); | |
43 } | |
44 #endif | |
45 } | 33 } |
46 | 34 |
47 void GpuChannel::OnChannelConnected(int32 peer_pid) { | 35 void GpuChannel::OnChannelConnected(int32 peer_pid) { |
48 if (!renderer_process_.Open(peer_pid)) { | 36 if (!renderer_process_.Open(peer_pid)) { |
49 NOTREACHED(); | 37 NOTREACHED(); |
50 } | 38 } |
51 } | 39 } |
52 | 40 |
53 void GpuChannel::OnMessageReceived(const IPC::Message& message) { | 41 void GpuChannel::OnMessageReceived(const IPC::Message& message) { |
54 if (log_messages_) { | 42 if (log_messages_) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 #endif | 223 #endif |
236 } | 224 } |
237 | 225 |
238 bool GpuChannel::Init() { | 226 bool GpuChannel::Init() { |
239 // Check whether we're already initialized. | 227 // Check whether we're already initialized. |
240 if (channel_.get()) | 228 if (channel_.get()) |
241 return true; | 229 return true; |
242 | 230 |
243 // Map renderer ID to a (single) channel to that process. | 231 // Map renderer ID to a (single) channel to that process. |
244 std::string channel_name = GetChannelName(); | 232 std::string channel_name = GetChannelName(); |
245 #if defined(OS_POSIX) | |
246 // This gets called when the GpuChannel is initially created. At this | |
247 // point, create the socketpair and assign the GPU side FD to the channel | |
248 // name. Keep the renderer side FD as a member variable in the PluginChannel | |
249 // to be able to transmit it through IPC. | |
250 int gpu_fd; | |
251 IPC::SocketPair(&gpu_fd, &renderer_fd_); | |
252 IPC::AddChannelSocket(channel_name, gpu_fd); | |
253 #endif | |
254 channel_.reset(new IPC::SyncChannel( | 233 channel_.reset(new IPC::SyncChannel( |
255 channel_name, IPC::Channel::MODE_SERVER, this, | 234 channel_name, IPC::Channel::MODE_SERVER, this, |
256 ChildProcess::current()->io_message_loop(), false, | 235 ChildProcess::current()->io_message_loop(), false, |
257 ChildProcess::current()->GetShutDownEvent())); | 236 ChildProcess::current()->GetShutDownEvent())); |
258 | 237 |
259 return true; | 238 return true; |
260 } | 239 } |
261 | 240 |
262 std::string GpuChannel::GetChannelName() { | 241 std::string GpuChannel::GetChannelName() { |
263 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); | 242 return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_); |
264 } | 243 } |
| 244 |
| 245 #if defined(OS_POSIX) |
| 246 int GpuChannel::GetRendererFileDescriptor() { |
| 247 int fd = -1; |
| 248 if (channel_.get()) { |
| 249 fd = channel_->GetClientFileDescriptor(); |
| 250 } |
| 251 return fd; |
| 252 } |
| 253 #endif // defined(OS_POSIX) |
| 254 |
OLD | NEW |