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

Unified Diff: chrome/browser/plugin_service.cc

Issue 6163003: Added automatic update for plugins based on watching file changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a line >80chars long. Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/plugin_service.cc
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc
index 0c8ee4c579650e0d8e4d7e3f96e5a364f6c8e4d2..10bed08b006af932219f67a66ae706a9084589af 100644
--- a/chrome/browser/plugin_service.cc
+++ b/chrome/browser/plugin_service.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/path_service.h"
+#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
@@ -58,6 +59,31 @@ static void NotifyPluginsOfActivation() {
}
#endif
+static void PurgePluginListCache(bool reload_pages) {
+ for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
+ !it.IsAtEnd(); it.Advance()) {
+ it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages));
+ }
+}
+
+// Delegate class for monitoring directories.
+class PluginDirWatcherDelegate : public FilePathWatcher::Delegate {
+ virtual void OnFilePathChanged(const FilePath& path) {
+ VLOG(1) << "Watched path changed : " << path.value();
+
+ // Make the plugin list update itself
+ webkit::npapi::PluginList::Singleton()->RefreshPlugins();
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
Bernhard Bauer 2011/01/10 13:27:20 Is there are reason you're calling this method on
jam 2011/01/10 17:18:10 yep RenderProcessHost lives on the UI thread
pastarmovj 2011/01/11 17:17:26 It was a comment from John back than "since this i
pastarmovj 2011/01/11 17:17:26 Sorry I didn't post my answer earlier, when I had
+ NewRunnableFunction(&PurgePluginListCache, true));
+ }
+ virtual void OnError() {
+ // TODO(pastarmovj): Add some sensible error handling. Maybe silently
+ // stopping the watcher would be enough. Or possibly restart it.
+ NOTREACHED();
+ }
+};
+
// static
bool PluginService::enable_chrome_plugins_ = true;
@@ -85,7 +111,8 @@ void PluginService::EnableChromePlugins(bool enable) {
PluginService::PluginService()
: main_message_loop_(MessageLoop::current()),
resource_dispatcher_host_(NULL),
- ui_locale_(g_browser_process->GetApplicationLocale()) {
+ ui_locale_(g_browser_process->GetApplicationLocale()),
+ file_watcher_delegate_(new PluginDirWatcherDelegate()) {
RegisterPepperPlugins();
// Have the NPAPI plugin list search for Chrome plugins as well.
@@ -122,6 +149,9 @@ PluginService::PluginService()
chrome::RegisterInternalGPUPlugin();
+ // Start watching for changes in the plugin list. This means watching
+ // for changes in the Windows registry keys and on both Windows and POSIX
+ // watch for changes in the paths that are expected to contain plugins.
#if defined(OS_WIN)
hkcu_key_.Create(
HKEY_CURRENT_USER, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY);
@@ -145,6 +175,22 @@ PluginService::PluginService()
user_data_dir.Append("Plugins"));
}
#endif
+ // Get the list of all paths for registering the FilePathWatchers
+ // that will track and if needed reload the list of plugins on runtime.
+ std::vector<FilePath> plugin_dirs_list;
jam 2011/01/10 17:18:10 nit: plugin_dirs_ is enough, especially since list
pastarmovj 2011/01/11 17:17:26 That's true, thanks for the note :) Done.
+ webkit::npapi::PluginList::Singleton()->GetPluginDirectories(
+ &plugin_dirs_list);
+
+ for (size_t i = 0; i < plugin_dirs_list.size(); ++i) {
+ FilePathWatcher* watcher = new FilePathWatcher();
+ VLOG(1) << "Watching for changes in : " << plugin_dirs_list[i].value();
Bernhard Bauer 2011/01/10 13:27:20 Nit: no space before the colon.
pastarmovj 2011/01/11 17:17:26 Done.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableFunction(
+ &PluginService::RegisterFilePathWatcher,
+ watcher, plugin_dirs_list[i], file_watcher_delegate_));
+ file_watchers_.push_back(watcher);
+ }
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources());
@@ -168,6 +214,8 @@ PluginService::~PluginService() {
hkcu_event_->Release();
hklm_event_->Release();
#endif
+ // Delete the file watchers to release the refcounted delegates.
+ STLDeleteElements(&file_watchers_);
}
void PluginService::LoadChromePlugins(
@@ -304,13 +352,6 @@ bool PluginService::GetFirstAllowedPluginInfo(
#endif
}
-static void PurgePluginListCache(bool reload_pages) {
- for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
- !it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages));
- }
-}
-
void PluginService::OnWaitableEventSignaled(
base::WaitableEvent* waitable_event) {
#if defined(OS_WIN)
@@ -322,6 +363,9 @@ void PluginService::OnWaitableEventSignaled(
webkit::npapi::PluginList::Singleton()->RefreshPlugins();
PurgePluginListCache(true);
+#else
+ // This event should only get signaled on a Windows machine.
+ NOTREACHED();
#endif // defined(OS_WIN)
}
@@ -386,7 +430,7 @@ void PluginService::Observe(NotificationType type,
break;
}
default:
- DCHECK(false);
+ NOTREACHED();
}
}
@@ -428,3 +472,11 @@ void PluginService::RegisterPepperPlugins() {
webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
}
}
+
+// static
+void PluginService::RegisterFilePathWatcher(
+ FilePathWatcher *watcher,
+ const FilePath& path,
+ FilePathWatcher::Delegate* delegate) {
+ DCHECK(watcher->Watch(path, delegate));
Bernhard Bauer 2011/01/10 13:27:20 Isn't this whole line a no-op in a release build?
pastarmovj 2011/01/11 17:17:26 True. Sorry about that.
+}

Powered by Google App Engine
This is Rietveld 408576698