OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ | 5 #ifndef EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ |
6 #define EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ | 6 #define EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // ExtensionHosts are being loaded for some period of time. | 22 // ExtensionHosts are being loaded for some period of time. |
23 class LoadMonitoringExtensionHostQueue | 23 class LoadMonitoringExtensionHostQueue |
24 : public ExtensionHostQueue, | 24 : public ExtensionHostQueue, |
25 public DeferredStartRenderHostObserver { | 25 public DeferredStartRenderHostObserver { |
26 public: | 26 public: |
27 // Construction for testing. | 27 // Construction for testing. |
28 // Allows overriding the default timeout and triggering a callback when | 28 // Allows overriding the default timeout and triggering a callback when |
29 // monitoring has finished (timeout has elapsed and UMA is logged). | 29 // monitoring has finished (timeout has elapsed and UMA is logged). |
30 using FinishedCallback = base::Callback<void(size_t, // num_queued | 30 using FinishedCallback = base::Callback<void(size_t, // num_queued |
31 size_t, // max_loaded | 31 size_t, // max_loaded |
32 size_t, // max_in_queue | 32 size_t, // max_awaiting_loading |
33 size_t // max_active_loading | 33 size_t // max_active_loading |
34 )>; | 34 )>; |
35 LoadMonitoringExtensionHostQueue(scoped_ptr<ExtensionHostQueue> delegate, | 35 LoadMonitoringExtensionHostQueue(scoped_ptr<ExtensionHostQueue> delegate, |
36 base::TimeDelta monitor_time, | 36 base::TimeDelta monitor_time, |
37 const FinishedCallback& finished_callback); | 37 const FinishedCallback& finished_callback); |
38 | 38 |
39 // Production code should use this constructor. | 39 // Production code should use this constructor. |
40 // | 40 // |
41 // Monitoring will not start until the first Add()ed | 41 // Monitoring will not start until the first Add()ed |
42 // DeferredStartRenderHost starts loading, or StartMonitoring() is called. | 42 // DeferredStartRenderHost starts loading, or StartMonitoring() is called. |
(...skipping 22 matching lines...) Expand all Loading... |
65 const DeferredStartRenderHost* host) override; | 65 const DeferredStartRenderHost* host) override; |
66 void OnDeferredStartRenderHostDestroyed( | 66 void OnDeferredStartRenderHostDestroyed( |
67 const DeferredStartRenderHost* host) override; | 67 const DeferredStartRenderHost* host) override; |
68 | 68 |
69 private: | 69 private: |
70 // Starts/finishes monitoring |host|, though either will have no effect if | 70 // Starts/finishes monitoring |host|, though either will have no effect if |
71 // monitoring has already finished. | 71 // monitoring has already finished. |
72 void StartMonitoringHost(const DeferredStartRenderHost* host); | 72 void StartMonitoringHost(const DeferredStartRenderHost* host); |
73 void FinishMonitoringHost(const DeferredStartRenderHost* host); | 73 void FinishMonitoringHost(const DeferredStartRenderHost* host); |
74 | 74 |
75 // Removes |host| from the internal |in_queue_| tracking. | |
76 void RemoveFromQueue(const DeferredStartRenderHost* host); | |
77 | |
78 // Called when monitoring should finish. Metrics are recorded, and from this | 75 // Called when monitoring should finish. Metrics are recorded, and from this |
79 // point on no monitoring will take place. | 76 // point on no monitoring will take place. |
80 void FinishMonitoring(); | 77 void FinishMonitoring(); |
81 | 78 |
82 // Delegate actually loading DeferredStartRenderHosts to another queue. | 79 // Delegate actually loading DeferredStartRenderHosts to another queue. |
83 scoped_ptr<ExtensionHostQueue> delegate_; | 80 scoped_ptr<ExtensionHostQueue> delegate_; |
84 | 81 |
85 // The amount of time to monitor for. By default this is 1 minute, but it can | 82 // The amount of time to monitor for. By default this is 1 minute, but it can |
86 // be overriden by tests. | 83 // be overriden by tests. |
87 base::TimeDelta monitor_time_; | 84 base::TimeDelta monitor_time_; |
88 | 85 |
89 // A callback to run when monitoring has finished. Intended for testing. | 86 // A callback to run when monitoring has finished. Intended for testing. |
90 FinishedCallback finished_callback_; | 87 FinishedCallback finished_callback_; |
91 | 88 |
92 // The hosts which are in the delegate's queue. | 89 // The hosts which are waiting to start loading. |
93 std::set<DeferredStartRenderHost*> in_queue_; | 90 std::set<const DeferredStartRenderHost*> awaiting_loading_; |
94 // The hosts which are currently loading. | 91 // The hosts which are currently loading. |
95 std::set<const DeferredStartRenderHost*> active_loading_; | 92 std::set<const DeferredStartRenderHost*> active_loading_; |
96 | 93 |
97 // True if this has started monitoring. | 94 // True if this has started monitoring. |
98 bool started_; | 95 bool started_; |
99 | 96 |
100 // Metrics: | 97 // Metrics: |
101 // The total number of hosts that were added to the queue. | 98 // The total number of hosts that were added to the queue. |
102 size_t num_queued_; | 99 size_t num_queued_; |
103 // The total number of hosts that started loading. | 100 // The total number of hosts that started loading. |
104 size_t num_loaded_; | 101 size_t num_loaded_; |
105 // The maximum number of hosts in the queue at any time. | 102 // The maximum number of hosts waiting to load at the same time. |
106 size_t max_in_queue_; | 103 size_t max_awaiting_loading_; |
107 // The maximum number of hosts that were loading at the same time. | 104 // The maximum number of hosts that were loading at the same time. |
108 size_t max_active_loading_; | 105 size_t max_active_loading_; |
109 | 106 |
110 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; | 107 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; |
111 | 108 |
112 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); | 109 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); |
113 }; | 110 }; |
114 | 111 |
115 } // namespace extensions | 112 } // namespace extensions |
116 | 113 |
117 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ | 114 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ |
OLD | NEW |