diff options
author | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-04 12:16:48 +0000 |
---|---|---|
committer | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-04 12:16:48 +0000 |
commit | 9530df2727e0f01e2b1205350f11f6b873ff77d4 (patch) | |
tree | a9048ac699ae1737a34b95aa0671c5479cde5917 /ppapi | |
parent | b8770cd5fa7618d1b5d1e629de92e10f8beca668 (diff) | |
download | chromium_src-9530df2727e0f01e2b1205350f11f6b873ff77d4.zip chromium_src-9530df2727e0f01e2b1205350f11f6b873ff77d4.tar.gz chromium_src-9530df2727e0f01e2b1205350f11f6b873ff77d4.tar.bz2 |
Test Keeping NaCl plugins used in app background pages alive when active.
(Re-landing with fixes from https://codereview.chromium.org/111563006/ )
Activity in Native Client plugins results in IPC messages
sent to the BrowserPpapiHostImpl and routed to call
extensions::ProcessManager::KeepaliveImpulse.
Testing patch, builds on implementation:
https://codereview.chromium.org/61063003/
Design doc:
https://docs.google.com/a/chromium.org/document/d/1mI0lS1rfAf-BAGLmWAEcWy37Xq9dOvgfMx8OqeUMXts/edit#
BUG=298339
No change to mseaborn owned file since last LGTM:
TBR=mseaborn@chromium.org
Review URL: https://codereview.chromium.org/112663007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243021 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/plugin_main_nacl.cc | 17 | ||||
-rw-r--r-- | ppapi/shared_impl/ppapi_switches.cc | 3 | ||||
-rw-r--r-- | ppapi/shared_impl/ppapi_switches.h | 1 | ||||
-rw-r--r-- | ppapi/tests/extensions/background_keepalive/background.cc | 63 | ||||
-rw-r--r-- | ppapi/tests/extensions/background_keepalive/background.js | 41 | ||||
-rw-r--r-- | ppapi/tests/extensions/background_keepalive/manifest.json | 11 | ||||
-rw-r--r-- | ppapi/tests/extensions/extensions.gyp | 19 |
7 files changed, 155 insertions, 0 deletions
diff --git a/ppapi/proxy/plugin_main_nacl.cc b/ppapi/proxy/plugin_main_nacl.cc index 4407d7c..a128f63 100644 --- a/ppapi/proxy/plugin_main_nacl.cc +++ b/ppapi/proxy/plugin_main_nacl.cc @@ -13,6 +13,7 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" +#include "base/strings/string_number_conversions.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "components/tracing/child_trace_message_filter.h" @@ -29,6 +30,7 @@ #include "ppapi/proxy/plugin_message_filter.h" #include "ppapi/proxy/plugin_proxy_delegate.h" #include "ppapi/proxy/resource_reply_thread_registrar.h" +#include "ppapi/shared_impl/ppapi_switches.h" #include "ppapi/shared_impl/ppb_audio_shared.h" #if defined(IPC_MESSAGE_LOG_ENABLED) @@ -94,6 +96,8 @@ class PpapiDispatcher : public ProxyChannel, SerializedHandle handle); void OnPluginDispatcherMessageReceived(const IPC::Message& msg); + void SetPpapiKeepAliveThrottleFromCommandLine(); + std::set<PP_Instance> instances_; std::map<uint32, PluginDispatcher*> plugin_dispatchers_; uint32 next_plugin_dispatcher_id_; @@ -206,6 +210,7 @@ void PpapiDispatcher::OnMsgCreateNaClChannel( logging::LoggingSettings settings; settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; logging::InitLogging(settings); + SetPpapiKeepAliveThrottleFromCommandLine(); command_line_and_logging_initialized = true; } // Tell the process-global GetInterface which interfaces it can return to the @@ -248,6 +253,18 @@ void PpapiDispatcher::OnPluginDispatcherMessageReceived( dispatcher->second->OnMessageReceived(msg); } +void PpapiDispatcher::SetPpapiKeepAliveThrottleFromCommandLine() { + unsigned keepalive_throttle_interval_milliseconds = 0; + if (base::StringToUint( + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kPpapiKeepAliveThrottle), + &keepalive_throttle_interval_milliseconds)) { + ppapi::proxy::PluginGlobals::Get()-> + set_keepalive_throttle_interval_milliseconds( + keepalive_throttle_interval_milliseconds); + } +} + } // namespace void PpapiPluginRegisterThreadCreator( diff --git a/ppapi/shared_impl/ppapi_switches.cc b/ppapi/shared_impl/ppapi_switches.cc index 84ba250..2a3f1c28 100644 --- a/ppapi/shared_impl/ppapi_switches.cc +++ b/ppapi/shared_impl/ppapi_switches.cc @@ -9,4 +9,7 @@ namespace switches { // Enables the testing interface for PPAPI. const char kEnablePepperTesting[] = "enable-pepper-testing"; +// Specifies throttling time in milliseconds for PpapiHostMsg_Keepalive IPCs. +const char kPpapiKeepAliveThrottle[] = "ppapi-keep-alive-throttle"; + } // namespace switches diff --git a/ppapi/shared_impl/ppapi_switches.h b/ppapi/shared_impl/ppapi_switches.h index a5c8e9d..4fb9c3481 100644 --- a/ppapi/shared_impl/ppapi_switches.h +++ b/ppapi/shared_impl/ppapi_switches.h @@ -10,6 +10,7 @@ namespace switches { PPAPI_SHARED_EXPORT extern const char kEnablePepperTesting[]; +PPAPI_SHARED_EXPORT extern const char kPpapiKeepAliveThrottle[]; } // namespace switches diff --git a/ppapi/tests/extensions/background_keepalive/background.cc b/ppapi/tests/extensions/background_keepalive/background.cc new file mode 100644 index 0000000..59dd5ef --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/background.cc @@ -0,0 +1,63 @@ +// Copyright 2014 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 <cstdio> +#include <string> + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/message_loop.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/var.h" +#include "ppapi/utility/completion_callback_factory.h" + +class Instance : public pp::Instance { + public: + explicit Instance(PP_Instance instance) : + pp::Instance(instance), + callback_factory_(this), + delay_milliseconds_(10), + active_(true) { + DoSomething(PP_OK); + } + virtual ~Instance() {} + + virtual void HandleMessage(const pp::Var& message_var) { + std::string message_string = message_var.AsString(); + if (message_string == "be idle") { + active_ = false; + } else { + PostMessage("Unhandled control message."); + } + } + + void DoSomething(int32_t result) { + if (active_) { + pp::MessageLoop loop = pp::MessageLoop::GetCurrent(); + pp::CompletionCallback c = callback_factory_.NewCallback( + &Instance::DoSomething); + loop.PostWork(c, delay_milliseconds_); + } + } + + pp::CompletionCallbackFactory<Instance> callback_factory_; + int delay_milliseconds_; + bool active_; +}; + +class Module : public pp::Module { + public: + Module() : pp::Module() {} + virtual ~Module() {} + + virtual pp::Instance* CreateInstance(PP_Instance instance) { + return new Instance(instance); + } +}; + +namespace pp { +Module* CreateModule() { + return new ::Module(); +} +} // namespace pp + diff --git a/ppapi/tests/extensions/background_keepalive/background.js b/ppapi/tests/extensions/background_keepalive/background.js new file mode 100644 index 0000000..6b9c259 --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/background.js @@ -0,0 +1,41 @@ +// Copyright 2014 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. + +var NaClModulesExpected = 0; +var NaClModulesLoaded = 0; + +// Indicate load success. +function moduleDidLoad() { + NaClModulesLoaded++; + if (NaClModulesLoaded == NaClModulesExpected) + chrome.test.sendMessage("nacl_modules_loaded", handleChromeTestMessage); +} + +var handleChromeTestMessage = function (message) { + NaClModules = document.querySelectorAll('embed'); + for (var i = 0; i < NaClModules.length; i++) { + NaClModules[i].postMessage(message); + } +} + +function handleNaclMessage(message_event) { + console.log("handleNaclMessage: " + message_event.data); +} + +function createNaClEmbed() { + NaClModulesExpected++; + + var listener = document.createElement("div"); + listener.addEventListener("load", moduleDidLoad, true); + listener.addEventListener("message", handleNaclMessage, true); + listener.innerHTML = '<embed' + + ' src="ppapi_tests_extensions_background_keepalive.nmf"' + + ' type="application/x-nacl" />'; + document.body.appendChild(listener); +} + +// Create 2 embeds to verify that we can handle more than one. +createNaClEmbed(); +createNaClEmbed(); + diff --git a/ppapi/tests/extensions/background_keepalive/manifest.json b/ppapi/tests/extensions/background_keepalive/manifest.json new file mode 100644 index 0000000..28fb912 --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/manifest.json @@ -0,0 +1,11 @@ +{ + "manifest_version": 2, + "name": "background_nacl", + "version": "0", + "description": "Tests keeping background page with NaCl alive when active.", + "app": { + "background": { + "scripts": ["background.js"] + } + } +} diff --git a/ppapi/tests/extensions/extensions.gyp b/ppapi/tests/extensions/extensions.gyp index d063b83f4..70af268 100644 --- a/ppapi/tests/extensions/extensions.gyp +++ b/ppapi/tests/extensions/extensions.gyp @@ -29,5 +29,24 @@ ], }, }, + { + 'target_name': 'ppapi_tests_extensions_background_keepalive', + 'type': 'none', + 'variables': { + 'nexe_target': 'ppapi_tests_extensions_background_keepalive', + # Only newlib build is used in tests, no need to build others. + 'build_newlib': 1, + 'build_glibc': 0, + 'build_pnacl_newlib': 0, + 'nexe_destination_dir': 'test_data/ppapi/tests/extensions/background_keepalive', + 'sources': [ + 'background_keepalive/background.cc', + ], + 'test_files': [ + 'background_keepalive/background.js', + 'background_keepalive/manifest.json', + ], + }, + }, ], } |