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/common/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 } | 166 } |
167 | 167 |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 PluginList::PluginList() | 171 PluginList::PluginList() |
172 : loading_state_(LOADING_STATE_NEEDS_REFRESH), | 172 : loading_state_(LOADING_STATE_NEEDS_REFRESH), |
173 plugins_discovery_disabled_(false) { | 173 plugins_discovery_disabled_(false) { |
174 } | 174 } |
175 | 175 |
176 bool PluginList::PrepareForPluginLoading() { | |
177 base::AutoLock lock(lock_); | |
178 if (loading_state_ == LOADING_STATE_UP_TO_DATE) | |
Robert Sesek
2014/01/21 20:58:18
I think this is kind of a weird API; it maybe sets
Bernhard Bauer
2014/01/21 23:02:11
Well, what happens to the state internally is not
jam
2014/01/23 01:43:09
yes it's a bid odd to see this method that the cal
Bernhard Bauer
2014/01/23 17:35:31
LoadPlugins() does call this method internally. A
jam
2014/01/23 17:57:47
We don't need to support refreshing the plugins if
Bernhard Bauer
2014/01/23 18:17:46
Renderers aren't the only thing that can invalidat
| |
179 return false; | |
180 | |
181 loading_state_ = LOADING_STATE_REFRESHING; | |
182 return true; | |
183 } | |
184 | |
176 void PluginList::LoadPlugins(bool include_npapi) { | 185 void PluginList::LoadPlugins(bool include_npapi) { |
177 { | 186 if (!PrepareForPluginLoading()) |
178 base::AutoLock lock(lock_); | 187 return; |
179 if (loading_state_ == LOADING_STATE_UP_TO_DATE) | |
180 return; | |
181 | |
182 loading_state_ = LOADING_STATE_REFRESHING; | |
183 } | |
184 | 188 |
185 std::vector<WebPluginInfo> new_plugins; | 189 std::vector<WebPluginInfo> new_plugins; |
186 base::Closure will_load_callback; | 190 base::Closure will_load_callback; |
187 { | 191 { |
188 base::AutoLock lock(lock_); | 192 base::AutoLock lock(lock_); |
189 will_load_callback = will_load_plugins_callback_; | 193 will_load_callback = will_load_plugins_callback_; |
190 } | 194 } |
191 if (!will_load_callback.is_null()) | 195 if (!will_load_callback.is_null()) |
192 will_load_callback.Run(); | 196 will_load_callback.Run(); |
193 | 197 |
194 std::vector<base::FilePath> plugin_paths; | 198 std::vector<base::FilePath> plugin_paths; |
195 GetPluginPathsToLoad(&plugin_paths, include_npapi); | 199 GetPluginPathsToLoad(&plugin_paths, include_npapi); |
196 | 200 |
197 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); | 201 for (std::vector<base::FilePath>::const_iterator it = plugin_paths.begin(); |
198 it != plugin_paths.end(); | 202 it != plugin_paths.end(); |
199 ++it) { | 203 ++it) { |
200 WebPluginInfo plugin_info; | 204 WebPluginInfo plugin_info; |
201 LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); | 205 LoadPluginIntoPluginList(*it, &new_plugins, &plugin_info); |
202 } | 206 } |
203 | 207 |
204 base::AutoLock lock(lock_); | 208 SetPlugins(new_plugins); |
205 plugins_list_.swap(new_plugins); | |
206 | |
207 // If we haven't been invalidated in the mean time, mark the plug-in list as | |
208 // up-to-date. | |
209 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) | |
210 loading_state_ = LOADING_STATE_UP_TO_DATE; | |
211 } | 209 } |
212 | 210 |
213 bool PluginList::LoadPluginIntoPluginList( | 211 bool PluginList::LoadPluginIntoPluginList( |
214 const base::FilePath& path, | 212 const base::FilePath& path, |
215 std::vector<WebPluginInfo>* plugins, | 213 std::vector<WebPluginInfo>* plugins, |
216 WebPluginInfo* plugin_info) { | 214 WebPluginInfo* plugin_info) { |
217 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 215 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
218 << "Loading plugin " << path.value(); | 216 << "Loading plugin " << path.value(); |
219 if (!ReadPluginInfo(path, plugin_info)) | 217 if (!ReadPluginInfo(path, plugin_info)) |
220 return false; | 218 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 271 |
274 #if defined(OS_WIN) | 272 #if defined(OS_WIN) |
275 GetPluginPathsFromRegistry(plugin_paths); | 273 GetPluginPathsFromRegistry(plugin_paths); |
276 #endif | 274 #endif |
277 } | 275 } |
278 } | 276 } |
279 | 277 |
280 void PluginList::SetPlugins(const std::vector<WebPluginInfo>& plugins) { | 278 void PluginList::SetPlugins(const std::vector<WebPluginInfo>& plugins) { |
281 base::AutoLock lock(lock_); | 279 base::AutoLock lock(lock_); |
282 | 280 |
283 DCHECK_NE(LOADING_STATE_REFRESHING, loading_state_); | 281 // If we haven't been invalidated in the mean time, mark the plug-in list as |
284 loading_state_ = LOADING_STATE_UP_TO_DATE; | 282 // up-to-date. |
283 if (loading_state_ != LOADING_STATE_NEEDS_REFRESH) | |
284 loading_state_ = LOADING_STATE_UP_TO_DATE; | |
285 | 285 |
286 plugins_list_.clear(); | 286 plugins_list_ = plugins; |
287 plugins_list_.insert(plugins_list_.end(), plugins.begin(), plugins.end()); | |
288 } | 287 } |
289 | 288 |
290 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { | 289 void PluginList::set_will_load_plugins_callback(const base::Closure& callback) { |
291 base::AutoLock lock(lock_); | 290 base::AutoLock lock(lock_); |
292 will_load_plugins_callback_ = callback; | 291 will_load_plugins_callback_ = callback; |
293 } | 292 } |
294 | 293 |
295 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins, | 294 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins, |
296 bool include_npapi) { | 295 bool include_npapi) { |
297 LoadPlugins(include_npapi); | 296 LoadPlugins(include_npapi); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 plugin_path); | 405 plugin_path); |
407 if (it != extra_plugin_paths_.end()) | 406 if (it != extra_plugin_paths_.end()) |
408 extra_plugin_paths_.erase(it); | 407 extra_plugin_paths_.erase(it); |
409 } | 408 } |
410 | 409 |
411 PluginList::~PluginList() { | 410 PluginList::~PluginList() { |
412 } | 411 } |
413 | 412 |
414 | 413 |
415 } // namespace content | 414 } // namespace content |
OLD | NEW |