Bumping manifests a=b2g-bump
[gecko.git] / dom / plugins / ipc / PluginProcessParent.cpp
blobd7fb2fde97438343bf8fca2644c1cf9d6e581e7f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/plugins/PluginProcessParent.h"
9 #include "base/string_util.h"
10 #include "base/process_util.h"
12 #include "mozilla/ipc/BrowserProcessSubThread.h"
13 #include "mozilla/plugins/PluginMessageUtils.h"
14 #include "mozilla/Telemetry.h"
16 using std::vector;
17 using std::string;
19 using mozilla::ipc::BrowserProcessSubThread;
20 using mozilla::ipc::GeckoChildProcessHost;
21 using mozilla::plugins::PluginProcessParent;
22 using base::ProcessArchitecture;
24 template<>
25 struct RunnableMethodTraits<PluginProcessParent>
27 static void RetainCallee(PluginProcessParent* obj) { }
28 static void ReleaseCallee(PluginProcessParent* obj) { }
31 PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
32 GeckoChildProcessHost(GeckoProcessType_Plugin),
33 mPluginFilePath(aPluginFilePath)
37 PluginProcessParent::~PluginProcessParent()
41 bool
42 PluginProcessParent::Launch(int32_t timeoutMs)
44 ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture();
45 uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
47 uint32_t pluginLibArchitectures = currentArchitecture;
48 #ifdef XP_MACOSX
49 nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures);
50 if (NS_FAILED(rv)) {
51 // If the call failed just assume that we want the current architecture.
52 pluginLibArchitectures = currentArchitecture;
54 #endif
56 ProcessArchitecture selectedArchitecture = currentArchitecture;
57 if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) {
58 // Prefererence in order: x86_64, i386, PPC. The only particularly important thing
59 // about this order is that we'll prefer 64-bit architectures first.
60 if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) {
61 selectedArchitecture = base::PROCESS_ARCH_X86_64;
63 else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) {
64 selectedArchitecture = base::PROCESS_ARCH_I386;
66 else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) {
67 selectedArchitecture = base::PROCESS_ARCH_PPC;
69 else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) {
70 selectedArchitecture = base::PROCESS_ARCH_ARM;
72 else {
73 return false;
77 vector<string> args;
78 args.push_back(MungePluginDsoPath(mPluginFilePath));
79 Telemetry::AutoTimer<Telemetry::PLUGIN_STARTUP_MS> timer;
80 return SyncLaunch(args, timeoutMs, selectedArchitecture);
83 void
84 PluginProcessParent::Delete()
86 MessageLoop* currentLoop = MessageLoop::current();
87 MessageLoop* ioLoop = XRE_GetIOMessageLoop();
89 if (currentLoop == ioLoop) {
90 delete this;
91 return;
94 ioLoop->PostTask(FROM_HERE,
95 NewRunnableMethod(this, &PluginProcessParent::Delete));