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" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/time.h" | |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/plugins/plugin_prefs.h" | 16 #include "chrome/browser/plugins/plugin_prefs.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "components/metrics/proto/system_profile.pb.h" | 19 #include "components/metrics/proto/system_profile.pb.h" |
19 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
20 #include "content/public/browser/plugin_service.h" | 21 #include "content/public/browser/plugin_service.h" |
21 #include "content/public/common/process_type.h" | 22 #include "content/public/common/process_type.h" |
22 #include "content/public/common/webplugininfo.h" | 23 #include "content/public/common/webplugininfo.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
27 // Delay for RecordCurrentState execution. | |
28 const int kRecordStateDelayMs = 15 * base::Time::kMillisecondsPerSecond; | |
29 | |
26 // Returns the plugin preferences corresponding for this user, if available. | 30 // Returns the plugin preferences corresponding for this user, if available. |
27 // If multiple user profiles are loaded, returns the preferences corresponding | 31 // If multiple user profiles are loaded, returns the preferences corresponding |
28 // to an arbitrary one of the profiles. | 32 // to an arbitrary one of the profiles. |
29 PluginPrefs* GetPluginPrefs() { | 33 PluginPrefs* GetPluginPrefs() { |
30 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 34 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
31 | 35 |
32 if (!profile_manager) { | 36 if (!profile_manager) { |
33 // The profile manager can be NULL when testing. | 37 // The profile manager can be NULL when testing. |
34 return NULL; | 38 return NULL; |
35 } | 39 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 metrics::SystemProfileProto* system_profile_proto) { | 123 metrics::SystemProfileProto* system_profile_proto) { |
120 PluginPrefs* plugin_prefs = GetPluginPrefs(); | 124 PluginPrefs* plugin_prefs = GetPluginPrefs(); |
121 for (size_t i = 0; i < plugins_.size(); ++i) { | 125 for (size_t i = 0; i < plugins_.size(); ++i) { |
122 SetPluginInfo(plugins_[i], plugin_prefs, | 126 SetPluginInfo(plugins_[i], plugin_prefs, |
123 system_profile_proto->add_plugin()); | 127 system_profile_proto->add_plugin()); |
124 } | 128 } |
125 } | 129 } |
126 | 130 |
127 void PluginMetricsProvider::ProvideStabilityMetrics( | 131 void PluginMetricsProvider::ProvideStabilityMetrics( |
128 metrics::SystemProfileProto* system_profile_proto) { | 132 metrics::SystemProfileProto* system_profile_proto) { |
133 | |
Alexei Svitkine (slow)
2014/08/06 15:10:01
Nit: No blank line at start of method body. Instea
gayane -on leave until 09-2017
2014/08/06 19:38:27
Done.
| |
134 RecordCurrentStateIfPending(); | |
129 const base::ListValue* plugin_stats_list = local_state_->GetList( | 135 const base::ListValue* plugin_stats_list = local_state_->GetList( |
130 prefs::kStabilityPluginStats); | 136 prefs::kStabilityPluginStats); |
131 if (!plugin_stats_list) | 137 if (!plugin_stats_list) |
132 return; | 138 return; |
133 | 139 |
134 metrics::SystemProfileProto::Stability* stability = | 140 metrics::SystemProfileProto::Stability* stability = |
135 system_profile_proto->mutable_stability(); | 141 system_profile_proto->mutable_stability(); |
136 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); | 142 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); |
137 iter != plugin_stats_list->end(); ++iter) { | 143 iter != plugin_stats_list->end(); ++iter) { |
138 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 144 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; | 298 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; |
293 // Initialize the type if this entry is new. | 299 // Initialize the type if this entry is new. |
294 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | 300 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { |
295 // The plug-in process might not actually be of type PLUGIN (which means | 301 // The plug-in process might not actually be of type PLUGIN (which means |
296 // NPAPI), but we only care that it is *a* plug-in process. | 302 // NPAPI), but we only care that it is *a* plug-in process. |
297 stats.process_type = content::PROCESS_TYPE_PLUGIN; | 303 stats.process_type = content::PROCESS_TYPE_PLUGIN; |
298 } else { | 304 } else { |
299 DCHECK(IsPluginProcess(stats.process_type)); | 305 DCHECK(IsPluginProcess(stats.process_type)); |
300 } | 306 } |
301 stats.loading_errors++; | 307 stats.loading_errors++; |
308 RecordCurrentStateWithDelay(kRecordStateDelayMs); | |
302 } | 309 } |
303 | 310 |
304 void PluginMetricsProvider::SetPluginsForTesting( | 311 void PluginMetricsProvider::SetPluginsForTesting( |
305 const std::vector<content::WebPluginInfo>& plugins) { | 312 const std::vector<content::WebPluginInfo>& plugins) { |
306 plugins_ = plugins; | 313 plugins_ = plugins; |
307 } | 314 } |
308 | 315 |
309 // static | 316 // static |
310 bool PluginMetricsProvider::IsPluginProcess(int process_type) { | 317 bool PluginMetricsProvider::IsPluginProcess(int process_type) { |
311 return (process_type == content::PROCESS_TYPE_PLUGIN || | 318 return (process_type == content::PROCESS_TYPE_PLUGIN || |
(...skipping 20 matching lines...) Expand all Loading... | |
332 if (!ContainsKey(child_process_stats_buffer_, child_name)) { | 339 if (!ContainsKey(child_process_stats_buffer_, child_name)) { |
333 child_process_stats_buffer_[child_name] = | 340 child_process_stats_buffer_[child_name] = |
334 ChildProcessStats(data.process_type); | 341 ChildProcessStats(data.process_type); |
335 } | 342 } |
336 return child_process_stats_buffer_[child_name]; | 343 return child_process_stats_buffer_[child_name]; |
337 } | 344 } |
338 | 345 |
339 void PluginMetricsProvider::BrowserChildProcessHostConnected( | 346 void PluginMetricsProvider::BrowserChildProcessHostConnected( |
340 const content::ChildProcessData& data) { | 347 const content::ChildProcessData& data) { |
341 GetChildProcessStats(data).process_launches++; | 348 GetChildProcessStats(data).process_launches++; |
349 RecordCurrentStateWithDelay(kRecordStateDelayMs); | |
342 } | 350 } |
343 | 351 |
344 void PluginMetricsProvider::BrowserChildProcessCrashed( | 352 void PluginMetricsProvider::BrowserChildProcessCrashed( |
345 const content::ChildProcessData& data) { | 353 const content::ChildProcessData& data) { |
346 GetChildProcessStats(data).process_crashes++; | 354 GetChildProcessStats(data).process_crashes++; |
355 RecordCurrentStateWithDelay(kRecordStateDelayMs); | |
347 } | 356 } |
348 | 357 |
349 void PluginMetricsProvider::BrowserChildProcessInstanceCreated( | 358 void PluginMetricsProvider::BrowserChildProcessInstanceCreated( |
350 const content::ChildProcessData& data) { | 359 const content::ChildProcessData& data) { |
351 GetChildProcessStats(data).instances++; | 360 GetChildProcessStats(data).instances++; |
361 RecordCurrentStateWithDelay(kRecordStateDelayMs); | |
352 } | 362 } |
363 | |
364 bool PluginMetricsProvider::RecordCurrentStateWithDelay(int delay_sec) { | |
365 if (weak_ptr_factory_.HasWeakPtrs()) | |
366 return false; | |
367 | |
368 base::MessageLoopProxy::current()->PostDelayedTask( | |
369 FROM_HERE, | |
370 base::Bind(&PluginMetricsProvider::RecordCurrentState, | |
371 weak_ptr_factory_.GetWeakPtr()), | |
372 base::TimeDelta::FromMilliseconds(delay_sec)); | |
373 return true; | |
374 } | |
375 | |
376 bool PluginMetricsProvider::RecordCurrentStateIfPending() { | |
377 if (!weak_ptr_factory_.HasWeakPtrs()) | |
378 return false; | |
379 | |
380 weak_ptr_factory_.InvalidateWeakPtrs(); | |
381 RecordCurrentState(); | |
382 return true; | |
383 } | |
OLD | NEW |