OLD | NEW |
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.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadPluginFailed, OnPluginLoadFailed) | 38 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadPluginFailed, OnPluginLoadFailed) |
39 IPC_MESSAGE_UNHANDLED(handled = false) | 39 IPC_MESSAGE_UNHANDLED(handled = false) |
40 IPC_END_MESSAGE_MAP() | 40 IPC_END_MESSAGE_MAP() |
41 return handled; | 41 return handled; |
42 } | 42 } |
43 | 43 |
44 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { | 44 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { |
45 canonical_list_.erase(canonical_list_.begin(), | 45 canonical_list_.erase(canonical_list_.begin(), |
46 canonical_list_.begin() + next_load_index_ + 1); | 46 canonical_list_.begin() + next_load_index_ + 1); |
47 next_load_index_ = 0; | 47 next_load_index_ = 0; |
| 48 |
48 LoadPluginsInternal(); | 49 LoadPluginsInternal(); |
49 } | 50 } |
50 | 51 |
51 bool PluginLoaderPosix::Send(IPC::Message* message) { | 52 bool PluginLoaderPosix::Send(IPC::Message* message) { |
52 return process_host_->Send(message); | 53 return process_host_->Send(message); |
53 } | 54 } |
54 | 55 |
55 PluginLoaderPosix::~PluginLoaderPosix() { | 56 PluginLoaderPosix::~PluginLoaderPosix() { |
56 } | 57 } |
57 | 58 |
(...skipping 17 matching lines...) Expand all Loading... |
75 make_scoped_refptr(this))); | 76 make_scoped_refptr(this))); |
76 | 77 |
77 HISTOGRAM_TIMES("PluginLoaderPosix.GetPluginList", | 78 HISTOGRAM_TIMES("PluginLoaderPosix.GetPluginList", |
78 (base::TimeTicks::Now() - start_time) * | 79 (base::TimeTicks::Now() - start_time) * |
79 base::Time::kMicrosecondsPerMillisecond); | 80 base::Time::kMicrosecondsPerMillisecond); |
80 } | 81 } |
81 | 82 |
82 void PluginLoaderPosix::LoadPluginsInternal() { | 83 void PluginLoaderPosix::LoadPluginsInternal() { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
84 | 85 |
| 86 // Check if the list is empty or all plugins have already been loaded before |
| 87 // forking. |
| 88 if (MaybeRunPendingCallbacks()) |
| 89 return; |
| 90 |
85 if (load_start_time_.is_null()) | 91 if (load_start_time_.is_null()) |
86 load_start_time_ = base::TimeTicks::Now(); | 92 load_start_time_ = base::TimeTicks::Now(); |
87 | 93 |
88 process_host_ = new UtilityProcessHost(this, BrowserThread::IO); | 94 process_host_ = new UtilityProcessHost(this, BrowserThread::IO); |
89 process_host_->set_no_sandbox(true); | 95 process_host_->set_no_sandbox(true); |
90 #if defined(OS_MACOSX) | 96 #if defined(OS_MACOSX) |
91 process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); | 97 process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); |
92 #endif | 98 #endif |
93 | 99 |
94 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_)); | 100 process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_)); |
95 } | 101 } |
96 | 102 |
97 void PluginLoaderPosix::OnPluginLoaded(const webkit::WebPluginInfo& plugin) { | 103 void PluginLoaderPosix::OnPluginLoaded(const webkit::WebPluginInfo& plugin) { |
98 if (plugin.path.value() != canonical_list_[next_load_index_].value()) { | 104 if (plugin.path.value() != canonical_list_[next_load_index_].value()) { |
99 LOG(ERROR) << "Received unexpected plugin load message for " | 105 LOG(ERROR) << "Received unexpected plugin load message for " |
100 << plugin.path.value(); | 106 << plugin.path.value(); |
101 return; | 107 return; |
102 } | 108 } |
103 | 109 |
104 if (!MaybeAddInternalPlugin(plugin.path)) | 110 if (!MaybeAddInternalPlugin(plugin.path)) |
105 loaded_plugins_.push_back(plugin); | 111 loaded_plugins_.push_back(plugin); |
106 | 112 |
107 ++next_load_index_; | 113 ++next_load_index_; |
108 | 114 |
109 RunPendingCallbacks(); | 115 MaybeRunPendingCallbacks(); |
110 } | 116 } |
111 | 117 |
112 void PluginLoaderPosix::OnPluginLoadFailed(const FilePath& plugin_path) { | 118 void PluginLoaderPosix::OnPluginLoadFailed(const FilePath& plugin_path) { |
113 if (plugin_path.value() != canonical_list_[next_load_index_].value()) { | 119 if (plugin_path.value() != canonical_list_[next_load_index_].value()) { |
114 LOG(ERROR) << "Received unexpected plugin load failure message for " | 120 LOG(ERROR) << "Received unexpected plugin load failure message for " |
115 << plugin_path.value(); | 121 << plugin_path.value(); |
116 return; | 122 return; |
117 } | 123 } |
118 | 124 |
119 ++next_load_index_; | 125 ++next_load_index_; |
120 | 126 |
121 MaybeAddInternalPlugin(plugin_path); | 127 MaybeAddInternalPlugin(plugin_path); |
122 RunPendingCallbacks(); | 128 MaybeRunPendingCallbacks(); |
123 } | 129 } |
124 | 130 |
125 bool PluginLoaderPosix::MaybeAddInternalPlugin(const FilePath& plugin_path) { | 131 bool PluginLoaderPosix::MaybeAddInternalPlugin(const FilePath& plugin_path) { |
126 for (std::vector<webkit::WebPluginInfo>::iterator it = | 132 for (std::vector<webkit::WebPluginInfo>::iterator it = |
127 internal_plugins_.begin(); | 133 internal_plugins_.begin(); |
128 it != internal_plugins_.end(); | 134 it != internal_plugins_.end(); |
129 ++it) { | 135 ++it) { |
130 if (it->path == plugin_path) { | 136 if (it->path == plugin_path) { |
131 loaded_plugins_.push_back(*it); | 137 loaded_plugins_.push_back(*it); |
132 internal_plugins_.erase(it); | 138 internal_plugins_.erase(it); |
133 return true; | 139 return true; |
134 } | 140 } |
135 } | 141 } |
136 return false; | 142 return false; |
137 } | 143 } |
138 | 144 |
139 void PluginLoaderPosix::RunPendingCallbacks() { | 145 bool PluginLoaderPosix::MaybeRunPendingCallbacks() { |
140 if (next_load_index_ < canonical_list_.size()) | 146 if (next_load_index_ < canonical_list_.size()) |
141 return; | 147 return false; |
142 | 148 |
143 PluginList::Singleton()->SetPlugins(loaded_plugins_); | 149 PluginList::Singleton()->SetPlugins(loaded_plugins_); |
144 for (std::vector<PendingCallback>::iterator it = callbacks_.begin(); | 150 for (std::vector<PendingCallback>::iterator it = callbacks_.begin(); |
145 it != callbacks_.end(); | 151 it != callbacks_.end(); |
146 ++it) { | 152 ++it) { |
147 it->target_loop->PostTask(FROM_HERE, | 153 it->target_loop->PostTask(FROM_HERE, |
148 base::Bind(it->callback, loaded_plugins_)); | 154 base::Bind(it->callback, loaded_plugins_)); |
149 } | 155 } |
150 callbacks_.clear(); | 156 callbacks_.clear(); |
151 | 157 |
152 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone", | 158 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone", |
153 (base::TimeTicks::Now() - load_start_time_) | 159 (base::TimeTicks::Now() - load_start_time_) |
154 * base::Time::kMicrosecondsPerMillisecond); | 160 * base::Time::kMicrosecondsPerMillisecond); |
155 load_start_time_ = base::TimeTicks(); | 161 load_start_time_ = base::TimeTicks(); |
| 162 |
| 163 return true; |
156 } | 164 } |
157 | 165 |
158 PluginLoaderPosix::PendingCallback::PendingCallback( | 166 PluginLoaderPosix::PendingCallback::PendingCallback( |
159 scoped_refptr<base::MessageLoopProxy> loop, | 167 scoped_refptr<base::MessageLoopProxy> loop, |
160 const PluginService::GetPluginsCallback& cb) | 168 const PluginService::GetPluginsCallback& cb) |
161 : target_loop(loop), | 169 : target_loop(loop), |
162 callback(cb) { | 170 callback(cb) { |
163 } | 171 } |
164 | 172 |
165 PluginLoaderPosix::PendingCallback::~PendingCallback() { | 173 PluginLoaderPosix::PendingCallback::~PendingCallback() { |
166 } | 174 } |
OLD | NEW |