OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/metrics/plugin_metrics_provider.h" | 5 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 217 |
218 base::DictionaryValue* plugin_dict = | 218 base::DictionaryValue* plugin_dict = |
219 static_cast<base::DictionaryValue*>(*value_iter); | 219 static_cast<base::DictionaryValue*>(*value_iter); |
220 std::string plugin_name; | 220 std::string plugin_name; |
221 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); | 221 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
222 if (plugin_name.empty()) { | 222 if (plugin_name.empty()) { |
223 NOTREACHED(); | 223 NOTREACHED(); |
224 continue; | 224 continue; |
225 } | 225 } |
226 | 226 |
227 // TODO(viettrungluu): remove conversions | 227 if (child_process_stats_buffer_.find(plugin_name) == |
228 base::string16 name16 = base::UTF8ToUTF16(plugin_name); | |
229 if (child_process_stats_buffer_.find(name16) == | |
230 child_process_stats_buffer_.end()) { | 228 child_process_stats_buffer_.end()) { |
231 continue; | 229 continue; |
232 } | 230 } |
233 | 231 |
234 ChildProcessStats stats = child_process_stats_buffer_[name16]; | 232 ChildProcessStats stats = child_process_stats_buffer_[plugin_name]; |
235 if (stats.process_launches) { | 233 if (stats.process_launches) { |
236 int launches = 0; | 234 int launches = 0; |
237 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); | 235 plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
238 launches += stats.process_launches; | 236 launches += stats.process_launches; |
239 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches); | 237 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, launches); |
240 } | 238 } |
241 if (stats.process_crashes) { | 239 if (stats.process_crashes) { |
242 int crashes = 0; | 240 int crashes = 0; |
243 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); | 241 plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
244 crashes += stats.process_crashes; | 242 crashes += stats.process_crashes; |
245 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes); | 243 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, crashes); |
246 } | 244 } |
247 if (stats.instances) { | 245 if (stats.instances) { |
248 int instances = 0; | 246 int instances = 0; |
249 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); | 247 plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
250 instances += stats.instances; | 248 instances += stats.instances; |
251 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances); | 249 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, instances); |
252 } | 250 } |
253 if (stats.loading_errors) { | 251 if (stats.loading_errors) { |
254 int loading_errors = 0; | 252 int loading_errors = 0; |
255 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, | 253 plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, |
256 &loading_errors); | 254 &loading_errors); |
257 loading_errors += stats.loading_errors; | 255 loading_errors += stats.loading_errors; |
258 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | 256 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, |
259 loading_errors); | 257 loading_errors); |
260 } | 258 } |
261 | 259 |
262 child_process_stats_buffer_.erase(name16); | 260 child_process_stats_buffer_.erase(plugin_name); |
263 } | 261 } |
264 | 262 |
265 // Now go through and add dictionaries for plugins that didn't already have | 263 // Now go through and add dictionaries for plugins that didn't already have |
266 // reports in Local State. | 264 // reports in Local State. |
267 for (std::map<base::string16, ChildProcessStats>::iterator cache_iter = | 265 for (std::map<std::string, ChildProcessStats>::iterator cache_iter = |
Ilya Sherman
2015/10/16 22:09:33
nit: Please update this type to be "auto"
Deepak
2015/10/18 05:59:41
Done.
| |
268 child_process_stats_buffer_.begin(); | 266 child_process_stats_buffer_.begin(); |
269 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { | 267 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { |
270 ChildProcessStats stats = cache_iter->second; | 268 ChildProcessStats stats = cache_iter->second; |
271 | 269 |
272 // Insert only plugins information into the plugins list. | 270 // Insert only plugins information into the plugins list. |
273 if (!IsPluginProcess(stats.process_type)) | 271 if (!IsPluginProcess(stats.process_type)) |
274 continue; | 272 continue; |
275 | 273 |
276 // TODO(viettrungluu): remove conversion | |
277 std::string plugin_name = base::UTF16ToUTF8(cache_iter->first); | |
278 | |
279 base::DictionaryValue* plugin_dict = new base::DictionaryValue; | 274 base::DictionaryValue* plugin_dict = new base::DictionaryValue; |
280 | 275 |
281 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); | 276 plugin_dict->SetString(prefs::kStabilityPluginName, cache_iter->first); |
282 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, | 277 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, |
283 stats.process_launches); | 278 stats.process_launches); |
284 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, | 279 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, |
285 stats.process_crashes); | 280 stats.process_crashes); |
286 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | 281 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, |
287 stats.instances); | 282 stats.instances); |
288 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | 283 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, |
289 stats.loading_errors); | 284 stats.loading_errors); |
290 plugins->Append(plugin_dict); | 285 plugins->Append(plugin_dict); |
291 } | 286 } |
292 child_process_stats_buffer_.clear(); | 287 child_process_stats_buffer_.clear(); |
293 } | 288 } |
294 | 289 |
295 void PluginMetricsProvider::LogPluginLoadingError( | 290 void PluginMetricsProvider::LogPluginLoadingError( |
296 const base::FilePath& plugin_path) { | 291 const base::FilePath& plugin_path) { |
297 content::WebPluginInfo plugin; | 292 content::WebPluginInfo plugin; |
298 bool success = | 293 bool success = |
299 content::PluginService::GetInstance()->GetPluginInfoByPath(plugin_path, | 294 content::PluginService::GetInstance()->GetPluginInfoByPath(plugin_path, |
300 &plugin); | 295 &plugin); |
301 DCHECK(success); | 296 DCHECK(success); |
302 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; | 297 ChildProcessStats& stats = |
298 child_process_stats_buffer_[base::UTF16ToUTF8(plugin.name)]; | |
303 // Initialize the type if this entry is new. | 299 // Initialize the type if this entry is new. |
304 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | 300 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { |
305 // The plugin process might not actually be of type PLUGIN (which means | 301 // The plugin process might not actually be of type PLUGIN (which means |
306 // NPAPI), but we only care that it is *a* plugin process. | 302 // NPAPI), but we only care that it is *a* plugin process. |
307 stats.process_type = content::PROCESS_TYPE_PLUGIN; | 303 stats.process_type = content::PROCESS_TYPE_PLUGIN; |
308 } else { | 304 } else { |
309 DCHECK(IsPluginProcess(stats.process_type)); | 305 DCHECK(IsPluginProcess(stats.process_type)); |
310 } | 306 } |
311 stats.loading_errors++; | 307 stats.loading_errors++; |
312 RecordCurrentStateWithDelay(kRecordStateDelayMs); | 308 RecordCurrentStateWithDelay(kRecordStateDelayMs); |
(...skipping 17 matching lines...) Expand all Loading... | |
330 } | 326 } |
331 | 327 |
332 void PluginMetricsProvider::OnGotPlugins( | 328 void PluginMetricsProvider::OnGotPlugins( |
333 const base::Closure& done_callback, | 329 const base::Closure& done_callback, |
334 const std::vector<content::WebPluginInfo>& plugins) { | 330 const std::vector<content::WebPluginInfo>& plugins) { |
335 plugins_ = plugins; | 331 plugins_ = plugins; |
336 done_callback.Run(); | 332 done_callback.Run(); |
337 } | 333 } |
338 | 334 |
339 PluginMetricsProvider::ChildProcessStats& | 335 PluginMetricsProvider::ChildProcessStats& |
340 PluginMetricsProvider::GetChildProcessStats( | 336 PluginMetricsProvider::GetChildProcessStats( |
Ilya Sherman
2015/10/16 22:09:33
This method is fairly frequently called, so I'm no
Deepak
2015/10/18 05:59:41
I understand, It is best if we can avoid all strin
Ilya Sherman
2015/10/20 06:24:32
What makes you say that PluginMetricsProvider::Rec
| |
341 const content::ChildProcessData& data) { | 337 const content::ChildProcessData& data) { |
342 const base::string16& child_name = data.name; | 338 const std::string& child_name = base::UTF16ToUTF8(data.name); |
343 if (!ContainsKey(child_process_stats_buffer_, child_name)) { | 339 if (!ContainsKey(child_process_stats_buffer_, child_name)) { |
344 child_process_stats_buffer_[child_name] = | 340 child_process_stats_buffer_[child_name] = |
345 ChildProcessStats(data.process_type); | 341 ChildProcessStats(data.process_type); |
346 } | 342 } |
347 return child_process_stats_buffer_[child_name]; | 343 return child_process_stats_buffer_[child_name]; |
348 } | 344 } |
349 | 345 |
350 void PluginMetricsProvider::BrowserChildProcessHostConnected( | 346 void PluginMetricsProvider::BrowserChildProcessHostConnected( |
351 const content::ChildProcessData& data) { | 347 const content::ChildProcessData& data) { |
352 GetChildProcessStats(data).process_launches++; | 348 GetChildProcessStats(data).process_launches++; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 } | 385 } |
390 | 386 |
391 bool PluginMetricsProvider::RecordCurrentStateIfPending() { | 387 bool PluginMetricsProvider::RecordCurrentStateIfPending() { |
392 if (!weak_ptr_factory_.HasWeakPtrs()) | 388 if (!weak_ptr_factory_.HasWeakPtrs()) |
393 return false; | 389 return false; |
394 | 390 |
395 weak_ptr_factory_.InvalidateWeakPtrs(); | 391 weak_ptr_factory_.InvalidateWeakPtrs(); |
396 RecordCurrentState(); | 392 RecordCurrentState(); |
397 return true; | 393 return true; |
398 } | 394 } |
OLD | NEW |