Chromium Code Reviews| 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 LoadPluginsInternal(); | 48 |
| 49 if (!MaybeRunPendingCallbacks()) | |
| 50 LoadPluginsInternal(); | |
|
Bernhard Bauer
2011/10/24 14:57:08
You could have the check for an empty canonical li
Robert Sesek
2011/10/24 16:44:40
Done.
| |
| 49 } | 51 } |
| 50 | 52 |
| 51 bool PluginLoaderPosix::Send(IPC::Message* message) { | 53 bool PluginLoaderPosix::Send(IPC::Message* message) { |
| 52 return process_host_->Send(message); | 54 return process_host_->Send(message); |
| 53 } | 55 } |
| 54 | 56 |
| 55 PluginLoaderPosix::~PluginLoaderPosix() { | 57 PluginLoaderPosix::~PluginLoaderPosix() { |
| 56 } | 58 } |
| 57 | 59 |
| 58 void PluginLoaderPosix::GetPluginsToLoad() { | 60 void PluginLoaderPosix::GetPluginsToLoad() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 LOG(ERROR) << "Received unexpected plugin load message for " | 101 LOG(ERROR) << "Received unexpected plugin load message for " |
| 100 << plugin.path.value(); | 102 << plugin.path.value(); |
| 101 return; | 103 return; |
| 102 } | 104 } |
| 103 | 105 |
| 104 if (!MaybeAddInternalPlugin(plugin.path)) | 106 if (!MaybeAddInternalPlugin(plugin.path)) |
| 105 loaded_plugins_.push_back(plugin); | 107 loaded_plugins_.push_back(plugin); |
| 106 | 108 |
| 107 ++next_load_index_; | 109 ++next_load_index_; |
| 108 | 110 |
| 109 RunPendingCallbacks(); | 111 MaybeRunPendingCallbacks(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void PluginLoaderPosix::OnPluginLoadFailed(const FilePath& plugin_path) { | 114 void PluginLoaderPosix::OnPluginLoadFailed(const FilePath& plugin_path) { |
| 113 if (plugin_path.value() != canonical_list_[next_load_index_].value()) { | 115 if (plugin_path.value() != canonical_list_[next_load_index_].value()) { |
| 114 LOG(ERROR) << "Received unexpected plugin load failure message for " | 116 LOG(ERROR) << "Received unexpected plugin load failure message for " |
| 115 << plugin_path.value(); | 117 << plugin_path.value(); |
| 116 return; | 118 return; |
| 117 } | 119 } |
| 118 | 120 |
| 119 ++next_load_index_; | 121 ++next_load_index_; |
| 120 | 122 |
| 121 MaybeAddInternalPlugin(plugin_path); | 123 MaybeAddInternalPlugin(plugin_path); |
| 122 RunPendingCallbacks(); | 124 MaybeRunPendingCallbacks(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 bool PluginLoaderPosix::MaybeAddInternalPlugin(const FilePath& plugin_path) { | 127 bool PluginLoaderPosix::MaybeAddInternalPlugin(const FilePath& plugin_path) { |
| 126 for (std::vector<webkit::WebPluginInfo>::iterator it = | 128 for (std::vector<webkit::WebPluginInfo>::iterator it = |
| 127 internal_plugins_.begin(); | 129 internal_plugins_.begin(); |
| 128 it != internal_plugins_.end(); | 130 it != internal_plugins_.end(); |
| 129 ++it) { | 131 ++it) { |
| 130 if (it->path == plugin_path) { | 132 if (it->path == plugin_path) { |
| 131 loaded_plugins_.push_back(*it); | 133 loaded_plugins_.push_back(*it); |
| 132 internal_plugins_.erase(it); | 134 internal_plugins_.erase(it); |
| 133 return true; | 135 return true; |
| 134 } | 136 } |
| 135 } | 137 } |
| 136 return false; | 138 return false; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void PluginLoaderPosix::RunPendingCallbacks() { | 141 bool PluginLoaderPosix::MaybeRunPendingCallbacks() { |
| 140 if (next_load_index_ < canonical_list_.size()) | 142 if (next_load_index_ < canonical_list_.size()) |
| 141 return; | 143 return false; |
| 142 | 144 |
| 143 PluginList::Singleton()->SetPlugins(loaded_plugins_); | 145 PluginList::Singleton()->SetPlugins(loaded_plugins_); |
| 144 for (std::vector<PendingCallback>::iterator it = callbacks_.begin(); | 146 for (std::vector<PendingCallback>::iterator it = callbacks_.begin(); |
| 145 it != callbacks_.end(); | 147 it != callbacks_.end(); |
| 146 ++it) { | 148 ++it) { |
| 147 it->target_loop->PostTask(FROM_HERE, | 149 it->target_loop->PostTask(FROM_HERE, |
| 148 base::Bind(it->callback, loaded_plugins_)); | 150 base::Bind(it->callback, loaded_plugins_)); |
| 149 } | 151 } |
| 150 callbacks_.clear(); | 152 callbacks_.clear(); |
| 151 | 153 |
| 152 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone", | 154 HISTOGRAM_TIMES("PluginLoaderPosix.LoadDone", |
| 153 (base::TimeTicks::Now() - load_start_time_) | 155 (base::TimeTicks::Now() - load_start_time_) |
| 154 * base::Time::kMicrosecondsPerMillisecond); | 156 * base::Time::kMicrosecondsPerMillisecond); |
| 155 load_start_time_ = base::TimeTicks(); | 157 load_start_time_ = base::TimeTicks(); |
| 158 | |
| 159 return true; | |
| 156 } | 160 } |
| 157 | 161 |
| 158 PluginLoaderPosix::PendingCallback::PendingCallback( | 162 PluginLoaderPosix::PendingCallback::PendingCallback( |
| 159 scoped_refptr<base::MessageLoopProxy> loop, | 163 scoped_refptr<base::MessageLoopProxy> loop, |
| 160 const PluginService::GetPluginsCallback& cb) | 164 const PluginService::GetPluginsCallback& cb) |
| 161 : target_loop(loop), | 165 : target_loop(loop), |
| 162 callback(cb) { | 166 callback(cb) { |
| 163 } | 167 } |
| 164 | 168 |
| 165 PluginLoaderPosix::PendingCallback::~PendingCallback() { | 169 PluginLoaderPosix::PendingCallback::~PendingCallback() { |
| 166 } | 170 } |
| OLD | NEW |