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