OLD | NEW |
1 // Copyright (c) 2012 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 "components/nacl/browser/nacl_broker_host_win.h" | 5 #include "components/nacl/browser/nacl_broker_host_win.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/nacl/browser/nacl_broker_service_win.h" | 10 #include "components/nacl/browser/nacl_broker_service_win.h" |
11 #include "components/nacl/browser/nacl_browser.h" | 11 #include "components/nacl/browser/nacl_browser.h" |
12 #include "components/nacl/common/nacl_cmd_line.h" | 12 #include "components/nacl/common/nacl_cmd_line.h" |
| 13 #include "components/nacl/common/nacl_constants.h" |
13 #include "components/nacl/common/nacl_messages.h" | 14 #include "components/nacl/common/nacl_messages.h" |
14 #include "components/nacl/common/nacl_process_type.h" | 15 #include "components/nacl/common/nacl_process_type.h" |
15 #include "components/nacl/common/nacl_switches.h" | 16 #include "components/nacl/common/nacl_switches.h" |
16 #include "content/public/browser/browser_child_process_host.h" | 17 #include "content/public/browser/browser_child_process_host.h" |
17 #include "content/public/browser/child_process_data.h" | 18 #include "content/public/browser/child_process_data.h" |
18 #include "content/public/common/child_process_host.h" | 19 #include "content/public/common/child_process_host.h" |
19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
20 #include "content/public/common/mojo_channel_switches.h" | 21 #include "content/public/common/mojo_channel_switches.h" |
21 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 22 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
22 #include "mojo/edk/embedder/embedder.h" | 23 #include "mojo/edk/embedder/embedder.h" |
(...skipping 17 matching lines...) Expand all Loading... |
40 | 41 |
41 namespace nacl { | 42 namespace nacl { |
42 | 43 |
43 NaClBrokerHost::NaClBrokerHost() : is_terminating_(false) { | 44 NaClBrokerHost::NaClBrokerHost() : is_terminating_(false) { |
44 } | 45 } |
45 | 46 |
46 NaClBrokerHost::~NaClBrokerHost() { | 47 NaClBrokerHost::~NaClBrokerHost() { |
47 } | 48 } |
48 | 49 |
49 bool NaClBrokerHost::Init() { | 50 bool NaClBrokerHost::Init() { |
50 const std::string mojo_child_token = mojo::edk::GenerateRandomToken(); | |
51 DCHECK(!process_); | 51 DCHECK(!process_); |
52 process_.reset(content::BrowserChildProcessHost::Create( | 52 process_.reset(content::BrowserChildProcessHost::Create( |
53 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this, | 53 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_BROKER), this, |
54 mojo_child_token)); | 54 kNaClBrokerServiceName)); |
55 | 55 |
56 // Create the channel that will be used for communicating with the broker. | 56 process_->GetHost()->CreateChannelMojo(); |
57 const std::string mojo_channel_token = | |
58 process_->GetHost()->CreateChannelMojo(mojo_child_token); | |
59 if (mojo_channel_token.empty()) | |
60 return false; | |
61 | 57 |
62 // Create the path to the nacl broker/loader executable. | 58 // Create the path to the nacl broker/loader executable. |
63 base::FilePath nacl_path; | 59 base::FilePath nacl_path; |
64 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path)) | 60 if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path)) |
65 return false; | 61 return false; |
66 | 62 |
67 base::CommandLine* cmd_line = new base::CommandLine(nacl_path); | 63 base::CommandLine* cmd_line = new base::CommandLine(nacl_path); |
68 CopyNaClCommandLineArguments(cmd_line); | 64 CopyNaClCommandLineArguments(cmd_line); |
69 | 65 |
70 cmd_line->AppendSwitchASCII(switches::kProcessType, | 66 cmd_line->AppendSwitchASCII(switches::kProcessType, |
71 switches::kNaClBrokerProcess); | 67 switches::kNaClBrokerProcess); |
72 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); | |
73 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 68 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
74 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 69 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
75 | 70 |
76 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate, cmd_line, | 71 process_->Launch(new NaClBrokerSandboxedProcessLauncherDelegate, cmd_line, |
77 true); | 72 true); |
78 return true; | 73 return true; |
79 } | 74 } |
80 | 75 |
81 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { | 76 bool NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) { |
82 bool handled = true; | 77 bool handled = true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid, | 114 NaClBrokerService::GetInstance()->OnDebugExceptionHandlerLaunched(pid, |
120 success); | 115 success); |
121 } | 116 } |
122 | 117 |
123 void NaClBrokerHost::StopBroker() { | 118 void NaClBrokerHost::StopBroker() { |
124 is_terminating_ = true; | 119 is_terminating_ = true; |
125 process_->Send(new NaClProcessMsg_StopBroker()); | 120 process_->Send(new NaClProcessMsg_StopBroker()); |
126 } | 121 } |
127 | 122 |
128 } // namespace nacl | 123 } // namespace nacl |
OLD | NEW |