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/child/npapi/plugin_lib.h" | 5 #include "content/child/npapi/plugin_lib.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // instance function calls (i.e. NP_Initialize and NP_Shutdown). So we keep | 26 // instance function calls (i.e. NP_Initialize and NP_Shutdown). So we keep |
27 // a map of PluginLib objects. | 27 // a map of PluginLib objects. |
28 if (!g_loaded_libs) | 28 if (!g_loaded_libs) |
29 g_loaded_libs = new std::vector<scoped_refptr<PluginLib> >; | 29 g_loaded_libs = new std::vector<scoped_refptr<PluginLib> >; |
30 | 30 |
31 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { | 31 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { |
32 if ((*g_loaded_libs)[i]->plugin_info().path == filename) | 32 if ((*g_loaded_libs)[i]->plugin_info().path == filename) |
33 return (*g_loaded_libs)[i].get(); | 33 return (*g_loaded_libs)[i].get(); |
34 } | 34 } |
35 | 35 |
36 webkit::WebPluginInfo info; | 36 WebPluginInfo info; |
37 if (!PluginList::Singleton()->ReadPluginInfo(filename, &info)) | 37 if (!PluginList::Singleton()->ReadPluginInfo(filename, &info)) |
38 return NULL; | 38 return NULL; |
39 | 39 |
40 return new PluginLib(info); | 40 return new PluginLib(info); |
41 } | 41 } |
42 | 42 |
43 void PluginLib::UnloadAllPlugins() { | 43 void PluginLib::UnloadAllPlugins() { |
44 if (g_loaded_libs) { | 44 if (g_loaded_libs) { |
45 // PluginLib::Unload() can remove items from the list and even delete | 45 // PluginLib::Unload() can remove items from the list and even delete |
46 // the list when it removes the last item, so we must work with a copy | 46 // the list when it removes the last item, so we must work with a copy |
47 // of the list so that we don't get the carpet removed under our feet. | 47 // of the list so that we don't get the carpet removed under our feet. |
48 std::vector<scoped_refptr<PluginLib> > loaded_libs(*g_loaded_libs); | 48 std::vector<scoped_refptr<PluginLib> > loaded_libs(*g_loaded_libs); |
49 for (size_t i = 0; i < loaded_libs.size(); ++i) | 49 for (size_t i = 0; i < loaded_libs.size(); ++i) |
50 loaded_libs[i]->Unload(); | 50 loaded_libs[i]->Unload(); |
51 | 51 |
52 if (g_loaded_libs && g_loaded_libs->empty()) { | 52 if (g_loaded_libs && g_loaded_libs->empty()) { |
53 delete g_loaded_libs; | 53 delete g_loaded_libs; |
54 g_loaded_libs = NULL; | 54 g_loaded_libs = NULL; |
55 } | 55 } |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void PluginLib::ShutdownAllPlugins() { | 59 void PluginLib::ShutdownAllPlugins() { |
60 if (g_loaded_libs) { | 60 if (g_loaded_libs) { |
61 for (size_t i = 0; i < g_loaded_libs->size(); ++i) | 61 for (size_t i = 0; i < g_loaded_libs->size(); ++i) |
62 (*g_loaded_libs)[i]->Shutdown(); | 62 (*g_loaded_libs)[i]->Shutdown(); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 PluginLib::PluginLib(const webkit::WebPluginInfo& info) | 66 PluginLib::PluginLib(const WebPluginInfo& info) |
67 : web_plugin_info_(info), | 67 : web_plugin_info_(info), |
68 library_(NULL), | 68 library_(NULL), |
69 initialized_(false), | 69 initialized_(false), |
70 saved_data_(0), | 70 saved_data_(0), |
71 instance_count_(0), | 71 instance_count_(0), |
72 skip_unload_(false), | 72 skip_unload_(false), |
73 defer_unload_(false) { | 73 defer_unload_(false) { |
74 base::StatsCounter(kPluginLibrariesLoadedCounter).Increment(); | 74 base::StatsCounter(kPluginLibrariesLoadedCounter).Increment(); |
75 memset(static_cast<void*>(&plugin_funcs_), 0, sizeof(plugin_funcs_)); | 75 memset(static_cast<void*>(&plugin_funcs_), 0, sizeof(plugin_funcs_)); |
76 g_loaded_libs->push_back(make_scoped_refptr(this)); | 76 g_loaded_libs->push_back(make_scoped_refptr(this)); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 | 327 |
328 void PluginLib::Shutdown() { | 328 void PluginLib::Shutdown() { |
329 if (initialized_) { | 329 if (initialized_) { |
330 NP_Shutdown(); | 330 NP_Shutdown(); |
331 initialized_ = false; | 331 initialized_ = false; |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 } // namespace content | 335 } // namespace content |
OLD | NEW |