OLD | NEW |
---|---|
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/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" | 21 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
20 #include "chrome/common/logging_chrome.h" | 22 #include "chrome/common/logging_chrome.h" |
21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/render_view_host.h" | |
25 #include "content/public/browser/site_instance.h" | |
22 #include "extensions/browser/info_map.h" | 26 #include "extensions/browser/info_map.h" |
27 #include "extensions/browser/process_manager.h" | |
23 #include "extensions/common/constants.h" | 28 #include "extensions/common/constants.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 monitors its activity and sends an IPC to the browser | |
40 // process BrowserPpapiHost upon transitioning in our out of idleness. The | |
yzshen1
2013/11/21 18:01:50
our -> or
scheib
2013/12/11 21:35:40
Done.
| |
41 // content::BrowserPpapiHost passes context information up to the chrome level | |
42 // NaClProcessHost where we use the instance's context to find the associated | |
43 // extension process manager. | |
44 // | |
45 // There is 1:many relationship for extension:nacl-embeds, but only a | |
46 // 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't | |
47 // rely on this knowledge because it routes messages for ppapi non-nacl | |
48 // instances as well, though they won't have callbacks set. Here the 1:1 | |
49 // assumption is made and DCHECKed. | |
50 void OnIdleStateChangeOnUIThread( | |
51 content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, | |
yzshen1
2013/11/21 18:01:50
This whole vector is copied quite a few times:
wh
scheib
2013/12/11 21:35:40
Done. Parameters changed to all const references.
yzshen1
2013/12/13 21:23:15
Right.
Thanks for the nice document!
| |
52 const base::FilePath profile_data_directory, | |
yzshen1
2013/11/21 18:01:50
const &, please.
scheib
2013/12/11 21:35:40
Done.
scheib
2013/12/11 21:35:40
Done.
| |
53 bool idle) { | |
54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
55 | |
56 // Only one instance will exist for NaCl embeds, even when more than one | |
57 // embed of the same plugin exists on the same page. | |
58 DCHECK(intance_data.size() == 1); | |
59 if (intance_data.size() < 1) | |
60 return; | |
61 | |
62 content::RenderViewHost* render_view_host = content::RenderViewHost::FromID( | |
63 intance_data[0].render_process_id, intance_data[0].render_view_id); | |
64 DCHECK(render_view_host); | |
65 if (!render_view_host) | |
66 return; | |
67 | |
68 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); | |
69 DCHECK(site_instance); | |
70 if (!site_instance) | |
71 return; | |
72 | |
73 extensions::ExtensionSystem* extension_system = | |
74 extensions::ExtensionSystem::GetForBrowserContext( | |
75 site_instance->GetBrowserContext()); | |
76 DCHECK(extension_system); | |
77 if (!extension_system) | |
78 return; | |
79 | |
80 const ExtensionService* extension_service = | |
81 extension_system->extension_service(); | |
82 DCHECK(extension_service); | |
83 if (!extension_service) | |
84 return; | |
85 | |
86 const extensions::Extension* extension = extension_service->GetExtensionById( | |
87 intance_data[0].document_url.host(), false); | |
88 if (!extension) | |
89 return; | |
90 | |
91 extensions::ProcessManager* pm = extension_system->process_manager(); | |
92 DCHECK(pm); | |
93 if (!pm) | |
94 return; | |
95 | |
96 if (idle) { | |
97 fprintf(stderr, "%s:%s:%d DecrementLazyKeepaliveCount\n", | |
yzshen1
2013/11/21 18:01:50
Is this intended to be in the production code?
scheib
2013/12/11 21:35:40
No, this patch was still Work In Progress soliciti
| |
98 __FILE__, __FUNCTION__, __LINE__); | |
99 pm->DecrementLazyKeepaliveCount(extension); | |
yzshen1
2013/11/21 18:01:50
If the plugin is destroyed while the last call is
scheib
2013/12/11 21:35:40
No longer an issue as the design has changed. Now
| |
100 } else { | |
101 fprintf(stderr, "%s:%s:%d IncrementLazyKeepaliveCount\n", | |
yzshen1
2013/11/21 18:01:50
Is this debugging code that should be removed?
scheib
2013/12/11 21:35:40
Done.
| |
102 __FILE__, __FUNCTION__, __LINE__); | |
103 pm->IncrementLazyKeepaliveCount(extension); | |
104 } | |
105 } | |
106 | |
107 // Calls OnIdleStateChangeOnUIThread on UI thread. | |
108 void OnIdleStateChange( | |
109 content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, | |
110 const base::FilePath profile_data_directory, | |
111 bool idle) { | |
112 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
113 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
114 base::Bind(&OnIdleStateChangeOnUIThread, | |
115 intance_data, | |
116 profile_data_directory, | |
117 idle)); | |
118 } | |
119 | |
120 } // namespace | |
121 | |
29 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( | 122 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( |
30 extensions::InfoMap* extension_info_map) | 123 extensions::InfoMap* extension_info_map) |
31 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} | 124 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} |
32 | 125 |
33 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { | 126 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { |
34 } | 127 } |
35 | 128 |
36 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id, | 129 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id, |
37 int render_view_id, | 130 int render_view_id, |
38 int error_id) { | 131 int error_id) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return false; | 267 return false; |
175 | 268 |
176 // GetFilePath is a blocking function call. | 269 // GetFilePath is a blocking function call. |
177 const base::FilePath resource_file_path = resource.GetFilePath(); | 270 const base::FilePath resource_file_path = resource.GetFilePath(); |
178 if (resource_file_path.empty()) | 271 if (resource_file_path.empty()) |
179 return false; | 272 return false; |
180 | 273 |
181 *file_path = resource_file_path; | 274 *file_path = resource_file_path; |
182 return true; | 275 return true; |
183 } | 276 } |
277 | |
278 const content::BrowserPpapiHost::OnIdleChangeCallback | |
279 NaClBrowserDelegateImpl::GetOnIdleChangeCallback() { | |
280 return base::Bind(&OnIdleStateChange); | |
281 } | |
OLD | NEW |