summaryrefslogtreecommitdiffstats
path: root/chrome/browser/utility_process_host.cc
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 22:23:43 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 22:23:43 +0000
commit1fca149ca717c64ae05edb534a61a909dc0a6d11 (patch)
tree6972a9efe49eba842a77cdeb98be8ac2caba8d27 /chrome/browser/utility_process_host.cc
parent20a85780ae0ae9b8467b10146044fec8c1144e77 (diff)
downloadchromium_src-1fca149ca717c64ae05edb534a61a909dc0a6d11.zip
chromium_src-1fca149ca717c64ae05edb534a61a909dc0a6d11.tar.gz
chromium_src-1fca149ca717c64ae05edb534a61a909dc0a6d11.tar.bz2
Introducing the Utility process, which handles the unpacking and verification
of extension packages. This is a first pass. In the second pass, I will add support for transcoding the manifest and any images in the browser process. BUG=11680 Review URL: http://codereview.chromium.org/114027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/utility_process_host.cc')
-rw-r--r--chrome/browser/utility_process_host.cc87
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc
new file mode 100644
index 0000000..20b34d5
--- /dev/null
+++ b/chrome/browser/utility_process_host.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2009 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/utility_process_host.h"
+
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/process_util.h"
+#include "base/task.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/render_messages.h"
+
+#if defined(OS_WIN)
+#include "chrome/browser/sandbox_policy.h"
+#endif
+
+UtilityProcessHost::UtilityProcessHost(ResourceDispatcherHost* rdh,
+ Client* client,
+ MessageLoop* client_loop)
+ : ChildProcessHost(UTILITY_PROCESS, rdh),
+ client_(client),
+ client_loop_(client_loop) {
+}
+
+UtilityProcessHost::~UtilityProcessHost() {
+}
+
+bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) {
+ // Grant the subprocess access to the entire subdir the extension file is
+ // in, so that it can unpack to that dir.
+ if (!StartProcess(extension.DirName()))
+ return false;
+
+ Send(new UtilityMsg_UnpackExtension(extension));
+ return true;
+}
+
+bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) {
+ if (!CreateChannel())
+ return false;
+
+ std::wstring exe_path;
+ if (!PathService::Get(base::FILE_EXE, &exe_path))
+ return false;
+
+ CommandLine cmd_line(exe_path);
+ cmd_line.AppendSwitchWithValue(switches::kProcessType,
+ switches::kUtilityProcess);
+ cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, channel_id());
+
+ base::ProcessHandle process;
+#if defined(OS_WIN)
+ process = sandbox::StartProcessWithAccess(&cmd_line, exposed_dir);
+#else
+ // TODO(port): sandbox
+ base::LaunchApp(cmd_line, false, false, &process);
+#endif
+ if (!process)
+ return false;
+ SetHandle(process);
+
+ return true;
+}
+
+void UtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
+ client_loop_->PostTask(FROM_HERE,
+ NewRunnableMethod(client_.get(), &Client::OnMessageReceived, message));
+}
+
+void UtilityProcessHost::OnChannelError() {
+ bool child_exited;
+ bool did_crash = base::DidProcessCrash(&child_exited, handle());
+ if (did_crash) {
+ client_loop_->PostTask(FROM_HERE,
+ NewRunnableMethod(client_.get(), &Client::OnProcessCrashed));
+ }
+}
+
+void UtilityProcessHost::Client::OnMessageReceived(
+ const IPC::Message& message) {
+ IPC_BEGIN_MESSAGE_MAP(UtilityProcessHost, message)
+ IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Reply,
+ Client::OnUnpackExtensionReply)
+ IPC_END_MESSAGE_MAP_EX()
+}