| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_loader_posix.h" | 5 #include "content/browser/plugin_loader_posix.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "content/common/child_process_host_impl.h" | 11 #include "content/common/child_process_host_impl.h" |
| 12 #include "content/common/utility_messages.h" | 12 #include "content/common/utility_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "webkit/plugins/npapi/plugin_list.h" | 14 #include "webkit/plugins/npapi/plugin_list.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 using content::ChildProcessHost; | 17 using content::ChildProcessHost; |
| 18 | 18 |
| 19 PluginLoaderPosix::PluginLoaderPosix() | 19 PluginLoaderPosix::PluginLoaderPosix() |
| 20 : process_host_(NULL), | 20 : next_load_index_(0) { |
| 21 next_load_index_(0) { | |
| 22 } | 21 } |
| 23 | 22 |
| 24 void PluginLoaderPosix::LoadPlugins( | 23 void PluginLoaderPosix::LoadPlugins( |
| 25 scoped_refptr<base::MessageLoopProxy> target_loop, | 24 scoped_refptr<base::MessageLoopProxy> target_loop, |
| 26 const content::PluginService::GetPluginsCallback& callback) { | 25 const content::PluginService::GetPluginsCallback& callback) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 | 27 |
| 29 callbacks_.push_back(PendingCallback(target_loop, callback)); | 28 callbacks_.push_back(PendingCallback(target_loop, callback)); |
| 30 | 29 |
| 31 if (callbacks_.size() == 1) { | 30 if (callbacks_.size() == 1) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 | 45 |
| 47 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { | 46 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { |
| 48 canonical_list_.erase(canonical_list_.begin(), | 47 canonical_list_.erase(canonical_list_.begin(), |
| 49 canonical_list_.begin() + next_load_index_ + 1); | 48 canonical_list_.begin() + next_load_index_ + 1); |
| 50 next_load_index_ = 0; | 49 next_load_index_ = 0; |
| 51 | 50 |
| 52 LoadPluginsInternal(); | 51 LoadPluginsInternal(); |
| 53 } | 52 } |
| 54 | 53 |
| 55 bool PluginLoaderPosix::Send(IPC::Message* message) { | 54 bool PluginLoaderPosix::Send(IPC::Message* message) { |
| 56 return process_host_->Send(message); | 55 if (process_host_) |
| 56 return process_host_->Send(message); |
| 57 return false; |
| 57 } | 58 } |
| 58 | 59 |
| 59 PluginLoaderPosix::~PluginLoaderPosix() { | 60 PluginLoaderPosix::~PluginLoaderPosix() { |
| 60 } | 61 } |
| 61 | 62 |
| 62 void PluginLoaderPosix::GetPluginsToLoad() { | 63 void PluginLoaderPosix::GetPluginsToLoad() { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 64 | 65 |
| 65 base::TimeTicks start_time(base::TimeTicks::Now()); | 66 base::TimeTicks start_time(base::TimeTicks::Now()); |
| 66 | 67 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 89 | 90 |
| 90 // Check if the list is empty or all plugins have already been loaded before | 91 // Check if the list is empty or all plugins have already been loaded before |
| 91 // forking. | 92 // forking. |
| 92 if (MaybeRunPendingCallbacks()) | 93 if (MaybeRunPendingCallbacks()) |
| 93 return; | 94 return; |
| 94 | 95 |
| 95 if (load_start_time_.is_null()) | 96 if (load_start_time_.is_null()) |
| 96 load_start_time_ = base::TimeTicks::Now(); | 97 load_start_time_ = base::TimeTicks::Now(); |
| 97 | 98 |
| 98 process_host_ = new UtilityProcessHost(this, BrowserThread::IO); | 99 process_host_ = |
| 100 (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr(); |
| 99 process_host_->set_no_sandbox(true); | 101 process_host_->set_no_sandbox(true); |
| 100 #if defined(OS_MACOSX) | 102 #if defined(OS_MACOSX) |
| 101 process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); | 103 process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); |
| 102 #endif | 104 #endif |
| 103 | 105 |
| 104 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_)); | 106 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_)); |
| 105 } | 107 } |
| 106 | 108 |
| 107 void PluginLoaderPosix::OnPluginLoaded(uint32 index, | 109 void PluginLoaderPosix::OnPluginLoaded(uint32 index, |
| 108 const webkit::WebPluginInfo& plugin) { | 110 const webkit::WebPluginInfo& plugin) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 174 |
| 173 PluginLoaderPosix::PendingCallback::PendingCallback( | 175 PluginLoaderPosix::PendingCallback::PendingCallback( |
| 174 scoped_refptr<base::MessageLoopProxy> loop, | 176 scoped_refptr<base::MessageLoopProxy> loop, |
| 175 const content::PluginService::GetPluginsCallback& cb) | 177 const content::PluginService::GetPluginsCallback& cb) |
| 176 : target_loop(loop), | 178 : target_loop(loop), |
| 177 callback(cb) { | 179 callback(cb) { |
| 178 } | 180 } |
| 179 | 181 |
| 180 PluginLoaderPosix::PendingCallback::~PendingCallback() { | 182 PluginLoaderPosix::PendingCallback::~PendingCallback() { |
| 181 } | 183 } |
| OLD | NEW |