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

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

Issue 8318028: Gracefully handle child process death in out-of-process plugin loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not send the index 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.h ('k') | content/browser/plugin_loader_posix_unittest.cc » ('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_loader_posix.h" 5 #include "content/browser/plugin_loader_posix.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/metrics/histogram.h"
9 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
10 #include "content/common/utility_messages.h" 12 #include "content/common/utility_messages.h"
11 #include "webkit/plugins/npapi/plugin_list.h" 13 #include "webkit/plugins/npapi/plugin_list.h"
12 14
13 namespace { 15 using webkit::npapi::PluginList;
14 16
15 void RunGetPluginsCallback(const PluginService::GetPluginsCallback& callback, 17 PluginLoaderPosix::PluginLoaderPosix()
16 const std::vector<webkit::WebPluginInfo> plugins) { 18 : next_load_index_(0) {
17 callback.Run(plugins);
18 } 19 }
19 20
20 } // namespace
21
22 // static
23 void PluginLoaderPosix::LoadPlugins( 21 void PluginLoaderPosix::LoadPlugins(
24 base::MessageLoopProxy* target_loop, 22 scoped_refptr<base::MessageLoopProxy> target_loop,
25 const PluginService::GetPluginsCallback& callback) { 23 const PluginService::GetPluginsCallback& callback) {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
27 25
28 PluginLoaderPosix* client = new PluginLoaderPosix(target_loop, callback); 26 callbacks_.push_back(PendingCallback(target_loop, callback));
29 UtilityProcessHost* process_host =
30 new UtilityProcessHost(client, BrowserThread::IO);
31 process_host->set_no_sandbox(true);
32 #if defined(OS_MACOSX)
33 process_host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
34 #endif
35 27
36 std::vector<FilePath> extra_plugin_paths; 28 if (callbacks_.size() == 1) {
37 std::vector<FilePath> extra_plugin_dirs; 29 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
38 std::vector<webkit::WebPluginInfo> internal_plugins; 30 base::Bind(&PluginLoaderPosix::GetPluginsToLoad, this));
39 webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad( 31 }
40 &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins);
41
42 process_host->Send(new UtilityMsg_LoadPlugins(
43 extra_plugin_paths, extra_plugin_dirs, internal_plugins));
44 } 32 }
45 33
46 bool PluginLoaderPosix::OnMessageReceived(const IPC::Message& message) { 34 bool PluginLoaderPosix::OnMessageReceived(const IPC::Message& message) {
47 bool handled = true; 35 bool handled = true;
48 IPC_BEGIN_MESSAGE_MAP(PluginLoaderPosix, message) 36 IPC_BEGIN_MESSAGE_MAP(PluginLoaderPosix, message)
49 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins) 37 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugin, OnPluginLoaded)
38 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadPluginFailed, OnPluginLoadFailed)
50 IPC_MESSAGE_UNHANDLED(handled = false) 39 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP() 40 IPC_END_MESSAGE_MAP()
52 return handled; 41 return handled;
53 } 42 }
54 43
55 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { 44 void PluginLoaderPosix::OnProcessCrashed(int exit_code) {
56 LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code 45 canonical_list_.erase(canonical_list_.begin(),
57 << ". You will have no plugins!"; 46 canonical_list_.begin() + next_load_index_ + 1);
58 // Don't leave callers hanging. 47 next_load_index_ = 0;
59 OnGotPlugins(std::vector<webkit::WebPluginInfo>()); 48 LoadPluginsInternal();
60 } 49 }
61 50
62 PluginLoaderPosix::PluginLoaderPosix( 51 bool PluginLoaderPosix::Send(IPC::Message* message) {
63 base::MessageLoopProxy* target_loop, 52 return process_host_->Send(message);
64 const PluginService::GetPluginsCallback& callback)
65 : target_loop_(target_loop),
66 callback_(callback) {
67 } 53 }
68 54
69 PluginLoaderPosix::~PluginLoaderPosix() { 55 PluginLoaderPosix::~PluginLoaderPosix() {
70 } 56 }
71 57
72 void PluginLoaderPosix::OnGotPlugins( 58 void PluginLoaderPosix::GetPluginsToLoad() {
73 const std::vector<webkit::WebPluginInfo>& plugins) { 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
74 webkit::npapi::PluginList::Singleton()->SetPlugins(plugins); 60
75 target_loop_->PostTask(FROM_HERE, 61 base::TimeTicks start_time(base::TimeTicks::Now());
76 base::Bind(&RunGetPluginsCallback, callback_, plugins)); 62
63 loaded_plugins_.clear();
64 next_load_index_ = 0;
65
66 canonical_list_.clear();
67 webkit::npapi::PluginList::Singleton()->GetPluginPathsToLoad(
68 &canonical_list_);
69
70 internal_plugins_.clear();
71 PluginList::Singleton()->GetInternalPlugins(&internal_plugins_);
72
73 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
74 base::Bind(&PluginLoaderPosix::LoadPluginsInternal,
75 make_scoped_refptr(this)));
76
77 HISTOGRAM_TIMES("PluginLoaderPosix.GetPluginList",
78 (base::TimeTicks::Now() - start_time) *
79 base::Time::kMicrosecondsPerMillisecond);
77 } 80 }
81
82 void PluginLoaderPosix::LoadPluginsInternal() {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
84
85 if (load_start_time_.is_null())
86 load_start_time_ = base::TimeTicks::Now();
87
88 process_host_ = new UtilityProcessHost(this, BrowserThread::IO);
89 process_host_->set_no_sandbox(true);
90 #if defined(OS_MACOSX)
91 process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
92 #endif
93
94 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_));
95 }
96
97 void PluginLoaderPosix::OnPluginLoaded(const webkit::WebPluginInfo& plugin) {
98 if (plugin.path.value() != canonical_list_[next_load_index_].value()) {
99 LOG(ERROR) << "Received unexpected plugin load message for "
100 << plugin.path.value();
101 return;
102 }
103
104 if (!MaybeAddInternalPlugin(plugin.path))
105 loaded_plugins_.push_back(plugin);
106
107 ++next_load_index_;
108
109 RunPendingCallbacks();
110 }
111
112 void PluginLoaderPosix::OnPluginLoadFailed(const FilePath& plugin_path) {
113 if (plugin_path.value() != canonical_list_[next_load_index_].value()) {
114 LOG(ERROR) << "Received unexpected plugin load failure message for "
115 << plugin_path.value();
116 return;
117 }
118
119 ++next_load_index_;
120
121 MaybeAddInternalPlugin(plugin_path);
122 RunPendingCallbacks();
123 }
124
125 bool PluginLoaderPosix::MaybeAddInternalPlugin(const FilePath& plugin_path) {
126 for (std::vector<webkit::WebPluginInfo>::iterator it =
127 internal_plugins_.begin();
128 it != internal_plugins_.end();
129 ++it) {
130 if (it->path == plugin_path) {
131 loaded_plugins_.push_back(*it);
132 internal_plugins_.erase(it);
133 return true;
134 }
135 }
136 return false;
137 }
138
139 void PluginLoaderPosix::RunPendingCallbacks() {
140 if (next_load_index_ < canonical_list_.size())
141 return;
142
143 PluginList::Singleton()->SetPlugins(loaded_plugins_);
144 for (std::vector<PendingCallback>::iterator it = callbacks_.begin();
145 it != callbacks_.end();
146 ++it) {
147 it->target_loop->PostTask(FROM_HERE,
148 base::Bind(it->callback, loaded_plugins_));
149 }
150 callbacks_.clear();
151
152 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone",
153 (base::TimeTicks::Now() - load_start_time_)
154 * base::Time::kMicrosecondsPerMillisecond);
155 load_start_time_ = base::TimeTicks();
156 }
157
158 PluginLoaderPosix::PendingCallback::PendingCallback(
159 scoped_refptr<base::MessageLoopProxy> loop,
160 const PluginService::GetPluginsCallback& cb)
161 : target_loop(loop),
162 callback(cb) {
163 }
164
165 PluginLoaderPosix::PendingCallback::~PendingCallback() {
166 }
OLDNEW
« no previous file with comments | « content/browser/plugin_loader_posix.h ('k') | content/browser/plugin_loader_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698