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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <set> | 11 #include <set> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/scoped_observer.h" | 16 #include "base/scoped_observer.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "extensions/browser/deferred_start_render_host_observer.h" | 18 #include "extensions/browser/deferred_start_render_host_observer.h" |
19 #include "extensions/browser/extension_host_queue.h" | 19 #include "extensions/browser/extension_host_queue.h" |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 | 22 |
23 // An ExtensionHostQueue which just monitors, and later reports, how many | 23 // An ExtensionHostQueue which just monitors, and later reports, how many |
24 // ExtensionHosts are being loaded for some period of time. | 24 // ExtensionHosts are being loaded for some period of time. |
25 class LoadMonitoringExtensionHostQueue | 25 class LoadMonitoringExtensionHostQueue |
26 : public ExtensionHostQueue, | 26 : public ExtensionHostQueue, |
27 public DeferredStartRenderHostObserver { | 27 public DeferredStartRenderHostObserver { |
28 public: | 28 public: |
29 // Construction for testing. | 29 // Construction for testing. |
30 // Allows overriding the default timeout and triggering a callback when | 30 // Allows overriding the default timeout and triggering a callback when |
31 // monitoring has finished (timeout has elapsed and UMA is logged). | 31 // monitoring has finished (timeout has elapsed and UMA is logged). |
32 using FinishedCallback = base::Callback<void(size_t, // num_queued | 32 using FinishedCallback = base::Callback<void(size_t, // num_queued |
33 size_t, // max_loaded | 33 size_t, // max_loaded |
34 size_t, // max_awaiting_loading | 34 size_t, // max_awaiting_loading |
35 size_t // max_active_loading | 35 size_t // max_active_loading |
36 )>; | 36 )>; |
37 LoadMonitoringExtensionHostQueue(scoped_ptr<ExtensionHostQueue> delegate, | 37 LoadMonitoringExtensionHostQueue(std::unique_ptr<ExtensionHostQueue> delegate, |
38 base::TimeDelta monitor_time, | 38 base::TimeDelta monitor_time, |
39 const FinishedCallback& finished_callback); | 39 const FinishedCallback& finished_callback); |
40 | 40 |
41 // Production code should use this constructor. | 41 // Production code should use this constructor. |
42 // | 42 // |
43 // Monitoring will not start until the first Add()ed | 43 // Monitoring will not start until the first Add()ed |
44 // DeferredStartRenderHost starts loading, or StartMonitoring() is called. | 44 // DeferredStartRenderHost starts loading, or StartMonitoring() is called. |
45 explicit LoadMonitoringExtensionHostQueue( | 45 explicit LoadMonitoringExtensionHostQueue( |
46 scoped_ptr<ExtensionHostQueue> delegate); | 46 std::unique_ptr<ExtensionHostQueue> delegate); |
47 | 47 |
48 ~LoadMonitoringExtensionHostQueue() override; | 48 ~LoadMonitoringExtensionHostQueue() override; |
49 | 49 |
50 // Starts monitoring. | 50 // Starts monitoring. |
51 // | 51 // |
52 // This can be called multiple times, but it has no effect if monitoring has | 52 // This can be called multiple times, but it has no effect if monitoring has |
53 // already started (or finished). Monitoring cannot be restarted. | 53 // already started (or finished). Monitoring cannot be restarted. |
54 // | 54 // |
55 // Note that monitoring will automatically start when Add() is called, so it | 55 // Note that monitoring will automatically start when Add() is called, so it |
56 // may not be necessary to call this at all. | 56 // may not be necessary to call this at all. |
(...skipping 15 matching lines...) Expand all Loading... |
72 // Starts/finishes monitoring |host|, though either will have no effect if | 72 // Starts/finishes monitoring |host|, though either will have no effect if |
73 // monitoring has already finished. | 73 // monitoring has already finished. |
74 void StartMonitoringHost(const DeferredStartRenderHost* host); | 74 void StartMonitoringHost(const DeferredStartRenderHost* host); |
75 void FinishMonitoringHost(const DeferredStartRenderHost* host); | 75 void FinishMonitoringHost(const DeferredStartRenderHost* host); |
76 | 76 |
77 // Called when monitoring should finish. Metrics are recorded, and from this | 77 // Called when monitoring should finish. Metrics are recorded, and from this |
78 // point on no monitoring will take place. | 78 // point on no monitoring will take place. |
79 void FinishMonitoring(); | 79 void FinishMonitoring(); |
80 | 80 |
81 // Delegate actually loading DeferredStartRenderHosts to another queue. | 81 // Delegate actually loading DeferredStartRenderHosts to another queue. |
82 scoped_ptr<ExtensionHostQueue> delegate_; | 82 std::unique_ptr<ExtensionHostQueue> delegate_; |
83 | 83 |
84 // The amount of time to monitor for. By default this is 1 minute, but it can | 84 // The amount of time to monitor for. By default this is 1 minute, but it can |
85 // be overriden by tests. | 85 // be overriden by tests. |
86 base::TimeDelta monitor_time_; | 86 base::TimeDelta monitor_time_; |
87 | 87 |
88 // A callback to run when monitoring has finished. Intended for testing. | 88 // A callback to run when monitoring has finished. Intended for testing. |
89 FinishedCallback finished_callback_; | 89 FinishedCallback finished_callback_; |
90 | 90 |
91 // The hosts which are waiting to start loading. | 91 // The hosts which are waiting to start loading. |
92 std::set<const DeferredStartRenderHost*> awaiting_loading_; | 92 std::set<const DeferredStartRenderHost*> awaiting_loading_; |
(...skipping 14 matching lines...) Expand all Loading... |
107 size_t max_active_loading_; | 107 size_t max_active_loading_; |
108 | 108 |
109 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; | 109 base::WeakPtrFactory<LoadMonitoringExtensionHostQueue> weak_ptr_factory_; |
110 | 110 |
111 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); | 111 DISALLOW_COPY_AND_ASSIGN(LoadMonitoringExtensionHostQueue); |
112 }; | 112 }; |
113 | 113 |
114 } // namespace extensions | 114 } // namespace extensions |
115 | 115 |
116 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ | 116 #endif // EXTENSIONS_BROWSER_LOAD_MONITORING_EXTENSION_HOST_QUEUE_H_ |
OLD | NEW |