Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : // Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #include "chrome/common/child_process_host.h"
8 :
9 : #include "base/compiler_specific.h"
10 : #include "base/logging.h"
11 : #include "base/message_loop.h"
12 : #include "base/process_util.h"
13 : #include "base/singleton.h"
14 : #include "base/waitable_event.h"
15 : #include "mozilla/ipc/ProcessChild.h"
16 : #include "mozilla/ipc/BrowserProcessSubThread.h"
17 : #include "mozilla/ipc/Transport.h"
18 : typedef mozilla::ipc::BrowserProcessSubThread ChromeThread;
19 : #include "chrome/common/process_watcher.h"
20 :
21 : using mozilla::ipc::FileDescriptor;
22 :
23 2 : ChildProcessHost::ChildProcessHost()
24 : : ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
25 2 : opening_channel_(false) {
26 2 : }
27 :
28 :
29 0 : ChildProcessHost::~ChildProcessHost() {
30 0 : }
31 :
32 2 : bool ChildProcessHost::CreateChannel() {
33 2 : channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::wstring());
34 2 : channel_.reset(new IPC::Channel(
35 4 : channel_id_, IPC::Channel::MODE_SERVER, &listener_));
36 2 : if (!channel_->Connect())
37 0 : return false;
38 :
39 2 : opening_channel_ = true;
40 :
41 2 : return true;
42 : }
43 :
44 0 : bool ChildProcessHost::CreateChannel(FileDescriptor& aFileDescriptor) {
45 0 : if (channel_.get()) {
46 0 : channel_->Close();
47 : }
48 0 : channel_ = mozilla::ipc::OpenDescriptor(aFileDescriptor, IPC::Channel::MODE_SERVER);
49 0 : if (!channel_->Connect()) {
50 0 : return false;
51 : }
52 :
53 0 : opening_channel_ = true;
54 :
55 0 : return true;
56 : }
57 :
58 2 : ChildProcessHost::ListenerHook::ListenerHook(ChildProcessHost* host)
59 2 : : host_(host) {
60 2 : }
61 :
62 0 : void ChildProcessHost::ListenerHook::OnMessageReceived(
63 : IPC::Message&& msg) {
64 0 : host_->OnMessageReceived(mozilla::Move(msg));
65 0 : }
66 :
67 2 : void ChildProcessHost::ListenerHook::OnChannelConnected(int32_t peer_pid) {
68 2 : host_->opening_channel_ = false;
69 2 : host_->OnChannelConnected(peer_pid);
70 2 : }
71 :
72 0 : void ChildProcessHost::ListenerHook::OnChannelError() {
73 0 : host_->opening_channel_ = false;
74 0 : host_->OnChannelError();
75 0 : }
76 :
77 2 : void ChildProcessHost::ListenerHook::GetQueuedMessages(std::queue<IPC::Message>& queue) {
78 2 : host_->GetQueuedMessages(queue);
79 2 : }
|