| 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 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ | 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ |
| 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ | 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/hash_tables.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "webkit/plugins/webplugininfo.h" | 17 #include "webkit/plugins/webplugininfo.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class DictionaryValue; | 20 class DictionaryValue; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| 24 class PluginMetadata; |
| 25 |
| 26 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 24 class PluginInstaller; | 27 class PluginInstaller; |
| 28 #endif |
| 25 | 29 |
| 30 // This class should be created and initialized by calling |
| 31 // |GetInstance()| and |Init()| on the UI thread. |
| 32 // After that it can be safely used on any other thread. |
| 26 class PluginFinder { | 33 class PluginFinder { |
| 27 public: | 34 public: |
| 28 typedef std::vector<webkit::WebPluginInfo> PluginVector; | 35 static PluginFinder* GetInstance(); |
| 29 typedef base::Callback<void(const PluginVector&, PluginFinder*)> | |
| 30 CombinedCallback; | |
| 31 // Gets PluginFinder and vector of Plugins asynchronously. It then | |
| 32 // calls |cb| once both are fetched. | |
| 33 static void GetPluginsAndPluginFinder(const CombinedCallback& cb); | |
| 34 | 36 |
| 37 // It should be called on the UI thread. |
| 38 void Init(); |
| 39 |
| 40 // TODO(ibraaaa): DELETE. http://crbug.com/124396 |
| 35 static void Get(const base::Callback<void(PluginFinder*)>& cb); | 41 static void Get(const base::Callback<void(PluginFinder*)>& cb); |
| 36 | 42 |
| 43 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 37 // Finds a plug-in for the given MIME type and language (specified as an IETF | 44 // Finds a plug-in for the given MIME type and language (specified as an IETF |
| 38 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, | 45 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, |
| 39 // or NULL if no plug-in is found. | 46 // or NULL if no plug-in is found. |
| 40 PluginInstaller* FindPlugin(const std::string& mime_type, | 47 PluginInstaller* FindPlugin(const std::string& mime_type, |
| 41 const std::string& language); | 48 const std::string& language); |
| 42 | 49 |
| 43 // Returns the plug-in with the given identifier. | 50 // Returns the plug-in with the given identifier. |
| 44 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); | 51 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); |
| 52 #endif |
| 45 | 53 |
| 46 // Gets a plug-in installer using |plugin|. | 54 // Returns the plug-in metadata with the given identifier. |
| 47 PluginInstaller* GetPluginInstaller(const webkit::WebPluginInfo& plugin); | 55 PluginMetadata* FindPluginMetadataWithIdentifier( |
| 56 const std::string& identifier); |
| 57 |
| 58 // Gets plug-in metadata using |plugin|. |
| 59 PluginMetadata* GetPluginMetadata(const webkit::WebPluginInfo& plugin); |
| 48 | 60 |
| 49 private: | 61 private: |
| 50 friend struct DefaultSingletonTraits<PluginFinder>; | 62 friend struct DefaultSingletonTraits<PluginFinder>; |
| 51 friend class Singleton<PluginFinder>; | 63 friend class Singleton<PluginFinder>; |
| 52 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); | 64 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); |
| 53 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); | 65 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); |
| 54 | 66 |
| 55 static PluginFinder* GetInstance(); | |
| 56 | |
| 57 PluginFinder(); | 67 PluginFinder(); |
| 58 ~PluginFinder(); | 68 ~PluginFinder(); |
| 59 | 69 |
| 60 // Loads the plug-in information from the browser resources and parses it. | 70 // Loads the plug-in information from the browser resources and parses it. |
| 61 // Returns NULL if the plug-in list couldn't be parsed. | 71 // Returns NULL if the plug-in list couldn't be parsed. |
| 62 static base::DictionaryValue* LoadPluginList(); | 72 static base::DictionaryValue* LoadPluginList(); |
| 63 | 73 |
| 64 PluginInstaller* CreateInstaller(const std::string& identifier, | 74 PluginMetadata* CreatePluginMetadata( |
| 65 const base::DictionaryValue* plugin_dict); | 75 const std::string& identifier, |
| 76 const base::DictionaryValue* plugin_dict); |
| 66 | 77 |
| 78 // Initialized in |Init()| method and is read-only after that. |
| 79 // No need to be synchronized. |
| 67 scoped_ptr<base::DictionaryValue> plugin_list_; | 80 scoped_ptr<base::DictionaryValue> plugin_list_; |
| 81 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 68 std::map<std::string, PluginInstaller*> installers_; | 82 std::map<std::string, PluginInstaller*> installers_; |
| 83 #endif |
| 69 | 84 |
| 70 // Note: Don't free memory for |name_insallers_| values | 85 std::map<std::string, PluginMetadata*> identifier_plugin_; |
| 86 |
| 87 // Note: Don't free memory for |name_plugin_| values |
| 71 // since it holds pointers to same instances | 88 // since it holds pointers to same instances |
| 72 // in |installers_| (Double De-allocation). | 89 // in |identifier_plugin_| (Double De-allocation). |
| 73 base::hash_map<string16, PluginInstaller*> name_installers_; | 90 std::map<string16, PluginMetadata*> name_plugin_; |
| 91 |
| 92 // Synchronization for |installers_|, |identifier_plugin_| and |
| 93 // |name_plugin_| are required since multiple threads |
| 94 // can be accessing them concurrently. |
| 95 base::Lock mutex_; |
| 74 | 96 |
| 75 DISALLOW_COPY_AND_ASSIGN(PluginFinder); | 97 DISALLOW_COPY_AND_ASSIGN(PluginFinder); |
| 76 }; | 98 }; |
| 77 | 99 |
| 78 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ | 100 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ |
| OLD | NEW |