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

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

Issue 8334004: Move PluginLoaderClient to PluginLoaderPosix in its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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_loader_posix.cc ('k') | content/content_browser.gypi » ('j') | 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) 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 #include "content/browser/plugin_service.h" 5 #include "content/browser/plugin_service.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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
20 #include "content/browser/content_browser_client.h" 20 #include "content/browser/content_browser_client.h"
21 #include "content/browser/plugin_loader_posix.h"
21 #include "content/browser/plugin_service_filter.h" 22 #include "content/browser/plugin_service_filter.h"
22 #include "content/browser/ppapi_plugin_process_host.h" 23 #include "content/browser/ppapi_plugin_process_host.h"
23 #include "content/browser/renderer_host/render_process_host.h" 24 #include "content/browser/renderer_host/render_process_host.h"
24 #include "content/browser/renderer_host/render_view_host.h" 25 #include "content/browser/renderer_host/render_view_host.h"
25 #include "content/browser/resource_context.h" 26 #include "content/browser/resource_context.h"
26 #include "content/browser/utility_process_host.h" 27 #include "content/browser/utility_process_host.h"
27 #include "content/common/content_notification_types.h" 28 #include "content/common/content_notification_types.h"
28 #include "content/common/notification_service.h" 29 #include "content/common/notification_service.h"
29 #include "content/common/pepper_plugin_registry.h" 30 #include "content/common/pepper_plugin_registry.h"
30 #include "content/common/plugin_messages.h" 31 #include "content/common/plugin_messages.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // correct thread. 67 // correct thread.
67 void WillLoadPluginsCallback() { 68 void WillLoadPluginsCallback() {
68 // TODO(rsesek): Change these to CHECKs. 69 // TODO(rsesek): Change these to CHECKs.
69 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) 70 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
70 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 71 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
71 #else 72 #else
72 CHECK(false) << "Plugin loading should happen out-of-process."; 73 CHECK(false) << "Plugin loading should happen out-of-process.";
73 #endif 74 #endif
74 } 75 }
75 76
76 #if defined(OS_POSIX)
77 // Utility child process client that manages the IPC for loading plugins out of
78 // process.
79 class PluginLoaderClient : public UtilityProcessHost::Client {
80 public:
81 // Meant to be called on the IO thread. Will invoke the callback on the target
82 // loop when the plugins have been loaded.
83 static void LoadPluginsOutOfProcess(
84 base::MessageLoopProxy* target_loop,
85 const PluginService::GetPluginsCallback& callback) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
87
88 PluginLoaderClient* client = new PluginLoaderClient(target_loop, callback);
89 UtilityProcessHost* process_host =
90 new UtilityProcessHost(client, BrowserThread::IO);
91 process_host->set_no_sandbox(true);
92 #if defined(OS_MACOSX)
93 process_host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
94 #endif
95
96 std::vector<FilePath> extra_plugin_paths;
97 std::vector<FilePath> extra_plugin_dirs;
98 std::vector<webkit::WebPluginInfo> internal_plugins;
99 webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad(
100 &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins);
101
102 process_host->Send(new UtilityMsg_LoadPlugins(
103 extra_plugin_paths, extra_plugin_dirs, internal_plugins));
104 }
105
106 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
107 bool handled = true;
108 IPC_BEGIN_MESSAGE_MAP(PluginLoaderClient, message)
109 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins)
110 IPC_MESSAGE_UNHANDLED(handled = false)
111 IPC_END_MESSAGE_MAP()
112 return handled;
113 }
114
115 virtual void OnProcessCrashed(int exit_code) OVERRIDE {
116 LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code
117 << ". You will have no plugins!";
118 // Don't leave callers hanging.
119 OnGotPlugins(std::vector<webkit::WebPluginInfo>());
120 }
121
122 virtual void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins) {
123 webkit::npapi::PluginList::Singleton()->SetPlugins(plugins);
124 target_loop_->PostTask(FROM_HERE,
125 base::Bind(&RunGetPluginsCallback, callback_, plugins));
126 }
127
128 private:
129 PluginLoaderClient(base::MessageLoopProxy* target_loop,
130 const PluginService::GetPluginsCallback& callback)
131 : target_loop_(target_loop),
132 callback_(callback) {
133 }
134
135 scoped_refptr<base::MessageLoopProxy> target_loop_;
136 PluginService::GetPluginsCallback callback_;
137
138 DISALLOW_COPY_AND_ASSIGN(PluginLoaderClient);
139 };
140 #endif // OS_POSIX
141
142 } // namespace 77 } // namespace
143 78
144 #if defined(OS_MACOSX) 79 #if defined(OS_MACOSX)
145 static void NotifyPluginsOfActivation() { 80 static void NotifyPluginsOfActivation() {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
147 82
148 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); 83 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
149 !iter.Done(); ++iter) { 84 !iter.Done(); ++iter) {
150 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); 85 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
151 plugin->OnAppActivation(); 86 plugin->OnAppActivation();
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 target_loop, callback)); 502 target_loop, callback));
568 #else 503 #else
569 std::vector<webkit::WebPluginInfo> cached_plugins; 504 std::vector<webkit::WebPluginInfo> cached_plugins;
570 if (webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded( 505 if (webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded(
571 &cached_plugins)) { 506 &cached_plugins)) {
572 // Can't assume the caller is reentrant. 507 // Can't assume the caller is reentrant.
573 target_loop->PostTask(FROM_HERE, 508 target_loop->PostTask(FROM_HERE,
574 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); 509 base::Bind(&RunGetPluginsCallback, callback, cached_plugins));
575 } else { 510 } else {
576 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 511 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
577 base::Bind(&PluginLoaderClient::LoadPluginsOutOfProcess, 512 base::Bind(&PluginLoaderPosix::LoadPlugins, target_loop, callback));
578 target_loop, callback));
579 } 513 }
580 #endif 514 #endif
581 } 515 }
582 516
583 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { 517 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) {
584 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); 518 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback));
585 } 519 }
586 520
587 void PluginService::GetPluginsInternal( 521 void PluginService::GetPluginsInternal(
588 base::MessageLoopProxy* target_loop, 522 base::MessageLoopProxy* target_loop,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 #if defined(OS_POSIX) && !defined(OS_MACOSX) 610 #if defined(OS_POSIX) && !defined(OS_MACOSX)
677 // static 611 // static
678 void PluginService::RegisterFilePathWatcher( 612 void PluginService::RegisterFilePathWatcher(
679 FilePathWatcher *watcher, 613 FilePathWatcher *watcher,
680 const FilePath& path, 614 const FilePath& path,
681 FilePathWatcher::Delegate* delegate) { 615 FilePathWatcher::Delegate* delegate) {
682 bool result = watcher->Watch(path, delegate); 616 bool result = watcher->Watch(path, delegate);
683 DCHECK(result); 617 DCHECK(result);
684 } 618 }
685 #endif 619 #endif
OLDNEW
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698