Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ | 6 #define CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "components/metrics/metrics_provider.h" | 15 #include "components/metrics/metrics_provider.h" |
| 15 #include "content/public/browser/browser_child_process_observer.h" | 16 #include "content/public/browser/browser_child_process_observer.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class FilePath; | 19 class FilePath; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 35 | 36 |
| 36 // Fetches plugin information data asynchronously and calls |done_callback| | 37 // Fetches plugin information data asynchronously and calls |done_callback| |
| 37 // when done. | 38 // when done. |
| 38 void GetPluginInformation(const base::Closure& done_callback); | 39 void GetPluginInformation(const base::Closure& done_callback); |
| 39 | 40 |
| 40 // metrics::MetricsDataProvider: | 41 // metrics::MetricsDataProvider: |
| 41 virtual void ProvideSystemProfileMetrics( | 42 virtual void ProvideSystemProfileMetrics( |
| 42 metrics::SystemProfileProto* system_profile_proto) OVERRIDE; | 43 metrics::SystemProfileProto* system_profile_proto) OVERRIDE; |
| 43 virtual void ProvideStabilityMetrics( | 44 virtual void ProvideStabilityMetrics( |
| 44 metrics::SystemProfileProto* system_profile_proto) OVERRIDE; | 45 metrics::SystemProfileProto* system_profile_proto) OVERRIDE; |
| 45 virtual void RecordCurrentState() OVERRIDE; | |
| 46 | 46 |
| 47 // Notifies the provider about an error loading the plugin at |plugin_path|. | 47 // Notifies the provider about an error loading the plugin at |plugin_path|. |
| 48 void LogPluginLoadingError(const base::FilePath& plugin_path); | 48 void LogPluginLoadingError(const base::FilePath& plugin_path); |
| 49 | 49 |
| 50 // Sets this provider's list of plugins, exposed for testing. | 50 // Sets this provider's list of plugins, exposed for testing. |
| 51 void SetPluginsForTesting(const std::vector<content::WebPluginInfo>& plugins); | 51 void SetPluginsForTesting(const std::vector<content::WebPluginInfo>& plugins); |
| 52 | 52 |
| 53 // Returns true if process of type |type| should be counted as a plugin | 53 // Returns true if process of type |type| should be counted as a plugin |
| 54 // process, and false otherwise. | 54 // process, and false otherwise. |
| 55 static bool IsPluginProcess(int process_type); | 55 static bool IsPluginProcess(int process_type); |
| 56 | 56 |
| 57 // Registers local state prefs used by this class. | 57 // Registers local state prefs used by this class. |
| 58 static void RegisterPrefs(PrefRegistrySimple* registry); | 58 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 FRIEND_TEST_ALL_PREFIXES(PluginMetricsProviderTest, | |
| 62 RecordCurrentStateWithDelay); | |
| 63 FRIEND_TEST_ALL_PREFIXES(PluginMetricsProviderTest, | |
| 64 RecordCurrentStateIfPending); | |
| 65 FRIEND_TEST_ALL_PREFIXES(PluginMetricsProviderTest, | |
| 66 ProvideStabilityMetricsWhenPendingTask); | |
| 61 struct ChildProcessStats; | 67 struct ChildProcessStats; |
| 62 | 68 |
| 63 // Receives the plugin list from the PluginService and calls |done_callback|. | 69 // Receives the plugin list from the PluginService and calls |done_callback|. |
| 64 void OnGotPlugins(const base::Closure& done_callback, | 70 void OnGotPlugins(const base::Closure& done_callback, |
| 65 const std::vector<content::WebPluginInfo>& plugins); | 71 const std::vector<content::WebPluginInfo>& plugins); |
| 66 | 72 |
| 67 // Returns reference to ChildProcessStats corresponding to |data|. | 73 // Returns reference to ChildProcessStats corresponding to |data|. |
| 68 ChildProcessStats& GetChildProcessStats( | 74 ChildProcessStats& GetChildProcessStats( |
| 69 const content::ChildProcessData& data); | 75 const content::ChildProcessData& data); |
| 70 | 76 |
| 77 // Saves plugin information to local state | |
|
Alexei Svitkine (slow)
2014/08/06 19:43:40
Nit: add a .
gayane -on leave until 09-2017
2014/08/06 20:47:07
Done.
| |
| 78 void RecordCurrentState(); | |
| 79 | |
| 80 // Posts a delayed task for RecordCurrentState. Returns true if new task is | |
| 81 // posted and false if there was one already waiting for execution. | |
| 82 // The param delay_sec is for unit tests. | |
| 83 bool RecordCurrentStateWithDelay(int delay_ms); | |
| 84 | |
| 85 // If a delayed RecordCurrnetState task exists then cancels it, calls | |
| 86 // RecordCurrentState immediately and returns true. Otherwise returns false. | |
| 87 bool RecordCurrentStateIfPending(); | |
| 88 | |
| 71 // content::BrowserChildProcessObserver: | 89 // content::BrowserChildProcessObserver: |
| 72 virtual void BrowserChildProcessHostConnected( | 90 virtual void BrowserChildProcessHostConnected( |
| 73 const content::ChildProcessData& data) OVERRIDE; | 91 const content::ChildProcessData& data) OVERRIDE; |
| 74 virtual void BrowserChildProcessCrashed( | 92 virtual void BrowserChildProcessCrashed( |
| 75 const content::ChildProcessData& data) OVERRIDE; | 93 const content::ChildProcessData& data) OVERRIDE; |
| 76 virtual void BrowserChildProcessInstanceCreated( | 94 virtual void BrowserChildProcessInstanceCreated( |
| 77 const content::ChildProcessData& data) OVERRIDE; | 95 const content::ChildProcessData& data) OVERRIDE; |
| 78 | 96 |
| 79 PrefService* local_state_; | 97 PrefService* local_state_; |
| 80 | 98 |
| 81 // The list of plugins which was retrieved on the file thread. | 99 // The list of plugins which was retrieved on the file thread. |
| 82 std::vector<content::WebPluginInfo> plugins_; | 100 std::vector<content::WebPluginInfo> plugins_; |
| 83 | 101 |
| 84 // Buffer of child process notifications for quick access. | 102 // Buffer of child process notifications for quick access. |
| 85 std::map<base::string16, ChildProcessStats> child_process_stats_buffer_; | 103 std::map<base::string16, ChildProcessStats> child_process_stats_buffer_; |
| 86 | 104 |
| 87 base::WeakPtrFactory<PluginMetricsProvider> weak_ptr_factory_; | 105 base::WeakPtrFactory<PluginMetricsProvider> weak_ptr_factory_; |
| 88 | 106 |
| 89 DISALLOW_COPY_AND_ASSIGN(PluginMetricsProvider); | 107 DISALLOW_COPY_AND_ASSIGN(PluginMetricsProvider); |
| 90 }; | 108 }; |
| 91 | 109 |
| 92 #endif // CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ | 110 #endif // CHROME_BROWSER_METRICS_PLUGIN_METRICS_PROVIDER_H_ |
| OLD | NEW |