Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 61063003: Keep NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: working prototype Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/nacl_host/nacl_process_host.h" 5 #include "chrome/browser/nacl_host/nacl_process_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/process/launch.h" 18 #include "base/process/launch.h"
19 #include "base/process/process_iterator.h" 19 #include "base/process/process_iterator.h"
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_system.h"
28 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" 30 #include "chrome/browser/nacl_host/nacl_host_message_filter.h"
31 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
30 #include "components/nacl/browser/nacl_browser.h" 33 #include "components/nacl/browser/nacl_browser.h"
31 #include "components/nacl/common/nacl_cmd_line.h" 34 #include "components/nacl/common/nacl_cmd_line.h"
32 #include "components/nacl/common/nacl_host_messages.h" 35 #include "components/nacl/common/nacl_host_messages.h"
33 #include "components/nacl/common/nacl_messages.h" 36 #include "components/nacl/common/nacl_messages.h"
34 #include "components/nacl/common/nacl_process_type.h" 37 #include "components/nacl/common/nacl_process_type.h"
35 #include "components/nacl/common/nacl_switches.h" 38 #include "components/nacl/common/nacl_switches.h"
36 #include "content/public/browser/browser_child_process_host.h" 39 #include "content/public/browser/browser_child_process_host.h"
37 #include "content/public/browser/browser_ppapi_host.h" 40 #include "content/public/browser/browser_ppapi_host.h"
38 #include "content/public/browser/child_process_data.h" 41 #include "content/public/browser/child_process_data.h"
42 #include "content/public/browser/render_view_host.h"
43 #include "content/public/browser/site_instance.h"
39 #include "content/public/common/child_process_host.h" 44 #include "content/public/common/child_process_host.h"
40 #include "content/public/common/content_switches.h" 45 #include "content/public/common/content_switches.h"
41 #include "content/public/common/process_type.h" 46 #include "content/public/common/process_type.h"
42 #include "ipc/ipc_channel.h" 47 #include "ipc/ipc_channel.h"
43 #include "ipc/ipc_switches.h" 48 #include "ipc/ipc_switches.h"
44 #include "native_client/src/shared/imc/nacl_imc_c.h" 49 #include "native_client/src/shared/imc/nacl_imc_c.h"
45 #include "net/base/net_util.h" 50 #include "net/base/net_util.h"
46 #include "net/socket/tcp_listen_socket.h" 51 #include "net/socket/tcp_listen_socket.h"
47 #include "ppapi/host/host_factory.h" 52 #include "ppapi/host/host_factory.h"
48 #include "ppapi/host/ppapi_host.h" 53 #include "ppapi/host/ppapi_host.h"
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 767 }
763 768
764 bool NaClProcessHost::SendStart() { 769 bool NaClProcessHost::SendStart() {
765 if (!enable_ppapi_proxy()) { 770 if (!enable_ppapi_proxy()) {
766 if (!ReplyToRenderer(IPC::ChannelHandle())) 771 if (!ReplyToRenderer(IPC::ChannelHandle()))
767 return false; 772 return false;
768 } 773 }
769 return StartNaClExecution(); 774 return StartNaClExecution();
770 } 775 }
771 776
777 class BrowserPpapiHostDelegate : public content::BrowserPpapiHost::Delegate {
778 virtual void OnIdleState(bool idle,
dmichael (off chromium) 2013/11/06 22:39:21 OnIdleStateChange? OnIdleStateTransition?
scheib 2013/11/15 01:22:17 Done: IdleStateChange
779 const base::FilePath& profile_data_directory,
780 const content::RenderViewHost* render_view_host,
781 const GURL& document_url) OVERRIDE {
782 DCHECK(render_view_host);
783 if (!render_view_host)
784 return;
785
786 content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
787 DCHECK(site_instance);
788 if (!site_instance)
789 return;
790
791 extensions::ExtensionSystem* extension_system =
792 extensions::ExtensionSystem::GetForBrowserContext(
793 site_instance->GetBrowserContext());
794 DCHECK(extension_system);
795 if (!extension_system)
796 return;
797
798 const ExtensionService* extension_service =
799 extension_system->extension_service();
800 DCHECK(extension_service);
801 if (!extension_service)
802 return;
803
804 const extensions::Extension* extension =
805 extension_service->GetExtensionById(document_url.host(), false);
806 DCHECK(extension);
807 if (!extension)
808 return;
809
810 ExtensionProcessManager* pm = extension_system->process_manager();
811 DCHECK(pm);
812 if (!pm)
813 return;
814
815 if (idle) {
816 fprintf(stderr, "%s:%s:%d DecrementLazyKeepaliveCount\n", __FILE__, __FUNC TION__, __LINE__);
817 pm->DecrementLazyKeepaliveCount(extension);
818 } else {
819 fprintf(stderr, "%s:%s:%d IncrementLazyKeepaliveCount\n", __FILE__, __FUNC TION__, __LINE__);
820 pm->IncrementLazyKeepaliveCount(extension);
821 }
822 }
823 };
dmichael (off chromium) 2013/11/06 22:39:21 This should probably go up in the unnamed namespac
scheib 2013/11/15 01:22:17 Done.
824
772 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is 825 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is
773 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin 826 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin
774 // listener. 827 // listener.
775 void NaClProcessHost::OnPpapiChannelCreated( 828 void NaClProcessHost::OnPpapiChannelCreated(
776 const IPC::ChannelHandle& channel_handle) { 829 const IPC::ChannelHandle& channel_handle) {
777 // Only renderer processes should create a channel. 830 // Only renderer processes should create a channel.
778 DCHECK(enable_ppapi_proxy()); 831 DCHECK(enable_ppapi_proxy());
779 // If the proxy channel is null, this must be the initial NaCl-Browser IPC 832 // If the proxy channel is null, this must be the initial NaCl-Browser IPC
780 // channel. 833 // channel.
781 if (!ipc_proxy_channel_.get()) { 834 if (!ipc_proxy_channel_.get()) {
782 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); 835 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type);
783 836
784 ipc_proxy_channel_.reset( 837 ipc_proxy_channel_.reset(
785 new IPC::ChannelProxy(channel_handle, 838 new IPC::ChannelProxy(channel_handle,
786 IPC::Channel::MODE_CLIENT, 839 IPC::Channel::MODE_CLIENT,
787 &ipc_plugin_listener_, 840 &ipc_plugin_listener_,
788 base::MessageLoopProxy::current().get())); 841 base::MessageLoopProxy::current().get()));
789 // Create the browser ppapi host and enable PPAPI message dispatching to the 842 // Create the browser ppapi host and enable PPAPI message dispatching to the
790 // browser process. 843 // browser process.
791 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( 844 ppapi_host_ = content::BrowserPpapiHost::CreateExternalPluginProcess(
845 new BrowserPpapiHostDelegate(),
792 ipc_proxy_channel_.get(), // sender 846 ipc_proxy_channel_.get(), // sender
793 permissions_, 847 permissions_,
794 process_->GetData().handle, 848 process_->GetData().handle,
795 ipc_proxy_channel_.get(), 849 ipc_proxy_channel_.get(),
796 nacl_host_message_filter_->render_process_id(), 850 nacl_host_message_filter_->render_process_id(),
797 render_view_id_, 851 render_view_id_,
798 profile_directory_)); 852 profile_directory_);
799 853
800 ppapi::PpapiNaClChannelArgs args; 854 ppapi::PpapiNaClChannelArgs args;
801 args.off_the_record = nacl_host_message_filter_->off_the_record(); 855 args.off_the_record = nacl_host_message_filter_->off_the_record();
802 args.permissions = permissions_; 856 args.permissions = permissions_;
803 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 857 CommandLine* cmdline = CommandLine::ForCurrentProcess();
804 DCHECK(cmdline); 858 DCHECK(cmdline);
805 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; 859 std::string flag_whitelist[] = {switches::kV, switches::kVModule};
806 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { 860 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) {
807 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); 861 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]);
808 if (!value.empty()) { 862 if (!value.empty()) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 } else { 1068 } else {
1015 NaClStartDebugExceptionHandlerThread( 1069 NaClStartDebugExceptionHandlerThread(
1016 process_handle.Take(), info, 1070 process_handle.Take(), info,
1017 base::MessageLoopProxy::current(), 1071 base::MessageLoopProxy::current(),
1018 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1072 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1019 weak_factory_.GetWeakPtr())); 1073 weak_factory_.GetWeakPtr()));
1020 return true; 1074 return true;
1021 } 1075 }
1022 } 1076 }
1023 #endif 1077 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698