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

Side by Side Diff: content/browser/plugin_service_impl.cc

Issue 11794042: Switch to using FilePathWatcher::Callback instead of FilePathWatcher::Delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/plugin_service_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/plugin_service_impl.h" 5 #include "content/browser/plugin_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // correct thread. 62 // correct thread.
63 void WillLoadPluginsCallback( 63 void WillLoadPluginsCallback(
64 base::SequencedWorkerPool::SequenceToken token) { 64 base::SequencedWorkerPool::SequenceToken token) {
65 if (LoadPluginListInProcess()) { 65 if (LoadPluginListInProcess()) {
66 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 66 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
67 token)); 67 token));
68 } else { 68 } else {
69 CHECK(false) << "Plugin loading should happen out-of-process."; 69 CHECK(false) << "Plugin loading should happen out-of-process.";
70 } 70 }
71 } 71 }
72 } // namespace
73 72
74 #if defined(OS_MACOSX) 73 #if defined(OS_MACOSX)
75 static void NotifyPluginsOfActivation() { 74 void NotifyPluginsOfActivation() {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77 76
78 for (PluginProcessHostIterator iter; !iter.Done(); ++iter) 77 for (PluginProcessHostIterator iter; !iter.Done(); ++iter)
79 iter->OnAppActivation(); 78 iter->OnAppActivation();
80 } 79 }
81 #endif 80 #endif
81
82 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) 82 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
83 // Delegate class for monitoring directories. 83 void NotifyPluginDirChanged(const FilePath& path, bool error) {
84 class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { 84 if (error) {
85 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
86 VLOG(1) << "Watched path changed: " << path.value();
87 // Make the plugin list update itself
88 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
89 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE,
91 base::Bind(&PluginService::PurgePluginListCache,
92 static_cast<BrowserContext*>(NULL), false));
93 }
94
95 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
96 // TODO(pastarmovj): Add some sensible error handling. Maybe silently 85 // TODO(pastarmovj): Add some sensible error handling. Maybe silently
97 // stopping the watcher would be enough. Or possibly restart it. 86 // stopping the watcher would be enough. Or possibly restart it.
98 NOTREACHED(); 87 NOTREACHED();
88 return;
99 } 89 }
90 VLOG(1) << "Watched path changed: " << path.value();
91 // Make the plugin list update itself
92 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
93 BrowserThread::PostTask(
94 BrowserThread::UI, FROM_HERE,
95 base::Bind(&PluginService::PurgePluginListCache,
96 static_cast<BrowserContext*>(NULL), false));
97 }
98 #endif
100 99
101 protected: 100 } // namespace
102 virtual ~PluginDirWatcherDelegate() {}
103 };
104 #endif
105 101
106 // static 102 // static
107 PluginService* PluginService::GetInstance() { 103 PluginService* PluginService::GetInstance() {
108 return PluginServiceImpl::GetInstance(); 104 return PluginServiceImpl::GetInstance();
109 } 105 }
110 106
111 void PluginService::PurgePluginListCache(BrowserContext* browser_context, 107 void PluginService::PurgePluginListCache(BrowserContext* browser_context,
112 bool reload_pages) { 108 bool reload_pages) {
113 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); 109 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
114 !it.IsAtEnd(); it.Advance()) { 110 !it.IsAtEnd(); it.Advance()) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 KEY_NOTIFY) == ERROR_SUCCESS) { 177 KEY_NOTIFY) == ERROR_SUCCESS) {
182 if (hklm_key_.StartWatching() == ERROR_SUCCESS) { 178 if (hklm_key_.StartWatching() == ERROR_SUCCESS) {
183 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); 179 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
184 hklm_watcher_.StartWatching(hklm_event_.get(), this); 180 hklm_watcher_.StartWatching(hklm_event_.get(), this);
185 } 181 }
186 } 182 }
187 #endif 183 #endif
188 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) 184 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
189 // On ChromeOS the user can't install plugins anyway and on Windows all 185 // On ChromeOS the user can't install plugins anyway and on Windows all
190 // important plugins register themselves in the registry so no need to do that. 186 // important plugins register themselves in the registry so no need to do that.
191 file_watcher_delegate_ = new PluginDirWatcherDelegate(); 187
192 // Get the list of all paths for registering the FilePathWatchers 188 // Get the list of all paths for registering the FilePathWatchers
193 // that will track and if needed reload the list of plugins on runtime. 189 // that will track and if needed reload the list of plugins on runtime.
194 std::vector<FilePath> plugin_dirs; 190 std::vector<FilePath> plugin_dirs;
195 plugin_list_->GetPluginDirectories(&plugin_dirs); 191 plugin_list_->GetPluginDirectories(&plugin_dirs);
196 192
197 for (size_t i = 0; i < plugin_dirs.size(); ++i) { 193 for (size_t i = 0; i < plugin_dirs.size(); ++i) {
198 // FilePathWatcher can not handle non-absolute paths under windows. 194 // FilePathWatcher can not handle non-absolute paths under windows.
199 // We don't watch for file changes in windows now but if this should ever 195 // We don't watch for file changes in windows now but if this should ever
200 // be extended to Windows these lines might save some time of debugging. 196 // be extended to Windows these lines might save some time of debugging.
201 #if defined(OS_WIN) 197 #if defined(OS_WIN)
202 if (!plugin_dirs[i].IsAbsolute()) 198 if (!plugin_dirs[i].IsAbsolute())
203 continue; 199 continue;
204 #endif 200 #endif
205 FilePathWatcher* watcher = new FilePathWatcher(); 201 FilePathWatcher* watcher = new FilePathWatcher();
206 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); 202 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value();
207 BrowserThread::PostTask( 203 BrowserThread::PostTask(
208 BrowserThread::FILE, FROM_HERE, 204 BrowserThread::FILE, FROM_HERE,
209 base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher, 205 base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher,
210 plugin_dirs[i], file_watcher_delegate_)); 206 plugin_dirs[i]));
211 file_watchers_.push_back(watcher); 207 file_watchers_.push_back(watcher);
212 } 208 }
213 #endif 209 #endif
214 } 210 }
215 211
216 PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( 212 PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess(
217 const FilePath& plugin_path) { 213 const FilePath& plugin_path) {
218 for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { 214 for (PluginProcessHostIterator iter; !iter.Done(); ++iter) {
219 if (iter->info().path == plugin_path) 215 if (iter->info().path == plugin_path)
220 return *iter; 216 return *iter;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 return NULL; 590 return NULL;
595 PepperPluginInfo new_pepper_info; 591 PepperPluginInfo new_pepper_info;
596 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) 592 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
597 return NULL; 593 return NULL;
598 ppapi_plugins_.push_back(new_pepper_info); 594 ppapi_plugins_.push_back(new_pepper_info);
599 return &ppapi_plugins_[ppapi_plugins_.size() - 1]; 595 return &ppapi_plugins_[ppapi_plugins_.size() - 1];
600 } 596 }
601 597
602 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) 598 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
603 // static 599 // static
604 void PluginServiceImpl::RegisterFilePathWatcher( 600 void PluginServiceImpl::RegisterFilePathWatcher(FilePathWatcher* watcher,
605 FilePathWatcher* watcher, 601 const FilePath& path) {
606 const FilePath& path, 602 bool result = watcher->Watch(path, false,
607 FilePathWatcher::Delegate* delegate) { 603 base::Bind(&NotifyPluginDirChanged));
608 bool result = watcher->Watch(path, delegate);
609 DCHECK(result); 604 DCHECK(result);
610 } 605 }
611 #endif 606 #endif
612 607
613 void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) { 608 void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) {
614 filter_ = filter; 609 filter_ = filter;
615 } 610 }
616 611
617 PluginServiceFilter* PluginServiceImpl::GetFilter() { 612 PluginServiceFilter* PluginServiceImpl::GetFilter() {
618 return filter_; 613 return filter_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 683 }
689 684
690 void PluginServiceImpl::SetPluginListForTesting( 685 void PluginServiceImpl::SetPluginListForTesting(
691 webkit::npapi::PluginList* plugin_list) { 686 webkit::npapi::PluginList* plugin_list) {
692 plugin_list_ = plugin_list; 687 plugin_list_ = plugin_list;
693 } 688 }
694 689
695 #if defined(OS_MACOSX) 690 #if defined(OS_MACOSX)
696 void PluginServiceImpl::AppActivated() { 691 void PluginServiceImpl::AppActivated() {
697 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 692 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
698 base::Bind(&NotifyPluginsOfActivation)); 693 base::Bind(&NotifyPluginsOfActivation));
699 } 694 }
700 #endif 695 #endif
701 696
702 void PluginServiceImpl::RegisterInternalPlugin( 697 void PluginServiceImpl::RegisterInternalPlugin(
703 const webkit::WebPluginInfo& info, 698 const webkit::WebPluginInfo& info,
704 bool add_at_beginning) { 699 bool add_at_beginning) {
705 plugin_list_->RegisterInternalPlugin(info, add_at_beginning); 700 plugin_list_->RegisterInternalPlugin(info, add_at_beginning);
706 } 701 }
707 702
708 void PluginServiceImpl::GetInternalPlugins( 703 void PluginServiceImpl::GetInternalPlugins(
709 std::vector<webkit::WebPluginInfo>* plugins) { 704 std::vector<webkit::WebPluginInfo>* plugins) {
710 plugin_list_->GetInternalPlugins(plugins); 705 plugin_list_->GetInternalPlugins(plugins);
711 } 706 }
712 707
713 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { 708 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() {
714 return plugin_list_; 709 return plugin_list_;
715 } 710 }
716 711
717 } // namespace content 712 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/plugin_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698