| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return ppapi_host_.get(); | 78 return ppapi_host_.get(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 const base::Process& BrowserPpapiHostImpl::GetPluginProcess() const { | 81 const base::Process& BrowserPpapiHostImpl::GetPluginProcess() const { |
| 82 // Handle should previously have been set before use. | 82 // Handle should previously have been set before use. |
| 83 DCHECK(in_process_ || plugin_process_.IsValid()); | 83 DCHECK(in_process_ || plugin_process_.IsValid()); |
| 84 return plugin_process_; | 84 return plugin_process_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool BrowserPpapiHostImpl::IsValidInstance(PP_Instance instance) const { | 87 bool BrowserPpapiHostImpl::IsValidInstance(PP_Instance instance) const { |
| 88 return instance_map_.find(instance) != instance_map_.end(); | 88 return instance_map_.contains(instance); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool BrowserPpapiHostImpl::GetRenderFrameIDsForInstance( | 91 bool BrowserPpapiHostImpl::GetRenderFrameIDsForInstance( |
| 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 auto* data = instance_map_.get(instance); |
| 96 if (found == instance_map_.end()) { | 96 if (data == nullptr) { |
| 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 = data->renderer_data.render_process_id; |
| 103 *render_frame_id = found->second.render_frame_id; | 103 *render_frame_id = data->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 auto* data = instance_map_.get(instance); |
| 121 if (found == instance_map_.end()) | 121 if (data == nullptr) |
| 122 return GURL(); | 122 return GURL(); |
| 123 return found->second.document_url; | 123 return data->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 auto* data = instance_map_.get(instance); |
| 128 if (found == instance_map_.end()) | 128 if (data == nullptr) |
| 129 return GURL(); | 129 return GURL(); |
| 130 return found->second.plugin_url; | 130 return data->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& renderer_instance_data) { |
| 141 DCHECK(instance_map_.find(instance) == instance_map_.end()); | 141 DCHECK(!instance_map_.contains(instance)); |
| 142 instance_map_[instance] = instance_data; | 142 instance_map_.add(instance, |
| 143 make_scoped_ptr(new InstanceData(renderer_instance_data))); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { | 146 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
| 146 InstanceMap::iterator found = instance_map_.find(instance); | 147 int erased = instance_map_.erase(instance); |
| 147 if (found == instance_map_.end()) { | 148 DCHECK_EQ(1, erased); |
| 148 NOTREACHED(); | 149 } |
| 149 return; | 150 |
| 151 void BrowserPpapiHostImpl::AddInstanceObserver(PP_Instance instance, |
| 152 InstanceObserver* observer) { |
| 153 instance_map_.get(instance)->observer_list.AddObserver(observer); |
| 154 } |
| 155 |
| 156 void BrowserPpapiHostImpl::RemoveInstanceObserver(PP_Instance instance, |
| 157 InstanceObserver* observer) { |
| 158 auto* data = instance_map_.get(instance); |
| 159 if (data) |
| 160 data->observer_list.RemoveObserver(observer); |
| 161 } |
| 162 |
| 163 void BrowserPpapiHostImpl::OnThrottleStateChanged(PP_Instance instance, |
| 164 bool is_throttled) { |
| 165 auto* data = instance_map_.get(instance); |
| 166 if (data) { |
| 167 data->is_throttled = is_throttled; |
| 168 FOR_EACH_OBSERVER(InstanceObserver, data->observer_list, |
| 169 OnThrottleStateChanged(is_throttled)); |
| 150 } | 170 } |
| 151 instance_map_.erase(found); | 171 } |
| 172 |
| 173 bool BrowserPpapiHostImpl::IsThrottled(PP_Instance instance) const { |
| 174 auto* data = instance_map_.get(instance); |
| 175 if (data) |
| 176 return data->is_throttled; |
| 177 |
| 178 return false; |
| 152 } | 179 } |
| 153 | 180 |
| 154 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( | 181 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( |
| 155 ppapi::host::PpapiHost* ppapi_host, | 182 ppapi::host::PpapiHost* ppapi_host, |
| 156 BrowserPpapiHostImpl* browser_ppapi_host_impl) | 183 BrowserPpapiHostImpl* browser_ppapi_host_impl) |
| 157 : ppapi_host_(ppapi_host), | 184 : ppapi_host_(ppapi_host), |
| 158 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} | 185 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} |
| 159 | 186 |
| 160 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 187 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
| 161 const IPC::Message& msg) { | 188 const IPC::Message& msg) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 185 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { | 212 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { |
| 186 if (browser_ppapi_host_impl_) | 213 if (browser_ppapi_host_impl_) |
| 187 browser_ppapi_host_impl_->OnKeepalive(); | 214 browser_ppapi_host_impl_->OnKeepalive(); |
| 188 } | 215 } |
| 189 | 216 |
| 190 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( | 217 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( |
| 191 int hash) const { | 218 int hash) const { |
| 192 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); | 219 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); |
| 193 } | 220 } |
| 194 | 221 |
| 222 BrowserPpapiHostImpl::InstanceData::InstanceData( |
| 223 const PepperRendererInstanceData& renderer_data) |
| 224 : renderer_data(renderer_data), is_throttled(false) { |
| 225 } |
| 226 |
| 227 BrowserPpapiHostImpl::InstanceData::~InstanceData() { |
| 228 } |
| 229 |
| 195 void BrowserPpapiHostImpl::OnKeepalive() { | 230 void BrowserPpapiHostImpl::OnKeepalive() { |
| 196 // An instance has been active. The on_keepalive_callback_ will be | 231 // 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 | 232 // used to permit the content embedder to handle this, e.g. by tracking |
| 198 // activity and shutting down processes that go idle. | 233 // activity and shutting down processes that go idle. |
| 199 // | 234 // |
| 200 // Currently embedders do not need to distinguish between instances having | 235 // Currently embedders do not need to distinguish between instances having |
| 201 // different idle state, and thus this implementation handles all instances | 236 // different idle state, and thus this implementation handles all instances |
| 202 // for this module together. | 237 // for this module together. |
| 203 | 238 |
| 204 if (on_keepalive_callback_.is_null()) | 239 if (on_keepalive_callback_.is_null()) |
| 205 return; | 240 return; |
| 206 | 241 |
| 207 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); | 242 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); |
| 208 | 243 |
| 209 InstanceMap::iterator instance = instance_map_.begin(); | 244 auto instance = instance_map_.begin(); |
| 210 int i = 0; | 245 int i = 0; |
| 211 while (instance != instance_map_.end()) { | 246 while (instance != instance_map_.end()) { |
| 212 instance_data[i].render_process_id = instance->second.render_process_id; | 247 instance_data[i].render_process_id = |
| 213 instance_data[i].render_frame_id = instance->second.render_frame_id; | 248 instance->second->renderer_data.render_process_id; |
| 214 instance_data[i].document_url = instance->second.document_url; | 249 instance_data[i].render_frame_id = |
| 250 instance->second->renderer_data.render_frame_id; |
| 251 instance_data[i].document_url = |
| 252 instance->second->renderer_data.document_url; |
| 215 ++instance; | 253 ++instance; |
| 216 ++i; | 254 ++i; |
| 217 } | 255 } |
| 218 on_keepalive_callback_.Run(instance_data, profile_data_directory_); | 256 on_keepalive_callback_.Run(instance_data, profile_data_directory_); |
| 219 } | 257 } |
| 220 | 258 |
| 221 } // namespace content | 259 } // namespace content |
| OLD | NEW |