Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: content/browser/plugin_service.h

Issue 7980011: Convert the PluginService interface to be an async wrapper around PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for review Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This class responds to requests from renderers for the list of plugins, and 5 // This class responds to requests from renderers for the list of plugins, and
6 // also a proxy object for plugin instances. 6 // also a proxy object for plugin instances.
7 7
8 #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_H_ 8 #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_H_
9 #define CONTENT_BROWSER_PLUGIN_SERVICE_H_ 9 #define CONTENT_BROWSER_PLUGIN_SERVICE_H_
10 #pragma once 10 #pragma once
11 11
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/callback.h"
16 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
18 #include "base/synchronization/waitable_event_watcher.h" 19 #include "base/synchronization/waitable_event_watcher.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/browser/plugin_process_host.h" 21 #include "content/browser/plugin_process_host.h"
21 #include "content/browser/ppapi_plugin_process_host.h" 22 #include "content/browser/ppapi_plugin_process_host.h"
22 #include "content/browser/ppapi_broker_process_host.h" 23 #include "content/browser/ppapi_broker_process_host.h"
23 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
24 #include "content/common/notification_observer.h" 25 #include "content/common/notification_observer.h"
25 #include "content/common/notification_registrar.h" 26 #include "content/common/notification_registrar.h"
26 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
27 #include "ipc/ipc_channel_handle.h" 28 #include "ipc/ipc_channel_handle.h"
29 #include "webkit/plugins/npapi/plugin_group.h"
jam 2011/09/21 00:04:51 nit: can you get away with forward declaring?
28 #include "webkit/plugins/webplugininfo.h" 30 #include "webkit/plugins/webplugininfo.h"
29 31
30 #if defined(OS_WIN) 32 #if defined(OS_WIN)
31 #include "base/memory/scoped_ptr.h" 33 #include "base/memory/scoped_ptr.h"
32 #include "base/win/registry.h" 34 #include "base/win/registry.h"
33 #endif 35 #endif
34 36
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) 37 #if defined(OS_POSIX) && !defined(OS_MACOSX)
36 #include "base/files/file_path_watcher.h" 38 #include "base/files/file_path_watcher.h"
37 #endif 39 #endif
38 40
39 struct PepperPluginInfo; 41 struct PepperPluginInfo;
40 class PluginDirWatcherDelegate; 42 class PluginDirWatcherDelegate;
41 43
44 namespace base {
45 class MessageLoopProxy;
46 }
47
42 namespace content { 48 namespace content {
43 class ResourceContext; 49 class ResourceContext;
44 class PluginServiceFilter; 50 class PluginServiceFilter;
45 } 51 }
46 52
53 namespace webkit {
54 namespace npapi {
55 class MockPluginList;
56 class PluginList;
57 }
58 }
59
47 // This must be created on the main thread but it's only called on the IO/file 60 // This must be created on the main thread but it's only called on the IO/file
48 // thread. 61 // thread. This is an asynchronous wrapper around the PluginList interface for
62 // querying plugin information, and this should instead of that class in the
63 // content layer and above.
jam 2011/09/21 00:04:51 above->below? (see http://dev.chromium.org/develop
Robert Sesek 2011/09/21 01:13:44 I guess it depends if you're looking up or down ;)
jam 2011/09/21 17:20:15 (big nit!) It's been my experience that we use dow
49 class CONTENT_EXPORT PluginService 64 class CONTENT_EXPORT PluginService
50 : public base::WaitableEventWatcher::Delegate, 65 : public base::WaitableEventWatcher::Delegate,
51 public NotificationObserver { 66 public NotificationObserver {
52 public: 67 public:
53 struct OverriddenPlugin { 68 struct OverriddenPlugin {
54 int render_process_id; 69 int render_process_id;
55 int render_view_id; 70 int render_view_id;
56 GURL url; // If empty, the override applies to all urls in render_view. 71 GURL url; // If empty, the override applies to all urls in render_view.
57 webkit::WebPluginInfo plugin; 72 webkit::WebPluginInfo plugin;
58 }; 73 };
59 74
75 typedef base::Callback<void(std::vector<webkit::WebPluginInfo>)>
jam 2011/09/21 00:04:51 const ref (and below)
76 GetPluginsCallback;
77 typedef base::Callback<void(std::vector<webkit::npapi::PluginGroup>)>
78 GetPluginGroupsCallback;
79
60 // Returns the PluginService singleton. 80 // Returns the PluginService singleton.
61 static PluginService* GetInstance(); 81 static PluginService* GetInstance();
62 82
63 // Starts watching for changes in the list of installed plug-ins. 83 // Starts watching for changes in the list of installed plug-ins.
64 void StartWatchingPlugins(); 84 void StartWatchingPlugins();
65 85
66 // Gets the browser's UI locale. 86 // Gets the browser's UI locale.
67 const std::string& GetUILocale(); 87 const std::string& GetUILocale();
68 88
69 // Returns the plugin process host corresponding to the plugin process that 89 // Returns the plugin process host corresponding to the plugin process that
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 int render_view_id, 128 int render_view_id,
109 const content::ResourceContext& context, 129 const content::ResourceContext& context,
110 const GURL& url, 130 const GURL& url,
111 const GURL& page_url, 131 const GURL& page_url,
112 const std::string& mime_type, 132 const std::string& mime_type,
113 bool allow_wildcard, 133 bool allow_wildcard,
114 bool* use_stale, 134 bool* use_stale,
115 webkit::WebPluginInfo* info, 135 webkit::WebPluginInfo* info,
116 std::string* actual_mime_type); 136 std::string* actual_mime_type);
117 137
118 // Returns a list of all plug-ins available to the resource context. Must be 138 // Marks the plugin list as dirty and will cause the plugins to be reloaded
119 // called on the FILE thread. 139 // on the next access through GetPlugins() or GetPluginGroups().
140 void RefreshPluginList();
141
142 // Asynchronously loads plugins on the FILE thread and then calls back to the
jam 2011/09/21 00:04:51 nit: i think it's better not to mention file threa
143 // provided function on the calling MessageLoop on completion.
120 void GetPlugins(const content::ResourceContext& context, 144 void GetPlugins(const content::ResourceContext& context,
121 std::vector<webkit::WebPluginInfo>* plugins); 145 const GetPluginsCallback& callback);
146 // Variant of above, but does not perform filtering based on |context|.
147 void GetPlugins(const GetPluginsCallback& callback);
148
149 // Returns the list of cached plugin groups. This can be called from any
150 // thread, but note that the data can be stale.
151 void GetCachedPluginGroups(std::vector<webkit::npapi::PluginGroup>* groups);
152
153 // Gets the list of plugin groups, reloading them from disk if marked as dirty
154 // with RefreshPluginList().
155 void GetPluginGroups(const GetPluginGroupsCallback& callback);
122 156
123 // Tells all the renderer processes to throw away their cache of the plugin 157 // Tells all the renderer processes to throw away their cache of the plugin
124 // list, and optionally also reload all the pages with plugins. 158 // list, and optionally also reload all the pages with plugins.
125 // NOTE: can only be called on the UI thread. 159 // NOTE: can only be called on the UI thread.
126 static void PurgePluginListCache(bool reload_pages); 160 static void PurgePluginListCache(bool reload_pages);
127 161
128 void set_filter(content::PluginServiceFilter* filter) { 162 void set_filter(content::PluginServiceFilter* filter) {
129 filter_ = filter; 163 filter_ = filter;
130 } 164 }
131 165
166 // Sets the PluginList for testing environments. Be sure to change back to
167 // NULL at the end of the test!
168 void SetPluginListForTesting(webkit::npapi::MockPluginList* plugin_list);
jam 2011/09/21 00:04:51 nit: can you make this private and friend the test
Robert Sesek 2011/09/21 01:13:44 I personally hate friending tests in shared compon
jam 2011/09/21 06:31:46 oh I didn't know about that presubmit check. I'm c
169
132 private: 170 private:
133 friend struct DefaultSingletonTraits<PluginService>; 171 friend struct DefaultSingletonTraits<PluginService>;
134 172
135 // Creates the PluginService object, but doesn't actually build the plugin 173 // Creates the PluginService object, but doesn't actually build the plugin
136 // list yet. It's generated lazily. 174 // list yet. It's generated lazily.
137 PluginService(); 175 PluginService();
138 virtual ~PluginService(); 176 virtual ~PluginService();
139 177
178 // Returns the PluginList, either the singleton or the override.
179 webkit::npapi::PluginList* GetPluginList();
180
140 // base::WaitableEventWatcher::Delegate implementation. 181 // base::WaitableEventWatcher::Delegate implementation.
141 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); 182 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event);
142 183
143 // NotificationObserver implementation 184 // NotificationObserver implementation
144 virtual void Observe(int type, const NotificationSource& source, 185 virtual void Observe(int type, const NotificationSource& source,
145 const NotificationDetails& details); 186 const NotificationDetails& details);
146 187
147 void RegisterPepperPlugins(); 188 void RegisterPepperPlugins();
148 189
149 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); 190 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path);
150 191
192 // Function that is run on the FILE thread to load the plugins synchronously.
193 void GetPluginsInternal(const content::ResourceContext* context,
194 base::MessageLoopProxy* target_loop,
195 const GetPluginsCallback& callback);
196
151 // Helper so we can do the plugin lookup on the FILE thread. 197 // Helper so we can do the plugin lookup on the FILE thread.
152 void GetAllowedPluginForOpenChannelToPlugin( 198 void GetAllowedPluginForOpenChannelToPlugin(
153 int render_process_id, 199 int render_process_id,
154 int render_view_id, 200 int render_view_id,
155 const GURL& url, 201 const GURL& url,
156 const GURL& page_url, 202 const GURL& page_url,
157 const std::string& mime_type, 203 const std::string& mime_type,
158 PluginProcessHost::Client* client, 204 PluginProcessHost::Client* client,
159 const content::ResourceContext* resource_context); 205 const content::ResourceContext* resource_context);
160 206
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; 238 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
193 #endif 239 #endif
194 240
195 std::vector<PepperPluginInfo> ppapi_plugins_; 241 std::vector<PepperPluginInfo> ppapi_plugins_;
196 242
197 // Weak pointer; outlives us. 243 // Weak pointer; outlives us.
198 content::PluginServiceFilter* filter_; 244 content::PluginServiceFilter* filter_;
199 245
200 std::set<PluginProcessHost::Client*> pending_plugin_clients_; 246 std::set<PluginProcessHost::Client*> pending_plugin_clients_;
201 247
248 // Alternate plugin list to use for testing environments. When NULL, defaults
249 // to the singleton.
250 webkit::npapi::PluginList* plugin_list_;
251
202 DISALLOW_COPY_AND_ASSIGN(PluginService); 252 DISALLOW_COPY_AND_ASSIGN(PluginService);
203 }; 253 };
204 254
205 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); 255 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService);
206 256
207 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ 257 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698