• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_
7 
8 #include <map>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h"
14 #include "components/metrics/metrics_provider.h"
15 #include "content/public/browser/browser_child_process_observer.h"
16 
17 namespace base {
18 class FilePath;
19 }
20 
21 namespace content {
22 struct WebPluginInfo;
23 }
24 
25 class PrefRegistrySimple;
26 class PrefService;
27 
28 // PluginMetricsProvider is responsible for adding out plugin information to
29 // the UMA proto.
30 class PluginMetricsProvider : public metrics::MetricsProvider,
31                               public content::BrowserChildProcessObserver {
32  public:
33   explicit PluginMetricsProvider(PrefService* local_state);
34   virtual ~PluginMetricsProvider();
35 
36   // Fetches plugin information data asynchronously and calls |done_callback|
37   // when done.
38   void GetPluginInformation(const base::Closure& done_callback);
39 
40   // metrics::MetricsDataProvider:
41   virtual void ProvideSystemProfileMetrics(
42       metrics::SystemProfileProto* system_profile_proto) OVERRIDE;
43   virtual void ProvideStabilityMetrics(
44       metrics::SystemProfileProto* system_profile_proto) OVERRIDE;
45   virtual void RecordCurrentState() OVERRIDE;
46 
47   // Notifies the provider about an error loading the plugin at |plugin_path|.
48   void LogPluginLoadingError(const base::FilePath& plugin_path);
49 
50   // Sets this provider's list of plugins, exposed for testing.
51   void SetPluginsForTesting(const std::vector<content::WebPluginInfo>& plugins);
52 
53   // Returns true if process of type |type| should be counted as a plugin
54   // process, and false otherwise.
55   static bool IsPluginProcess(int process_type);
56 
57   // Registers local state prefs used by this class.
58   static void RegisterPrefs(PrefRegistrySimple* registry);
59 
60  private:
61   struct ChildProcessStats;
62 
63   // Receives the plugin list from the PluginService and calls |done_callback|.
64   void OnGotPlugins(const base::Closure& done_callback,
65                     const std::vector<content::WebPluginInfo>& plugins);
66 
67   // Returns reference to ChildProcessStats corresponding to |data|.
68   ChildProcessStats& GetChildProcessStats(
69       const content::ChildProcessData& data);
70 
71   // content::BrowserChildProcessObserver:
72   virtual void BrowserChildProcessHostConnected(
73       const content::ChildProcessData& data) OVERRIDE;
74   virtual void BrowserChildProcessCrashed(
75       const content::ChildProcessData& data) OVERRIDE;
76   virtual void BrowserChildProcessInstanceCreated(
77       const content::ChildProcessData& data) OVERRIDE;
78 
79   PrefService* local_state_;
80 
81   // The list of plugins which was retrieved on the file thread.
82   std::vector<content::WebPluginInfo> plugins_;
83 
84   // Buffer of child process notifications for quick access.
85   std::map<base::string16, ChildProcessStats> child_process_stats_buffer_;
86 
87   base::WeakPtrFactory<PluginMetricsProvider> weak_ptr_factory_;
88 
89   DISALLOW_COPY_AND_ASSIGN(PluginMetricsProvider);
90 };
91 
92 #endif  // CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_
93