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

Side by Side Diff: content/browser/plugin_loader_posix.cc

Issue 128773002: Restart plugin loading only if the plugin list has actually become stale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: x Created 6 years, 11 months 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 "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/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/metrics/user_metrics.h" 11 #include "base/metrics/user_metrics.h"
12 #include "content/browser/utility_process_host_impl.h" 12 #include "content/browser/utility_process_host_impl.h"
13 #include "content/common/child_process_host_impl.h" 13 #include "content/common/child_process_host_impl.h"
14 #include "content/common/plugin_list.h" 14 #include "content/common/plugin_list.h"
15 #include "content/common/utility_messages.h" 15 #include "content/common/utility_messages.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/plugin_service.h" 17 #include "content/public/browser/plugin_service.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 PluginLoaderPosix::PluginLoaderPosix() 21 PluginLoaderPosix::PluginLoaderPosix()
22 : next_load_index_(0) { 22 : next_load_index_(0) {
23 } 23 }
24 24
25 void PluginLoaderPosix::LoadPlugins( 25 void PluginLoaderPosix::GetPlugins(
26 scoped_refptr<base::MessageLoopProxy> target_loop,
27 const PluginService::GetPluginsCallback& callback) { 26 const PluginService::GetPluginsCallback& callback) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
29 28
30 callbacks_.push_back(PendingCallback(target_loop, callback)); 29 std::vector<WebPluginInfo> cached_plugins;
30 if (PluginList::Singleton()->GetPluginsNoRefresh(&cached_plugins)) {
31 // Can't assume the caller is reentrant.
32 base::MessageLoop::current()->PostTask(FROM_HERE,
33 base::Bind(callback, cached_plugins));
34 return;
35 }
31 36
32 if (callbacks_.size() == 1) { 37 if (callbacks_.empty()) {
33 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 38 callbacks_.push_back(callback);
34 base::Bind(&PluginLoaderPosix::GetPluginsToLoad, this)); 39
40 PluginList::Singleton()->PrepareForPluginLoading();
Robert Sesek 2014/01/21 15:17:22 Why can't this just be RefreshPlugins?
Bernhard Bauer 2014/01/21 15:48:25 RefreshPlugins() marks the plugin list as invalida
41
42 BrowserThread::PostTask(BrowserThread::FILE,
43 FROM_HERE,
44 base::Bind(&PluginLoaderPosix::GetPluginsToLoad,
45 make_scoped_refptr(this)));
46 } else {
47 // If we are currently loading plugins, the plugin list might have been
48 // invalidated in the mean time, or might get invalidated before we finish.
49 // We'll wait until we have finished the current run, then try to get them
50 // again from the plugin list. If it has indeed been invalidated, it will
51 // restart plugin loading, otherwise it will immediately run the callback.
52 callbacks_.push_back(base::Bind(&PluginLoaderPosix::GetPluginsWrapper,
53 make_scoped_refptr(this), callback));
35 } 54 }
36 } 55 }
37 56
38 bool PluginLoaderPosix::OnMessageReceived(const IPC::Message& message) { 57 bool PluginLoaderPosix::OnMessageReceived(const IPC::Message& message) {
39 bool handled = true; 58 bool handled = true;
40 IPC_BEGIN_MESSAGE_MAP(PluginLoaderPosix, message) 59 IPC_BEGIN_MESSAGE_MAP(PluginLoaderPosix, message)
41 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugin, OnPluginLoaded) 60 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugin, OnPluginLoaded)
42 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadPluginFailed, OnPluginLoadFailed) 61 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadPluginFailed, OnPluginLoadFailed)
43 IPC_MESSAGE_UNHANDLED(handled = false) 62 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP() 63 IPC_END_MESSAGE_MAP()
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get()); 134 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get());
116 process_host_ = host->AsWeakPtr(); 135 process_host_ = host->AsWeakPtr();
117 process_host_->DisableSandbox(); 136 process_host_->DisableSandbox();
118 #if defined(OS_MACOSX) 137 #if defined(OS_MACOSX)
119 host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); 138 host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
120 #endif 139 #endif
121 140
122 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_)); 141 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_));
123 } 142 }
124 143
144 void PluginLoaderPosix::GetPluginsWrapper(
145 const PluginService::GetPluginsCallback& callback,
146 const std::vector<WebPluginInfo>& /* plugins */) {
147 // We are being called after plugin loading has finished, but we don't know
148 // whether the plugin list has been invalidated in the mean time
149 // (and therefore |plugins| might already be stale). So we simply ignore it
150 // and call regular GetPlugins() instead.
151 GetPlugins(callback);
152 }
153
125 void PluginLoaderPosix::OnPluginLoaded(uint32 index, 154 void PluginLoaderPosix::OnPluginLoaded(uint32 index,
126 const WebPluginInfo& plugin) { 155 const WebPluginInfo& plugin) {
127 if (index != next_load_index_) { 156 if (index != next_load_index_) {
128 LOG(ERROR) << "Received unexpected plugin load message for " 157 LOG(ERROR) << "Received unexpected plugin load message for "
129 << plugin.path.value() << "; index=" << index; 158 << plugin.path.value() << "; index=" << index;
130 return; 159 return;
131 } 160 }
132 161
133 if (!MaybeAddInternalPlugin(plugin.path)) 162 if (!MaybeAddInternalPlugin(plugin.path))
134 loaded_plugins_.push_back(plugin); 163 loaded_plugins_.push_back(plugin);
(...skipping 30 matching lines...) Expand all
165 } 194 }
166 return false; 195 return false;
167 } 196 }
168 197
169 bool PluginLoaderPosix::MaybeRunPendingCallbacks() { 198 bool PluginLoaderPosix::MaybeRunPendingCallbacks() {
170 if (next_load_index_ < canonical_list_.size()) 199 if (next_load_index_ < canonical_list_.size())
171 return false; 200 return false;
172 201
173 PluginList::Singleton()->SetPlugins(loaded_plugins_); 202 PluginList::Singleton()->SetPlugins(loaded_plugins_);
174 203
175 // Only call the first callback with loaded plugins because there may be 204 for (std::vector<PluginService::GetPluginsCallback>::iterator it =
176 // some extra plugin paths added since the first callback is added. 205 callbacks_.begin();
177 if (!callbacks_.empty()) { 206 it != callbacks_.end(); ++it) {
178 PendingCallback callback = callbacks_.front(); 207 base::MessageLoop::current()->PostTask(FROM_HERE,
179 callbacks_.pop_front(); 208 base::Bind(*it, loaded_plugins_));
180 callback.target_loop->PostTask(
181 FROM_HERE,
182 base::Bind(callback.callback, loaded_plugins_));
183 } 209 }
210 callbacks_.clear();
184 211
185 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone", 212 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone",
186 (base::TimeTicks::Now() - load_start_time_) 213 (base::TimeTicks::Now() - load_start_time_)
187 * base::Time::kMicrosecondsPerMillisecond); 214 * base::Time::kMicrosecondsPerMillisecond);
188 load_start_time_ = base::TimeTicks(); 215 load_start_time_ = base::TimeTicks();
189 216
190 if (!callbacks_.empty()) {
191 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
192 base::Bind(&PluginLoaderPosix::GetPluginsToLoad, this));
193 return false;
194 }
195 return true; 217 return true;
196 } 218 }
197 219
198 PluginLoaderPosix::PendingCallback::PendingCallback(
199 scoped_refptr<base::MessageLoopProxy> loop,
200 const PluginService::GetPluginsCallback& cb)
201 : target_loop(loop),
202 callback(cb) {
203 }
204
205 PluginLoaderPosix::PendingCallback::~PendingCallback() {
206 }
207
208 } // namespace content 220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698