OLD | NEW |
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 "content/browser/plugin_service_impl.h" | 5 #include "content/browser/plugin_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
20 #include "build/build_config.h" | 22 #include "build/build_config.h" |
21 #include "content/browser/ppapi_plugin_process_host.h" | 23 #include "content/browser/ppapi_plugin_process_host.h" |
22 #include "content/browser/renderer_host/render_process_host_impl.h" | 24 #include "content/browser/renderer_host/render_process_host_impl.h" |
23 #include "content/browser/renderer_host/render_view_host_impl.h" | 25 #include "content/browser/renderer_host/render_view_host_impl.h" |
24 #include "content/common/content_switches_internal.h" | 26 #include "content/common/content_switches_internal.h" |
25 #include "content/common/pepper_plugin_list.h" | 27 #include "content/common/pepper_plugin_list.h" |
26 #include "content/common/plugin_list.h" | 28 #include "content/common/plugin_list.h" |
27 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
28 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
(...skipping 13 matching lines...) Expand all Loading... |
42 // Number of browser processes that have started at least one PPAPI Flash | 44 // Number of browser processes that have started at least one PPAPI Flash |
43 // process during their lifetime. | 45 // process during their lifetime. |
44 START_PPAPI_FLASH_AT_LEAST_ONCE = 1, | 46 START_PPAPI_FLASH_AT_LEAST_ONCE = 1, |
45 // Total number of browser processes. | 47 // Total number of browser processes. |
46 TOTAL_BROWSER_PROCESSES, | 48 TOTAL_BROWSER_PROCESSES, |
47 FLASH_USAGE_ENUM_COUNT | 49 FLASH_USAGE_ENUM_COUNT |
48 }; | 50 }; |
49 | 51 |
50 // Callback set on the PluginList to assert that plugin loading happens on the | 52 // Callback set on the PluginList to assert that plugin loading happens on the |
51 // correct thread. | 53 // correct thread. |
52 void WillLoadPluginsCallback( | 54 void WillLoadPluginsCallback(base::SequenceChecker* sequence_checker) { |
53 base::SequencedWorkerPool::SequenceToken token) { | 55 DCHECK(sequence_checker->CalledOnValidSequence()); |
54 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | |
55 token)); | |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 // static | 60 // static |
61 PluginService* PluginService::GetInstance() { | 61 PluginService* PluginService::GetInstance() { |
62 return PluginServiceImpl::GetInstance(); | 62 return PluginServiceImpl::GetInstance(); |
63 } | 63 } |
64 | 64 |
65 void PluginService::PurgePluginListCache(BrowserContext* browser_context, | 65 void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
66 bool reload_pages) { | 66 bool reload_pages) { |
67 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 67 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
68 !it.IsAtEnd(); it.Advance()) { | 68 !it.IsAtEnd(); it.Advance()) { |
69 RenderProcessHost* host = it.GetCurrentValue(); | 69 RenderProcessHost* host = it.GetCurrentValue(); |
70 if (!browser_context || host->GetBrowserContext() == browser_context) | 70 if (!browser_context || host->GetBrowserContext() == browser_context) |
71 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); | 71 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // static | 75 // static |
76 PluginServiceImpl* PluginServiceImpl::GetInstance() { | 76 PluginServiceImpl* PluginServiceImpl::GetInstance() { |
77 return base::Singleton<PluginServiceImpl>::get(); | 77 return base::Singleton<PluginServiceImpl>::get(); |
78 } | 78 } |
79 | 79 |
80 PluginServiceImpl::PluginServiceImpl() | 80 PluginServiceImpl::PluginServiceImpl() |
81 : filter_(NULL) { | 81 : filter_(NULL) { |
| 82 plugin_list_sequence_checker_.DetachFromSequence(); |
| 83 |
82 // Collect the total number of browser processes (which create | 84 // Collect the total number of browser processes (which create |
83 // PluginServiceImpl objects, to be precise). The number is used to normalize | 85 // PluginServiceImpl objects, to be precise). The number is used to normalize |
84 // the number of processes which start at least one NPAPI/PPAPI Flash process. | 86 // the number of processes which start at least one NPAPI/PPAPI Flash process. |
85 static bool counted = false; | 87 static bool counted = false; |
86 if (!counted) { | 88 if (!counted) { |
87 counted = true; | 89 counted = true; |
88 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, | 90 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
89 FLASH_USAGE_ENUM_COUNT); | 91 FLASH_USAGE_ENUM_COUNT); |
90 } | 92 } |
91 } | 93 } |
92 | 94 |
93 PluginServiceImpl::~PluginServiceImpl() { | 95 PluginServiceImpl::~PluginServiceImpl() { |
94 } | 96 } |
95 | 97 |
96 void PluginServiceImpl::Init() { | 98 void PluginServiceImpl::Init() { |
97 plugin_list_token_ = base::SequencedWorkerPool::GetSequenceToken(); | 99 plugin_list_task_runner_ = |
| 100 BrowserThread::GetBlockingPool() |
| 101 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 102 base::SequencedWorkerPool::GetSequenceToken(), |
| 103 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
98 PluginList::Singleton()->set_will_load_plugins_callback( | 104 PluginList::Singleton()->set_will_load_plugins_callback( |
99 base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); | 105 base::Bind(&WillLoadPluginsCallback, &plugin_list_sequence_checker_)); |
100 | 106 |
101 RegisterPepperPlugins(); | 107 RegisterPepperPlugins(); |
102 } | 108 } |
103 | 109 |
104 PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( | 110 PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
105 const base::FilePath& plugin_path, | 111 const base::FilePath& plugin_path, |
106 const base::FilePath& profile_data_directory) { | 112 const base::FilePath& profile_data_directory) { |
107 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { | 113 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { |
108 if (iter->plugin_path() == plugin_path && | 114 if (iter->plugin_path() == plugin_path && |
109 iter->profile_data_directory() == profile_data_directory) { | 115 iter->profile_data_directory() == profile_data_directory) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 plugin_name.erase(plugin_name.length() - kPluginExtension.length()); | 304 plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
299 #endif // OS_MACOSX | 305 #endif // OS_MACOSX |
300 } | 306 } |
301 return plugin_name; | 307 return plugin_name; |
302 } | 308 } |
303 | 309 |
304 void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { | 310 void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
305 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner( | 311 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner( |
306 base::ThreadTaskRunnerHandle::Get()); | 312 base::ThreadTaskRunnerHandle::Get()); |
307 | 313 |
308 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 314 plugin_list_task_runner_->PostTask( |
309 plugin_list_token_, FROM_HERE, | 315 FROM_HERE, |
310 base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this), | 316 base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this), |
311 base::RetainedRef(target_task_runner), callback), | 317 base::RetainedRef(target_task_runner), callback)); |
312 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
313 } | 318 } |
314 | 319 |
315 void PluginServiceImpl::GetPluginsInternal( | 320 void PluginServiceImpl::GetPluginsInternal( |
316 base::SingleThreadTaskRunner* target_task_runner, | 321 base::SingleThreadTaskRunner* target_task_runner, |
317 const PluginService::GetPluginsCallback& callback) { | 322 const PluginService::GetPluginsCallback& callback) { |
318 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 323 DCHECK(plugin_list_sequence_checker_.CalledOnValidSequence()); |
319 plugin_list_token_)); | |
320 | 324 |
321 std::vector<WebPluginInfo> plugins; | 325 std::vector<WebPluginInfo> plugins; |
322 PluginList::Singleton()->GetPlugins(&plugins); | 326 PluginList::Singleton()->GetPlugins(&plugins); |
323 | 327 |
324 target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins)); | 328 target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins)); |
325 } | 329 } |
326 | 330 |
327 void PluginServiceImpl::RegisterPepperPlugins() { | 331 void PluginServiceImpl::RegisterPepperPlugins() { |
328 ComputePepperPluginList(&ppapi_plugins_); | 332 ComputePepperPluginList(&ppapi_plugins_); |
329 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { | 333 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 417 } |
414 | 418 |
415 bool PluginServiceImpl::PpapiDevChannelSupported( | 419 bool PluginServiceImpl::PpapiDevChannelSupported( |
416 BrowserContext* browser_context, | 420 BrowserContext* browser_context, |
417 const GURL& document_url) { | 421 const GURL& document_url) { |
418 return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( | 422 return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
419 browser_context, document_url); | 423 browser_context, document_url); |
420 } | 424 } |
421 | 425 |
422 } // namespace content | 426 } // namespace content |
OLD | NEW |