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_awaiting_loading | 32 size_t, // max_in_queue |
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 |
75 // Called when monitoring should finish. Metrics are recorded, and from this | 78 // Called when monitoring should finish. Metrics are recorded, and from this |
76 // point on no monitoring will take place. | 79 // point on no monitoring will take place. |
77 void FinishMonitoring(); | 80 void FinishMonitoring(); |
78 | 81 |
79 // Delegate actually loading DeferredStartRenderHosts to another queue. | 82 // Delegate actually loading DeferredStartRenderHosts to another queue. |
80 scoped_ptr<ExtensionHostQueue> delegate_; | 83 scoped_ptr<ExtensionHostQueue> delegate_; |
81 | 84 |
82 // The amount of time to monitor for. By default this is 1 minute, but it can | 85 // The amount of time to monitor for. By default this is 1 minute, but it can |
83 // be overriden by tests. | 86 // be overriden by tests. |
84 base::TimeDelta monitor_time_; | 87 base::TimeDelta monitor_time_; |
85 | 88 |
86 // A callback to run when monitoring has finished. Intended for testing. | 89 // A callback to run when monitoring has finished. Intended for testing. |
87 FinishedCallback finished_callback_; | 90 FinishedCallback finished_callback_; |
88 | 91 |
89 // The hosts which are waiting to start loading. | 92 // The hosts which are in the delegate's queue. |
90 std::set<const DeferredStartRenderHost*> awaiting_loading_; | 93 std::set<DeferredStartRenderHost*> in_queue_; |
91 // The hosts which are currently loading. | 94 // The hosts which are currently loading. |
92 std::set<const DeferredStartRenderHost*> active_loading_; | 95 std::set<const DeferredStartRenderHost*> active_loading_; |
93 | 96 |
94 // True if this has started monitoring. | 97 // True if this has started monitoring. |
95 bool started_; | 98 bool started_; |
96 | 99 |
97 // Metrics: | 100 // Metrics: |
98 // The total number of hosts that were added to the queue. | 101 // The total number of hosts that were added to the queue. |
99 size_t num_queued_; | 102 size_t num_queued_; |
100 // The total number of hosts that started loading. | 103 // The total number of hosts that started loading. |
101 size_t num_loaded_; | 104 size_t num_loaded_; |
102 // The maximum number of hosts waiting to load at the same time. | 105 // The maximum number of hosts in the queue at any time. |
103 size_t max_awaiting_loading_; | 106 size_t max_in_queue_; |
104 // The maximum number of hosts that were loading at the same time. | 107 // The maximum number of hosts that were loading at the same time. |
105 size_t max_active_loading_; | 108 size_t max_active_loading_; |
106 | 109 |
107 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; | 110 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; |
108 | 111 |
109 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); | 112 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); |
110 }; | 113 }; |
111 | 114 |
112 } // namespace extensions | 115 } // namespace extensions |
113 | 116 |
114 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ | 117 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ |
OLD | NEW |