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

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: Limited the file watcher to Linux only. 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
« no previous file with comments | « chrome/browser/plugin_service.h ('k') | webkit/plugins/npapi/plugin_list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/plugin_service.cc
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc
index 1f178d9b327a94d7d3ca57653648bef2e7bf81e2..8cb4f1283a364fed407b819f3319a3f2fccaab27 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"
@@ -56,6 +57,29 @@ 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));
+ }
+}
+
+#if defined(OS_LINUX)
+// 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();
+ }
+ virtual void OnError() {
+ // TODO(pastarmovj): Add some sensible error handling. Maybe silently
+ // stopping the watcher would be enough. Or possibly restart it.
+ NOTREACHED();
+ }
+};
+#endif
+
// static
bool PluginService::enable_chrome_plugins_ = true;
@@ -120,6 +144,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);
@@ -143,7 +170,36 @@ PluginService::PluginService()
user_data_dir.Append("Plugins"));
}
#endif
-
+// The FilePathWatcher produces too many false positives on MacOS (access time
+// updates?) which will lead to enforcing updates of the plugins way too often.
+// On ChromeOS the user can't install plugins anywaya and on Windows all
+// important pluigns register themselves in the registry so no need to do that.
jam 2011/01/18 20:21:31 nit: plugins
+#if defined(OS_LINUX)
+ file_watcher_delegate_ = new PluginDirWatcherDelegate();
+ // 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;
+ webkit::npapi::PluginList::Singleton()->GetPluginDirectories(
+ &plugin_dirs);
+
+ for (size_t i = 0; i < plugin_dirs.size(); ++i) {
+ FilePathWatcher* watcher = new FilePathWatcher();
+ // FilePathWatcher can not handle non-absolute paths under windows.
+ // We don't watch for file changes in windows now but if this should ever
+ // be extended to Windows these lines might save some time of debugging.
+#if defined(OS_WIN)
+ if (!plugin_dirs[i].IsAbsolute())
+ continue;
+#endif
+ VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value();
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableFunction(
+ &PluginService::RegisterFilePathWatcher,
+ watcher, plugin_dirs[i], file_watcher_delegate_));
+ file_watchers_.push_back(watcher);
+ }
+#endif
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
@@ -302,13 +358,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)
@@ -320,6 +369,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)
}
@@ -384,7 +436,7 @@ void PluginService::Observe(NotificationType type,
break;
}
default:
- DCHECK(false);
+ NOTREACHED();
}
}
@@ -426,3 +478,14 @@ void PluginService::RegisterPepperPlugins() {
webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
}
}
+
+#if defined(OS_LINUX)
+// static
+void PluginService::RegisterFilePathWatcher(
+ FilePathWatcher *watcher,
+ const FilePath& path,
+ FilePathWatcher::Delegate* delegate) {
+ bool result = watcher->Watch(path, delegate);
+ DCHECK(result);
+}
+#endif
« no previous file with comments | « chrome/browser/plugin_service.h ('k') | webkit/plugins/npapi/plugin_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698