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

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: Removed PurgePluginListCache from the file watchere as it lead to crashes when plugins were in use. 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 0c8ee4c579650e0d8e4d7e3f96e5a364f6c8e4d2..b3fe7133bba8b753b6c09d455a5086b1b3d8bd48 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,28 @@ 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();
pastarmovj 2011/01/12 16:51:09 Problem here was that PurgePluginCache can be exec
+ }
+ 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 +108,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 +146,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 +172,27 @@ 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;
+ 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.
+#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);
+ }
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources());
@@ -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);
pastarmovj 2011/01/12 16:51:09 I can imagine this will lead to the same problem (
+#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,12 @@ void PluginService::RegisterPepperPlugins() {
webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
}
}
+
+// static
+void PluginService::RegisterFilePathWatcher(
+ FilePathWatcher *watcher,
+ const FilePath& path,
+ FilePathWatcher::Delegate* delegate) {
+ bool result = watcher->Watch(path, delegate);
+ DCHECK(result);
+}
« 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