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