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

Side by Side Diff: chrome/browser/nacl_host/nacl_browser_delegate_impl.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: rebase Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_browser_delegate_impl.h" 5 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" 11 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" 14 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h"
15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" 16 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h"
15 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_paths_internal.h" 18 #include "chrome/common/chrome_paths_internal.h"
17 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/logging_chrome.h" 20 #include "chrome/common/logging_chrome.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/site_instance.h"
20 #include "extensions/browser/info_map.h" 24 #include "extensions/browser/info_map.h"
25 #include "extensions/browser/process_manager.h"
21 #include "extensions/common/constants.h" 26 #include "extensions/common/constants.h"
22 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
23 #include "extensions/common/manifest_handlers/shared_module_info.h" 28 #include "extensions/common/manifest_handlers/shared_module_info.h"
24 #include "extensions/common/url_pattern.h" 29 #include "extensions/common/url_pattern.h"
25 #include "ppapi/c/private/ppb_nacl_private.h" 30 #include "ppapi/c/private/ppb_nacl_private.h"
26 31
27 using extensions::SharedModuleInfo; 32 using extensions::SharedModuleInfo;
28 33
34 namespace {
35
36 // Handles an extension's NaCl process transitioning in or out of idle state by
37 // relaying the state to the extension's process manager.
38 //
39 // A NaCl instance, when active, sends keepalive IPCs to the browser process
40 // BrowserPpapiHost at a trottled rate. The content::BrowserPpapiHost passes
Mark Seaborn 2013/12/16 22:40:46 Typo: "throttled". Could you emphasise here that
scheib 2013/12/16 23:13:44 Done. "throttled". Bugged: https://code.google.com
Mark Seaborn 2013/12/18 09:11:43 Oh, I think I misread "active" in the comment as a
41 // context information up to the chrome level NaClProcessHost where we use the
42 // instance's context to find the associated extension process manager.
43 //
44 // There is 1:many relationship for extension:nacl-embeds, but only a
dmichael (off chromium) 2013/12/16 22:17:54 nit: "is +a+ 1:many"
scheib 2013/12/16 23:13:44 Done.
45 // 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't
46 // rely on this knowledge because it routes messages for ppapi non-nacl
47 // instances as well, though they won't have callbacks set. Here the 1:1
48 // assumption is made and DCHECKed.
49 void OnKeepaliveOnUIThread(
50 const content::BrowserPpapiHost::OnKeepaliveInstanceData& intance_data,
Mark Seaborn 2013/12/16 22:40:46 "instance_data"
scheib 2013/12/16 23:13:44 Done.
51 const base::FilePath& profile_data_directory) {
52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
53
54 // Only one instance will exist for NaCl embeds, even when more than one
55 // embed of the same plugin exists on the same page.
56 DCHECK(intance_data.size() == 1);
57 if (intance_data.size() < 1)
58 return;
59
60 content::RenderViewHost* render_view_host = content::RenderViewHost::FromID(
61 intance_data[0].render_process_id, intance_data[0].render_view_id);
62 if (!render_view_host)
63 return;
64
65 content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
66 if (!site_instance)
67 return;
68
69 extensions::ExtensionSystem* extension_system =
70 extensions::ExtensionSystem::GetForBrowserContext(
71 site_instance->GetBrowserContext());
72 if (!extension_system)
73 return;
74
75 const ExtensionService* extension_service =
76 extension_system->extension_service();
77 if (!extension_service)
78 return;
79
80 const extensions::Extension* extension = extension_service->GetExtensionById(
81 intance_data[0].document_url.host(), false);
82 if (!extension)
83 return;
84
85 extensions::ProcessManager* pm = extension_system->process_manager();
86 if (!pm)
87 return;
88
89 pm->KeepaliveImpulse(extension);
90 }
91
92 // Calls OnKeepaliveOnUIThread on UI thread.
93 void OnKeepalive(
94 const content::BrowserPpapiHost::OnKeepaliveInstanceData& intance_data,
Mark Seaborn 2013/12/16 22:40:46 "instance_data"
scheib 2013/12/16 23:13:44 Done.
95 const base::FilePath& profile_data_directory) {
96 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
97 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
98 base::Bind(&OnKeepaliveOnUIThread,
99 intance_data,
100 profile_data_directory));
101 }
102
103 } // namespace
104
29 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( 105 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl(
30 extensions::InfoMap* extension_info_map) 106 extensions::InfoMap* extension_info_map)
31 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} 107 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {}
32 108
33 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { 109 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() {
34 } 110 }
35 111
36 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id, 112 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id,
37 int render_view_id, 113 int render_view_id,
38 int error_id) { 114 int error_id) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return false; 250 return false;
175 251
176 // GetFilePath is a blocking function call. 252 // GetFilePath is a blocking function call.
177 const base::FilePath resource_file_path = resource.GetFilePath(); 253 const base::FilePath resource_file_path = resource.GetFilePath();
178 if (resource_file_path.empty()) 254 if (resource_file_path.empty())
179 return false; 255 return false;
180 256
181 *file_path = resource_file_path; 257 *file_path = resource_file_path;
182 return true; 258 return true;
183 } 259 }
260
261 content::BrowserPpapiHost::OnKeepaliveCallback
262 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() {
263 return base::Bind(&OnKeepalive);
264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698