OLD | NEW |
(Empty) | |
| 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 |
| 46 // Saves plugin-related updates from the in-object buffer to Local State |
| 47 // for retrieval next time we send a Profile log (generally next launch). |
| 48 void RecordPluginChanges(); |
| 49 |
| 50 // Notifies the provider about an error loading the plugin at |plugin_path|. |
| 51 void LogPluginLoadingError(const base::FilePath& plugin_path); |
| 52 |
| 53 // Sets this provider's list of plugins, exposed for testing. |
| 54 void SetPluginsForTesting(const std::vector<content::WebPluginInfo>& plugins); |
| 55 |
| 56 // Returns true if process of type |type| should be counted as a plugin |
| 57 // process, and false otherwise. |
| 58 static bool IsPluginProcess(int process_type); |
| 59 |
| 60 // Registers local state prefs used by this class. |
| 61 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 62 |
| 63 private: |
| 64 struct ChildProcessStats; |
| 65 |
| 66 // Receives the plugin list from the PluginService and calls |done_callback|. |
| 67 void OnGotPlugins(const base::Closure& done_callback, |
| 68 const std::vector<content::WebPluginInfo>& plugins); |
| 69 |
| 70 // Returns reference to ChildProcessStats corresponding to |data|. |
| 71 ChildProcessStats& GetChildProcessStats( |
| 72 const content::ChildProcessData& data); |
| 73 |
| 74 // content::BrowserChildProcessObserver: |
| 75 virtual void BrowserChildProcessHostConnected( |
| 76 const content::ChildProcessData& data) OVERRIDE; |
| 77 virtual void BrowserChildProcessCrashed( |
| 78 const content::ChildProcessData& data) OVERRIDE; |
| 79 virtual void BrowserChildProcessInstanceCreated( |
| 80 const content::ChildProcessData& data) OVERRIDE; |
| 81 |
| 82 PrefService* local_state_; |
| 83 |
| 84 // The list of plugins which was retrieved on the file thread. |
| 85 std::vector<content::WebPluginInfo> plugins_; |
| 86 |
| 87 // Buffer of child process notifications for quick access. |
| 88 std::map<base::string16, ChildProcessStats> child_process_stats_buffer_; |
| 89 |
| 90 base::WeakPtrFactory<PluginMetricsProvider> weak_ptr_factory_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(PluginMetricsProvider); |
| 93 }; |
| 94 |
| 95 #endif // CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ |
OLD | NEW |