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 |
| 144 instance_observers_map_.set( |
| 145 instance, make_scoped_ptr(new ObserverList<InstanceObserver>())); |
143 } | 146 } |
144 | 147 |
145 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { | 148 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
146 InstanceMap::iterator found = instance_map_.find(instance); | 149 InstanceMap::iterator found = instance_map_.find(instance); |
147 if (found == instance_map_.end()) { | 150 if (found == instance_map_.end()) { |
148 NOTREACHED(); | 151 NOTREACHED(); |
149 return; | 152 return; |
150 } | 153 } |
151 instance_map_.erase(found); | 154 instance_map_.erase(found); |
| 155 |
| 156 DCHECK(instance_observers_map_.get(instance)); |
| 157 instance_observers_map_.erase(instance); |
| 158 } |
| 159 |
| 160 void BrowserPpapiHostImpl::AddInstanceObserver(PP_Instance instance, |
| 161 InstanceObserver* observer) { |
| 162 instance_observers_map_.get(instance)->AddObserver(observer); |
| 163 } |
| 164 |
| 165 void BrowserPpapiHostImpl::RemoveInstanceObserver(PP_Instance instance, |
| 166 InstanceObserver* observer) { |
| 167 auto* instance_observer = instance_observers_map_.get(instance); |
| 168 if (instance_observer != nullptr) |
| 169 instance_observer->RemoveObserver(observer); |
| 170 } |
| 171 |
| 172 void BrowserPpapiHostImpl::OnThrottleStateChanged(PP_Instance instance, |
| 173 bool is_throttled) { |
| 174 auto found = instance_map_.find(instance); |
| 175 if (found != instance_map_.end()) |
| 176 found->second.is_throttled = is_throttled; |
| 177 |
| 178 auto* instance_observer = instance_observers_map_.get(instance); |
| 179 if (instance_observer != nullptr) { |
| 180 FOR_EACH_OBSERVER(InstanceObserver, *instance_observer, |
| 181 OnThrottleStateChanged(is_throttled)); |
| 182 } |
| 183 } |
| 184 |
| 185 bool BrowserPpapiHostImpl::IsThrottled(PP_Instance instance) const { |
| 186 auto found = instance_map_.find(instance); |
| 187 if (found != instance_map_.end()) { |
| 188 return found->second.is_throttled; |
| 189 } |
| 190 return false; |
152 } | 191 } |
153 | 192 |
154 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( | 193 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( |
155 ppapi::host::PpapiHost* ppapi_host, | 194 ppapi::host::PpapiHost* ppapi_host, |
156 BrowserPpapiHostImpl* browser_ppapi_host_impl) | 195 BrowserPpapiHostImpl* browser_ppapi_host_impl) |
157 : ppapi_host_(ppapi_host), | 196 : ppapi_host_(ppapi_host), |
158 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} | 197 browser_ppapi_host_impl_(browser_ppapi_host_impl) {} |
159 | 198 |
160 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( | 199 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( |
161 const IPC::Message& msg) { | 200 const IPC::Message& msg) { |
(...skipping 23 matching lines...) Expand all Loading... |
185 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { | 224 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() { |
186 if (browser_ppapi_host_impl_) | 225 if (browser_ppapi_host_impl_) |
187 browser_ppapi_host_impl_->OnKeepalive(); | 226 browser_ppapi_host_impl_->OnKeepalive(); |
188 } | 227 } |
189 | 228 |
190 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( | 229 void BrowserPpapiHostImpl::HostMessageFilter::OnHostMsgLogInterfaceUsage( |
191 int hash) const { | 230 int hash) const { |
192 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); | 231 UMA_HISTOGRAM_SPARSE_SLOWLY("Pepper.InterfaceUsed", hash); |
193 } | 232 } |
194 | 233 |
| 234 BrowserPpapiHostImpl::InstanceData::InstanceData() : is_throttled(false) { |
| 235 } |
| 236 |
| 237 BrowserPpapiHostImpl::InstanceData::~InstanceData() { |
| 238 } |
| 239 |
195 void BrowserPpapiHostImpl::OnKeepalive() { | 240 void BrowserPpapiHostImpl::OnKeepalive() { |
196 // An instance has been active. The on_keepalive_callback_ will be | 241 // 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 | 242 // used to permit the content embedder to handle this, e.g. by tracking |
198 // activity and shutting down processes that go idle. | 243 // activity and shutting down processes that go idle. |
199 // | 244 // |
200 // Currently embedders do not need to distinguish between instances having | 245 // Currently embedders do not need to distinguish between instances having |
201 // different idle state, and thus this implementation handles all instances | 246 // different idle state, and thus this implementation handles all instances |
202 // for this module together. | 247 // for this module together. |
203 | 248 |
204 if (on_keepalive_callback_.is_null()) | 249 if (on_keepalive_callback_.is_null()) |
205 return; | 250 return; |
206 | 251 |
207 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); | 252 BrowserPpapiHost::OnKeepaliveInstanceData instance_data(instance_map_.size()); |
208 | 253 |
209 InstanceMap::iterator instance = instance_map_.begin(); | 254 InstanceMap::iterator instance = instance_map_.begin(); |
210 int i = 0; | 255 int i = 0; |
211 while (instance != instance_map_.end()) { | 256 while (instance != instance_map_.end()) { |
212 instance_data[i].render_process_id = instance->second.render_process_id; | 257 instance_data[i].render_process_id = |
213 instance_data[i].render_frame_id = instance->second.render_frame_id; | 258 instance->second.renderer_data.render_process_id; |
214 instance_data[i].document_url = instance->second.document_url; | 259 instance_data[i].render_frame_id = |
| 260 instance->second.renderer_data.render_frame_id; |
| 261 instance_data[i].document_url = instance->second.renderer_data.document_url; |
215 ++instance; | 262 ++instance; |
216 ++i; | 263 ++i; |
217 } | 264 } |
218 on_keepalive_callback_.Run(instance_data, profile_data_directory_); | 265 on_keepalive_callback_.Run(instance_data, profile_data_directory_); |
219 } | 266 } |
220 | 267 |
221 } // namespace content | 268 } // namespace content |
OLD | NEW |