Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/metrics/plugin_metrics_provider.cc

Issue 441013002: Eliminate MetricsProvider::RecordCurrentState() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RecordCurrentState is called before reading from prefs and delayed calls are canceled. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ForcedRecordCurrentState();
129 const base::ListValue* plugin_stats_list = local_state_->GetList( 134 const base::ListValue* plugin_stats_list = local_state_->GetList(
130 prefs::kStabilityPluginStats); 135 prefs::kStabilityPluginStats);
131 if (!plugin_stats_list) 136 if (!plugin_stats_list)
132 return; 137 return;
133 138
134 metrics::SystemProfileProto::Stability* stability = 139 metrics::SystemProfileProto::Stability* stability =
135 system_profile_proto->mutable_stability(); 140 system_profile_proto->mutable_stability();
136 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); 141 for (base::ListValue::const_iterator iter = plugin_stats_list->begin();
137 iter != plugin_stats_list->end(); ++iter) { 142 iter != plugin_stats_list->end(); ++iter) {
138 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { 143 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; 297 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name];
293 // Initialize the type if this entry is new. 298 // Initialize the type if this entry is new.
294 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { 299 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) {
295 // The plug-in process might not actually be of type PLUGIN (which means 300 // 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. 301 // NPAPI), but we only care that it is *a* plug-in process.
297 stats.process_type = content::PROCESS_TYPE_PLUGIN; 302 stats.process_type = content::PROCESS_TYPE_PLUGIN;
298 } else { 303 } else {
299 DCHECK(IsPluginProcess(stats.process_type)); 304 DCHECK(IsPluginProcess(stats.process_type));
300 } 305 }
301 stats.loading_errors++; 306 stats.loading_errors++;
307 DelayedRecordCurrentState(kRecordStateDelayMs);
302 } 308 }
303 309
304 void PluginMetricsProvider::SetPluginsForTesting( 310 void PluginMetricsProvider::SetPluginsForTesting(
305 const std::vector<content::WebPluginInfo>& plugins) { 311 const std::vector<content::WebPluginInfo>& plugins) {
306 plugins_ = plugins; 312 plugins_ = plugins;
307 } 313 }
308 314
309 // static 315 // static
310 bool PluginMetricsProvider::IsPluginProcess(int process_type) { 316 bool PluginMetricsProvider::IsPluginProcess(int process_type) {
311 return (process_type == content::PROCESS_TYPE_PLUGIN || 317 return (process_type == content::PROCESS_TYPE_PLUGIN ||
(...skipping 20 matching lines...) Expand all
332 if (!ContainsKey(child_process_stats_buffer_, child_name)) { 338 if (!ContainsKey(child_process_stats_buffer_, child_name)) {
333 child_process_stats_buffer_[child_name] = 339 child_process_stats_buffer_[child_name] =
334 ChildProcessStats(data.process_type); 340 ChildProcessStats(data.process_type);
335 } 341 }
336 return child_process_stats_buffer_[child_name]; 342 return child_process_stats_buffer_[child_name];
337 } 343 }
338 344
339 void PluginMetricsProvider::BrowserChildProcessHostConnected( 345 void PluginMetricsProvider::BrowserChildProcessHostConnected(
340 const content::ChildProcessData& data) { 346 const content::ChildProcessData& data) {
341 GetChildProcessStats(data).process_launches++; 347 GetChildProcessStats(data).process_launches++;
348 DelayedRecordCurrentState(kRecordStateDelayMs);
342 } 349 }
343 350
344 void PluginMetricsProvider::BrowserChildProcessCrashed( 351 void PluginMetricsProvider::BrowserChildProcessCrashed(
345 const content::ChildProcessData& data) { 352 const content::ChildProcessData& data) {
346 GetChildProcessStats(data).process_crashes++; 353 GetChildProcessStats(data).process_crashes++;
354 DelayedRecordCurrentState(kRecordStateDelayMs);
347 } 355 }
348 356
349 void PluginMetricsProvider::BrowserChildProcessInstanceCreated( 357 void PluginMetricsProvider::BrowserChildProcessInstanceCreated(
350 const content::ChildProcessData& data) { 358 const content::ChildProcessData& data) {
351 GetChildProcessStats(data).instances++; 359 GetChildProcessStats(data).instances++;
360 DelayedRecordCurrentState(kRecordStateDelayMs);
352 } 361 }
362
363 bool PluginMetricsProvider::DelayedRecordCurrentState(int delay_sec) {
364 if (weak_ptr_factory_.HasWeakPtrs()) {
365 return false;
366 } else {
Alexei Svitkine (slow) 2014/08/05 21:35:21 Nit: No else after early return. Here and in the f
gayane -on leave until 09-2017 2014/08/06 14:51:35 Done.
367 base::MessageLoopProxy::current()->PostDelayedTask(
368 FROM_HERE,
369 base::Bind(&PluginMetricsProvider::RecordCurrentState,
370 weak_ptr_factory_.GetWeakPtr()),
371 base::TimeDelta::FromMilliseconds(delay_sec));
372 return true;
373 }
374 }
375
376 bool PluginMetricsProvider::ForcedRecordCurrentState() {
377 if (!weak_ptr_factory_.HasWeakPtrs()) {
378 return false;
379 } else {
380 weak_ptr_factory_.InvalidateWeakPtrs();
381 RecordCurrentState();
382 return true;
383 }
384
385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698