Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/pepper/browser_ppapi_host_impl.h" | 5 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
| 6 | 6 |
| 7 #include "base/metrics/sparse_histogram.h" | 7 #include "base/metrics/sparse_histogram.h" |
| 8 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 8 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
| 9 #include "content/browser/tracing/trace_message_filter.h" | 9 #include "content/browser/tracing/trace_message_filter.h" |
| 10 #include "content/common/pepper_renderer_instance_data.h" | 10 #include "content/common/pepper_renderer_instance_data.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 PP_Instance instance, | 92 PP_Instance instance, |
| 93 int* render_process_id, | 93 int* render_process_id, |
| 94 int* render_frame_id) const { | 94 int* render_frame_id) const { |
| 95 InstanceMap::const_iterator found = instance_map_.find(instance); | 95 InstanceMap::const_iterator found = instance_map_.find(instance); |
| 96 if (found == instance_map_.end()) { | 96 if (found == instance_map_.end()) { |
| 97 *render_process_id = 0; | 97 *render_process_id = 0; |
| 98 *render_frame_id = 0; | 98 *render_frame_id = 0; |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 *render_process_id = found->second.render_process_id; | 102 *render_process_id = found->second.renderer_data.render_process_id; |
| 103 *render_frame_id = found->second.render_frame_id; | 103 *render_frame_id = found->second.renderer_data.render_frame_id; |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 const std::string& BrowserPpapiHostImpl::GetPluginName() { | 107 const std::string& BrowserPpapiHostImpl::GetPluginName() { |
| 108 return plugin_name_; | 108 return plugin_name_; |
| 109 } | 109 } |
| 110 | 110 |
| 111 const base::FilePath& BrowserPpapiHostImpl::GetPluginPath() { | 111 const base::FilePath& BrowserPpapiHostImpl::GetPluginPath() { |
| 112 return plugin_path_; | 112 return plugin_path_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 const base::FilePath& BrowserPpapiHostImpl::GetProfileDataDirectory() { | 115 const base::FilePath& BrowserPpapiHostImpl::GetProfileDataDirectory() { |
| 116 return profile_data_directory_; | 116 return profile_data_directory_; |
| 117 } | 117 } |
| 118 | 118 |
| 119 GURL BrowserPpapiHostImpl::GetDocumentURLForInstance(PP_Instance instance) { | 119 GURL BrowserPpapiHostImpl::GetDocumentURLForInstance(PP_Instance instance) { |
| 120 InstanceMap::const_iterator found = instance_map_.find(instance); | 120 InstanceMap::const_iterator found = instance_map_.find(instance); |
| 121 if (found == instance_map_.end()) | 121 if (found == instance_map_.end()) |
| 122 return GURL(); | 122 return GURL(); |
| 123 return found->second.document_url; | 123 return found->second.renderer_data.document_url; |
| 124 } | 124 } |
| 125 | 125 |
| 126 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { | 126 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { |
| 127 InstanceMap::const_iterator found = instance_map_.find(instance); | 127 InstanceMap::const_iterator found = instance_map_.find(instance); |
| 128 if (found == instance_map_.end()) | 128 if (found == instance_map_.end()) |
| 129 return GURL(); | 129 return GURL(); |
| 130 return found->second.plugin_url; | 130 return found->second.renderer_data.plugin_url; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void BrowserPpapiHostImpl::SetOnKeepaliveCallback( | 133 void BrowserPpapiHostImpl::SetOnKeepaliveCallback( |
| 134 const BrowserPpapiHost::OnKeepaliveCallback& callback) { | 134 const BrowserPpapiHost::OnKeepaliveCallback& callback) { |
| 135 on_keepalive_callback_ = callback; | 135 on_keepalive_callback_ = callback; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void BrowserPpapiHostImpl::AddInstance( | 138 void BrowserPpapiHostImpl::AddInstance( |
| 139 PP_Instance instance, | 139 PP_Instance instance, |
| 140 const PepperRendererInstanceData& instance_data) { | 140 const PepperRendererInstanceData& instance_data) { |
| 141 DCHECK(instance_map_.find(instance) == instance_map_.end()); | 141 DCHECK(instance_map_.find(instance) == instance_map_.end()); |
| 142 instance_map_[instance] = instance_data; | 142 instance_map_[instance].renderer_data = instance_data; |
| 143 instance_map_[instance].observer_list.reset( | |
| 144 new ObserverList<InstanceObserver>()); | |
|
dmichael (off chromium)
2015/02/18 18:58:09
If you use map::insert, I believe your value type
tommycli
2015/02/18 19:19:09
Hey, I tried what you recommended in PS6, but I co
dmichael (off chromium)
2015/02/18 20:31:39
Bummer.
How about ScoperPtrHashMap instead, then?
tommycli
2015/02/18 21:31:17
Done.
| |
| 143 } | 145 } |
| 144 | 146 |
| 145 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { | 147 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
| 146 InstanceMap::iterator found = instance_map_.find(instance); | 148 InstanceMap::iterator found = instance_map_.find(instance); |
| 147 if (found == instance_map_.end()) { | 149 if (found == instance_map_.end()) { |
| 148 NOTREACHED(); | 150 NOTREACHED(); |
| 149 return; | 151 return; |
| 150 } | 152 } |
| 151 instance_map_.erase(found); | 153 instance_map_.erase(found); |
| 152 } | 154 } |
| 153 | 155 |
| 156 void BrowserPpapiHostImpl::AddInstanceObserver(PP_Instance instance, | |
| 157 InstanceObserver* observer) { | |
| 158 DCHECK(instance_map_.find(instance) != instance_map_.end()); | |
| 159 instance_map_[instance].observer_list->AddObserver(observer); | |
| 160 } | |
| 161 | |
| 162 void BrowserPpapiHostImpl::RemoveInstanceObserver(PP_Instance instance, | |
| 163 InstanceObserver* observer) { | |
| 164 InstanceMap::iterator found = instance_map_.find(instance); | |
| 165 if (found != instance_map_.end()) { | |
| 166 found->second.observer_list->RemoveObserver(observer); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void BrowserPpapiHostImpl::OnThrottleStateChanged(PP_Instance instance, | |
| 171 bool is_throttled) { | |
| 172 auto found = instance_map_.find(instance); | |
| 173 if (found != instance_map_.end()) { | |
| 174 found->second.is_throttled = is_throttled; | |
| 175 FOR_EACH_OBSERVER(InstanceObserver, *(found->second.observer_list), | |
| 176 OnThrottleStateChanged(is_throttled)); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 bool BrowserPpapiHostImpl::IsThrottled(PP_Instance instance) const { | |
| 181 auto found = instance_map_.find(instance); | |
| 182 if (found != instance_map_.end()) { | |
| 183 return found->second.is_throttled; | |
| 184 } | |
| 185 return false; | |
| 186 } | |
| 187 | |
| 154 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( | 188 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( |
| 155 ppapi::host::PpapiHost* ppapi_host, | 189 ppapi::host::PpapiHost* ppapi_host, |
| 156 BrowserPpapiHostImpl* browser_ppapi_host_impl) | 190 BrowserPpapiHostImpl* browser_ppapi_host_impl) |
| 157 : ppapi_host_(ppapi_host), | 191 : ppapi_host_(ppapi_host), |
| 158 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} | 192 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} |
| 159 | 193 |
| 160 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 194 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
| 161 const IPC::Message& msg) { | 195 const IPC::Message& msg) { |
| 162 // Don't forward messages if our owner object has been destroyed. | 196 // Don't forward messages if our owner object has been destroyed. |
| 163 if (!ppapi_host_) | 197 if (!ppapi_host_) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 185 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { | 219 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { |
| 186 if (browser_ppapi_host_impl_) | 220 if (browser_ppapi_host_impl_) |
| 187 browser_ppapi_host_impl_->OnKeepalive(); | 221 browser_ppapi_host_impl_->OnKeepalive(); |
| 188 } | 222 } |
| 189 | 223 |
| 190 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( | 224 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( |
| 191 int hash) const { | 225 int hash) const { |
| 192 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); | 226 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); |
| 193 } | 227 } |
| 194 | 228 |
| 229 BrowserPpapiHostImpl::InstanceData::InstanceData() : is_throttled(false) { | |
| 230 } | |
| 231 | |
| 232 BrowserPpapiHostImpl::InstanceData::~InstanceData() { | |
| 233 } | |
| 234 | |
| 195 void BrowserPpapiHostImpl::OnKeepalive() { | 235 void BrowserPpapiHostImpl::OnKeepalive() { |
| 196 // An instance has been active. The on_keepalive_callback_ will be | 236 // An instance has been active. The on_keepalive_callback_ will be |
| 197 // used to permit the content embedder to handle this, e.g. by tracking | 237 // used to permit the content embedder to handle this, e.g. by tracking |
| 198 // activity and shutting down processes that go idle. | 238 // activity and shutting down processes that go idle. |
| 199 // | 239 // |
| 200 // Currently embedders do not need to distinguish between instances having | 240 // Currently embedders do not need to distinguish between instances having |
| 201 // different idle state, and thus this implementation handles all instances | 241 // different idle state, and thus this implementation handles all instances |
| 202 // for this module together. | 242 // for this module together. |
| 203 | 243 |
| 204 if (on_keepalive_callback_.is_null()) | 244 if (on_keepalive_callback_.is_null()) |
| 205 return; | 245 return; |
| 206 | 246 |
| 207 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); | 247 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); |
| 208 | 248 |
| 209 InstanceMap::iterator instance = instance_map_.begin(); | 249 InstanceMap::iterator instance = instance_map_.begin(); |
| 210 int i = 0; | 250 int i = 0; |
| 211 while (instance != instance_map_.end()) { | 251 while (instance != instance_map_.end()) { |
| 212 instance_data[i].render_process_id = instance->second.render_process_id; | 252 instance_data[i].render_process_id = |
| 213 instance_data[i].render_frame_id = instance->second.render_frame_id; | 253 instance->second.renderer_data.render_process_id; |
| 214 instance_data[i].document_url = instance->second.document_url; | 254 instance_data[i].render_frame_id = |
| 255 instance->second.renderer_data.render_frame_id; | |
| 256 instance_data[i].document_url = instance->second.renderer_data.document_url; | |
| 215 ++instance; | 257 ++instance; |
| 216 ++i; | 258 ++i; |
| 217 } | 259 } |
| 218 on_keepalive_callback_.Run(instance_data, profile_data_directory_); | 260 on_keepalive_callback_.Run(instance_data, profile_data_directory_); |
| 219 } | 261 } |
| 220 | 262 |
| 221 } // namespace content | 263 } // namespace content |
| OLD | NEW |