 Chromium Code Reviews
 Chromium Code Reviews Issue 10910168:
  Separate plugin_metadata from plugin_installer, thread-safe plugin_finder  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master
    
  
    Issue 10910168:
  Separate plugin_metadata from plugin_installer, thread-safe plugin_finder  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master| 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. | |
| 
Bernhard Bauer
2012/09/24 09:14:25
This comment isn't correct anymore.
 
ibraaaa
2012/09/24 11:01:07
reverted the custom traits.
On 2012/09/24 09:14:25
 | |
| 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 // TODO(ibraaaa): DELETE. http://crbug.com/124396 | |
| 35 static void Get(const base::Callback<void(PluginFinder*)>& cb); | 38 static void Get(const base::Callback<void(PluginFinder*)>& cb); | 
| 36 | 39 | 
| 40 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
| 37 // Finds a plug-in for the given MIME type and language (specified as an IETF | 41 // 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, | 42 // language tag, i.e. en-US) and returns the PluginInstaller for the plug-in, | 
| 39 // or NULL if no plug-in is found. | 43 // or NULL if no plug-in is found. | 
| 40 PluginInstaller* FindPlugin(const std::string& mime_type, | 44 PluginInstaller* FindPlugin(const std::string& mime_type, | 
| 41 const std::string& language); | 45 const std::string& language); | 
| 42 | 46 | 
| 43 // Returns the plug-in with the given identifier. | 47 // Returns the plug-in with the given identifier. | 
| 44 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); | 48 PluginInstaller* FindPluginWithIdentifier(const std::string& identifier); | 
| 49 #endif | |
| 45 | 50 | 
| 46 // Gets a plug-in installer using |plugin|. | 51 // Returns the plug-in metadata with the given identifier. | 
| 47 PluginInstaller* GetPluginInstaller(const webkit::WebPluginInfo& plugin); | 52 PluginMetadata* FindPluginMetadataWithIdentifier( | 
| 53 const std::string& identifier); | |
| 54 | |
| 55 // Gets plug-in metadata using |plugin|. | |
| 56 PluginMetadata* GetPluginMetadata(const webkit::WebPluginInfo& plugin); | |
| 48 | 57 | 
| 49 private: | 58 private: | 
| 59 // Custom traits that calls |Init()| to initialize the singleton object | |
| 60 // after creation. | |
| 61 struct CustomSingletonTraits; | |
| 62 | |
| 50 friend struct DefaultSingletonTraits<PluginFinder>; | 63 friend struct DefaultSingletonTraits<PluginFinder>; | 
| 51 friend class Singleton<PluginFinder>; | 64 friend class Singleton<PluginFinder>; | 
| 52 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); | 65 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, JsonSyntax); | 
| 53 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); | 66 FRIEND_TEST_ALL_PREFIXES(PluginFinderTest, PluginGroups); | 
| 54 | 67 | 
| 55 static PluginFinder* GetInstance(); | |
| 56 | |
| 57 PluginFinder(); | 68 PluginFinder(); | 
| 58 ~PluginFinder(); | 69 ~PluginFinder(); | 
| 59 | 70 | 
| 71 // It should be called on the UI thread. | |
| 72 void Init(); | |
| 73 | |
| 60 // Loads the plug-in information from the browser resources and parses it. | 74 // Loads the plug-in information from the browser resources and parses it. | 
| 61 // Returns NULL if the plug-in list couldn't be parsed. | 75 // Returns NULL if the plug-in list couldn't be parsed. | 
| 62 static base::DictionaryValue* LoadPluginList(); | 76 static base::DictionaryValue* LoadPluginList(); | 
| 63 | 77 | 
| 64 PluginInstaller* CreateInstaller(const std::string& identifier, | 78 PluginMetadata* CreatePluginMetadata( | 
| 65 const base::DictionaryValue* plugin_dict); | 79 const std::string& identifier, | 
| 80 const base::DictionaryValue* plugin_dict); | |
| 66 | 81 | 
| 82 // Initialized in |Init()| method and is read-only after that. | |
| 83 // No need to be synchronized. | |
| 67 scoped_ptr<base::DictionaryValue> plugin_list_; | 84 scoped_ptr<base::DictionaryValue> plugin_list_; | 
| 85 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
| 68 std::map<std::string, PluginInstaller*> installers_; | 86 std::map<std::string, PluginInstaller*> installers_; | 
| 87 #endif | |
| 69 | 88 | 
| 70 // Note: Don't free memory for |name_insallers_| values | 89 std::map<std::string, PluginMetadata*> identifier_plugin_; | 
| 90 | |
| 91 // Note: Don't free memory for |name_plugin_| values | |
| 71 // since it holds pointers to same instances | 92 // since it holds pointers to same instances | 
| 72 // in |installers_| (Double De-allocation). | 93 // in |identifier_plugin_| (Double De-allocation). | 
| 73 base::hash_map<string16, PluginInstaller*> name_installers_; | 94 std::map<string16, PluginMetadata*> name_plugin_; | 
| 95 | |
| 96 // Synchronization for |installers_|, |identifier_plugin_| and | |
| 97 // |name_plugin_| are required since multiple threads | |
| 98 // can be accessing them concurrently. | |
| 99 base::Lock mutex_; | |
| 74 | 100 | 
| 75 DISALLOW_COPY_AND_ASSIGN(PluginFinder); | 101 DISALLOW_COPY_AND_ASSIGN(PluginFinder); | 
| 76 }; | 102 }; | 
| 77 | 103 | 
| 78 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ | 104 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_FINDER_H_ | 
| OLD | NEW |