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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 210 |
211 for (base::ListValue::iterator value_iter = plugins->begin(); | 211 for (base::ListValue::iterator value_iter = plugins->begin(); |
212 value_iter != plugins->end(); ++value_iter) { | 212 value_iter != plugins->end(); ++value_iter) { |
213 if (!(*value_iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 213 if (!(*value_iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
214 NOTREACHED(); | 214 NOTREACHED(); |
215 continue; | 215 continue; |
216 } | 216 } |
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 base::string16 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 (auto cache_iter = child_process_stats_buffer_.begin(); |
268 child_process_stats_buffer_.begin(); | |
269 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { | 266 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { |
270 ChildProcessStats stats = cache_iter->second; | 267 ChildProcessStats stats = cache_iter->second; |
271 | 268 |
272 // Insert only plugins information into the plugins list. | 269 // Insert only plugins information into the plugins list. |
273 if (!IsPluginProcess(stats.process_type)) | 270 if (!IsPluginProcess(stats.process_type)) |
274 continue; | 271 continue; |
275 | 272 |
276 // TODO(viettrungluu): remove conversion | |
277 std::string plugin_name = base::UTF16ToUTF8(cache_iter->first); | |
278 | |
279 base::DictionaryValue* plugin_dict = new base::DictionaryValue; | 273 base::DictionaryValue* plugin_dict = new base::DictionaryValue; |
280 | 274 |
281 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); | 275 plugin_dict->SetString(prefs::kStabilityPluginName, cache_iter->first); |
282 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, | 276 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, |
283 stats.process_launches); | 277 stats.process_launches); |
284 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, | 278 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, |
285 stats.process_crashes); | 279 stats.process_crashes); |
286 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | 280 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, |
287 stats.instances); | 281 stats.instances); |
288 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | 282 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, |
289 stats.loading_errors); | 283 stats.loading_errors); |
290 plugins->Append(plugin_dict); | 284 plugins->Append(plugin_dict); |
291 } | 285 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } | 383 } |
390 | 384 |
391 bool PluginMetricsProvider::RecordCurrentStateIfPending() { | 385 bool PluginMetricsProvider::RecordCurrentStateIfPending() { |
392 if (!weak_ptr_factory_.HasWeakPtrs()) | 386 if (!weak_ptr_factory_.HasWeakPtrs()) |
393 return false; | 387 return false; |
394 | 388 |
395 weak_ptr_factory_.InvalidateWeakPtrs(); | 389 weak_ptr_factory_.InvalidateWeakPtrs(); |
396 RecordCurrentState(); | 390 RecordCurrentState(); |
397 return true; | 391 return true; |
398 } | 392 } |
OLD | NEW |