summaryrefslogtreecommitdiffstats
path: root/chrome/browser/nacl_host
diff options
context:
space:
mode:
authorgregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 18:57:09 +0000
committergregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 18:57:09 +0000
commit103607e7bb3d18c9c5b78cf8dc558c2504047b1d (patch)
tree650fd33a0dfeded9eec339c24856307de5a86248 /chrome/browser/nacl_host
parent20c01928492aca53ee6ba6e1c84a199e889cb74d (diff)
downloadchromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.zip
chromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.tar.gz
chromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.tar.bz2
Implement the broker process that launches NaCl loader processes on 64-bit Windows systems.
BUG=28176 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=37578 Review URL: http://codereview.chromium.org/542030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37720 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/nacl_host')
-rw-r--r--chrome/browser/nacl_host/nacl_broker_host.cc74
-rw-r--r--chrome/browser/nacl_host/nacl_broker_host.h46
-rw-r--r--chrome/browser/nacl_host/nacl_broker_service.cc69
-rw-r--r--chrome/browser/nacl_host/nacl_broker_service.h57
4 files changed, 246 insertions, 0 deletions
diff --git a/chrome/browser/nacl_host/nacl_broker_host.cc b/chrome/browser/nacl_host/nacl_broker_host.cc
new file mode 100644
index 0000000..8abc228
--- /dev/null
+++ b/chrome/browser/nacl_host/nacl_broker_host.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/nacl_host/nacl_broker_host.h"
+
+#include "base/command_line.h"
+#include "ipc/ipc_switches.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/nacl_host/nacl_broker_service.h"
+#include "chrome/browser/nacl_process_host.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/nacl_cmd_line.h"
+#include "chrome/common/nacl_messages.h"
+
+NaClBrokerHost::NaClBrokerHost(
+ ResourceDispatcherHost* resource_dispatcher_host)
+ : ChildProcessHost(NACL_BROKER_PROCESS, resource_dispatcher_host) {
+}
+
+NaClBrokerHost::~NaClBrokerHost() {
+}
+
+URLRequestContext* NaClBrokerHost::GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data) {
+ return NULL;
+}
+
+bool NaClBrokerHost::Init() {
+ // Create the channel that will be used for communicating with the broker.
+ if (!CreateChannel())
+ return false;
+
+ // Create the path to the nacl broker/loader executable.
+ FilePath exe_path = GetChildPath(false);
+ if (exe_path.empty())
+ return false;
+
+ FilePath nacl_path = exe_path.DirName().Append(chrome::kNaClAppName);
+ CommandLine* cmd_line = new CommandLine(nacl_path);
+ nacl::CopyNaClCommandLineArguments(cmd_line);
+
+ cmd_line->AppendSwitchWithValue(switches::kProcessType,
+ switches::kNaClBrokerProcess);
+
+ cmd_line->AppendSwitchWithValue(switches::kProcessChannelID,
+ ASCIIToWide(channel_id()));
+
+ ChildProcessHost::Launch(FilePath(), cmd_line);
+ return true;
+}
+
+void NaClBrokerHost::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(NaClBrokerHost, msg)
+ IPC_MESSAGE_HANDLER(NaClProcessMsg_BrokerReady, OnBrokerReady)
+ IPC_MESSAGE_HANDLER(NaClProcessMsg_LoaderLaunched, OnLoaderLaunched)
+ IPC_END_MESSAGE_MAP()
+}
+
+void NaClBrokerHost::OnBrokerReady() {
+ NaClBrokerService::GetInstance()->OnBrokerStarted();
+}
+
+bool NaClBrokerHost::LaunchLoader(
+ const std::wstring& loader_channel_id) {
+ return Send(new NaClProcessMsg_LaunchLoaderThroughBroker(loader_channel_id));
+}
+
+void NaClBrokerHost::OnLoaderLaunched(const std::wstring& loader_channel_id,
+ base::ProcessHandle handle) {
+ NaClBrokerService::GetInstance()->OnLoaderLaunched(loader_channel_id, handle);
+}
diff --git a/chrome/browser/nacl_host/nacl_broker_host.h b/chrome/browser/nacl_host/nacl_broker_host.h
new file mode 100644
index 0000000..f526aa1
--- /dev/null
+++ b/chrome/browser/nacl_host/nacl_broker_host.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NACL_HOST_NACL_BROKER_HOST_H_
+#define CHROME_BROWSER_NACL_HOST_NACL_BROKER_HOST_H_
+
+#include "base/basictypes.h"
+#include "base/process.h"
+#include "chrome/common/child_process_host.h"
+#include "ipc/ipc_message.h"
+
+class NaClBrokerHost : public ChildProcessHost {
+ public:
+ explicit NaClBrokerHost(ResourceDispatcherHost* resource_dispatcher_host);
+ ~NaClBrokerHost();
+
+ // This function starts the broker process. It needs to be called
+ // before loaders can be launched.
+ bool Init();
+
+ // Send a message to the broker process, causing it to launch
+ // a Native Client loader process.
+ bool LaunchLoader(const std::wstring& loader_channel_id);
+
+ private:
+ // ResourceDispatcherHost::Receiver implementation:
+ virtual URLRequestContext* GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data);
+
+ virtual bool CanShutdown() { return true; }
+
+ // Handler for NaClProcessMsg_BrokerReady message (sent by the broker process)
+ void OnBrokerReady();
+ // Handler for NaClProcessMsg_LoaderLaunched message
+ void OnLoaderLaunched(const std::wstring& loader_channel_id,
+ base::ProcessHandle handle);
+
+ // IPC::Channel::Listener
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ DISALLOW_COPY_AND_ASSIGN(NaClBrokerHost);
+};
+
+#endif // CHROME_BROWSER_NACL_HOST_NACL_BROKER_HOST_H_
diff --git a/chrome/browser/nacl_host/nacl_broker_service.cc b/chrome/browser/nacl_host/nacl_broker_service.cc
new file mode 100644
index 0000000..ef659cd
--- /dev/null
+++ b/chrome/browser/nacl_host/nacl_broker_service.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/nacl_host/nacl_broker_service.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/nacl_process_host.h"
+#include "chrome/common/chrome_switches.h"
+
+NaClBrokerService* NaClBrokerService::GetInstance() {
+ return Singleton<NaClBrokerService>::get();
+}
+
+NaClBrokerService::NaClBrokerService()
+ : broker_started_(false),
+ broker_host_(NULL),
+ resource_dispatcher_host_(NULL),
+ initialized_(false) {
+}
+
+void NaClBrokerService::Init(ResourceDispatcherHost* resource_dispatcher_host) {
+ if (initialized_) {
+ return;
+ }
+ resource_dispatcher_host_ = resource_dispatcher_host;
+ StartBroker();
+ initialized_ = true;
+}
+
+bool NaClBrokerService::StartBroker() {
+ broker_host_.reset(new NaClBrokerHost(resource_dispatcher_host_));
+ if (!broker_host_->Init()) {
+ // Initialization failed, we will not retry in the future
+ broker_host_.reset(NULL);
+ }
+ return (broker_host_ != NULL);
+}
+
+bool NaClBrokerService::LaunchLoader(NaClProcessHost* nacl_process_host,
+ const std::wstring& loader_channel_id) {
+ if (broker_started_) {
+ broker_host_->LaunchLoader(loader_channel_id);
+ } else {
+ // Add task to the list
+ pending_launches_[loader_channel_id] = nacl_process_host;
+ }
+ return true;
+}
+
+void NaClBrokerService::OnBrokerStarted() {
+ PendingLaunchesMap::iterator it;
+ for (it = pending_launches_.begin(); it != pending_launches_.end(); it++) {
+ broker_host_->LaunchLoader(it->first);
+ }
+ broker_started_ = true;
+}
+
+void NaClBrokerService::OnLoaderLaunched(const std::wstring& channel_id,
+ base::ProcessHandle handle) {
+ NaClProcessHost* client;
+ PendingLaunchesMap::iterator it = pending_launches_.find(channel_id);
+ if (pending_launches_.end() == it) {
+ NOTREACHED();
+ }
+ client = it->second;
+ client->OnProcessLaunchedByBroker(handle);
+ pending_launches_.erase(it);
+}
diff --git a/chrome/browser/nacl_host/nacl_broker_service.h b/chrome/browser/nacl_host/nacl_broker_service.h
new file mode 100644
index 0000000..75e089d
--- /dev/null
+++ b/chrome/browser/nacl_host/nacl_broker_service.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_H_
+#define CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/singleton.h"
+#include "chrome/browser/nacl_host/nacl_broker_host.h"
+
+class NaClProcessHost;
+
+class NaClBrokerService {
+ public:
+ // Returns the NaClBrokerService singleton.
+ static NaClBrokerService* GetInstance();
+
+ void Init(ResourceDispatcherHost* resource_dispatcher_host);
+
+ // Can be called several times, must be called before LaunchLoader.
+ bool StartBroker();
+
+ // Send a message to the broker process, causing it to launch
+ // a Native Client loader process.
+ bool LaunchLoader(NaClProcessHost* client,
+ const std::wstring& loader_channel_id);
+
+ // Called by NaClBrokerHost to notify the service
+ // that the broker was launched.
+ void OnBrokerStarted();
+
+ // Called by NaClBrokerHost to notify the service that a loader was launched.
+ void OnLoaderLaunched(const std::wstring& channel_id,
+ base::ProcessHandle handle);
+
+ private:
+ typedef std::map<std::wstring, NaClProcessHost*>
+ PendingLaunchesMap;
+
+ friend struct DefaultSingletonTraits<NaClBrokerService>;
+
+ NaClBrokerService();
+ ~NaClBrokerService() {}
+
+ bool broker_started_;
+ scoped_ptr<NaClBrokerHost> broker_host_;
+ bool initialized_;
+ ResourceDispatcherHost* resource_dispatcher_host_;
+ PendingLaunchesMap pending_launches_;
+
+ DISALLOW_COPY_AND_ASSIGN(NaClBrokerService);
+};
+
+#endif // CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_H_