Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: extensions/browser/load_monitoring_extension_host_queue.cc

Issue 995983002: Make LoadMonitoringExtensionHostQueue remove itself as an ExtensionHost observer at the correct tim… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test, remove log Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "extensions/browser/load_monitoring_extension_host_queue.h" 5 #include "extensions/browser/load_monitoring_extension_host_queue.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
14 #include "extensions/browser/extension_host.h" 14 #include "extensions/browser/extension_host.h"
15 #include "extensions/browser/extension_host_observer.h" 15 #include "extensions/browser/extension_host_observer.h"
16 #include "extensions/browser/serial_extension_host_queue.h" 16 #include "extensions/browser/serial_extension_host_queue.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 LoadMonitoringExtensionHostQueue::LoadMonitoringExtensionHostQueue( 20 LoadMonitoringExtensionHostQueue::LoadMonitoringExtensionHostQueue(
21 scoped_ptr<ExtensionHostQueue> delegate, 21 scoped_ptr<ExtensionHostQueue> delegate,
22 base::TimeDelta monitor_time, 22 base::TimeDelta monitor_time,
23 const FinishedCallback& finished_callback) 23 const FinishedCallback& finished_callback)
24 : delegate_(delegate.Pass()), 24 : delegate_(delegate.Pass()),
25 monitor_time_(monitor_time), 25 monitor_time_(monitor_time),
26 finished_callback_(finished_callback), 26 finished_callback_(finished_callback),
27 started_(false), 27 started_(false),
28 num_queued_(0u), 28 num_queued_(0u),
29 num_loaded_(0u), 29 num_loaded_(0u),
30 max_in_queue_(0u), 30 max_waiting_loading_(0u),
31 max_active_loading_(0u), 31 max_active_loading_(0u),
32 weak_ptr_factory_(this) { 32 weak_ptr_factory_(this) {
33 } 33 }
34 34
35 LoadMonitoringExtensionHostQueue::LoadMonitoringExtensionHostQueue( 35 LoadMonitoringExtensionHostQueue::LoadMonitoringExtensionHostQueue(
36 scoped_ptr<ExtensionHostQueue> delegate) 36 scoped_ptr<ExtensionHostQueue> delegate)
37 : LoadMonitoringExtensionHostQueue(delegate.Pass(), 37 : LoadMonitoringExtensionHostQueue(delegate.Pass(),
38 base::TimeDelta::FromMinutes(1), 38 base::TimeDelta::FromMinutes(1),
39 FinishedCallback()) { 39 FinishedCallback()) {
40 } 40 }
41 41
42 LoadMonitoringExtensionHostQueue::~LoadMonitoringExtensionHostQueue() { 42 LoadMonitoringExtensionHostQueue::~LoadMonitoringExtensionHostQueue() {
43 } 43 }
44 44
45 void LoadMonitoringExtensionHostQueue::StartMonitoring() { 45 void LoadMonitoringExtensionHostQueue::StartMonitoring() {
46 if (started_) { 46 if (started_) {
47 return; 47 return;
48 } 48 }
49 started_ = true; 49 started_ = true;
50 base::MessageLoop::current()->PostDelayedTask( 50 base::MessageLoop::current()->PostDelayedTask(
51 FROM_HERE, base::Bind(&LoadMonitoringExtensionHostQueue::FinishMonitoring, 51 FROM_HERE, base::Bind(&LoadMonitoringExtensionHostQueue::FinishMonitoring,
52 weak_ptr_factory_.GetWeakPtr()), 52 weak_ptr_factory_.GetWeakPtr()),
53 monitor_time_); 53 monitor_time_);
54 } 54 }
55 55
56 void LoadMonitoringExtensionHostQueue::Add(DeferredStartRenderHost* host) { 56 void LoadMonitoringExtensionHostQueue::Add(DeferredStartRenderHost* host) {
57 StartMonitoring(); 57 StartMonitoring();
58 delegate_->Add(host); 58 delegate_->Add(host);
59 if (in_queue_.insert(host).second) { 59 host->AddDeferredStartRenderHostObserver(this);
not at google - send to devlin 2015/03/10 22:26:07 I moved this out of the "if (waiting_loading_.inse
Yoyo Zhou 2015/03/10 22:48:13 sounds good.
60 if (waiting_loading_.insert(host).second) {
60 ++num_queued_; 61 ++num_queued_;
61 max_in_queue_ = std::max(max_in_queue_, in_queue_.size()); 62 max_waiting_loading_ =
62 host->AddDeferredStartRenderHostObserver(this); 63 std::max(max_waiting_loading_, waiting_loading_.size());
63 } 64 }
64 } 65 }
65 66
66 void LoadMonitoringExtensionHostQueue::Remove(DeferredStartRenderHost* host) { 67 void LoadMonitoringExtensionHostQueue::Remove(DeferredStartRenderHost* host) {
67 delegate_->Remove(host); 68 delegate_->Remove(host);
68 RemoveFromQueue(host); 69 host->RemoveDeferredStartRenderHostObserver(this);
69 } 70 }
70 71
71 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStartLoading( 72 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStartLoading(
72 const DeferredStartRenderHost* host) { 73 const DeferredStartRenderHost* host) {
73 StartMonitoringHost(host); 74 StartMonitoringHost(host);
74 } 75 }
75 76
76 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStopLoading( 77 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStopLoading(
77 const DeferredStartRenderHost* host) { 78 const DeferredStartRenderHost* host) {
78 FinishMonitoringHost(host); 79 FinishMonitoringHost(host);
79 } 80 }
80 81
81 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDestroyed( 82 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDestroyed(
82 const DeferredStartRenderHost* host) { 83 const DeferredStartRenderHost* host) {
83 FinishMonitoringHost(host); 84 FinishMonitoringHost(host);
84 } 85 }
85 86
86 void LoadMonitoringExtensionHostQueue::StartMonitoringHost( 87 void LoadMonitoringExtensionHostQueue::StartMonitoringHost(
87 const DeferredStartRenderHost* host) { 88 const DeferredStartRenderHost* host) {
89 waiting_loading_.erase(host);
88 if (active_loading_.insert(host).second) { 90 if (active_loading_.insert(host).second) {
89 max_active_loading_ = std::max(max_active_loading_, active_loading_.size()); 91 max_active_loading_ = std::max(max_active_loading_, active_loading_.size());
90 } 92 }
91 RemoveFromQueue(host);
92 } 93 }
93 94
94 void LoadMonitoringExtensionHostQueue::FinishMonitoringHost( 95 void LoadMonitoringExtensionHostQueue::FinishMonitoringHost(
95 const DeferredStartRenderHost* host) { 96 const DeferredStartRenderHost* host) {
96 if (active_loading_.erase(host)) { 97 if (active_loading_.erase(host)) {
97 ++num_loaded_; 98 ++num_loaded_;
98 } 99 }
99 } 100 }
100 101
101 void LoadMonitoringExtensionHostQueue::RemoveFromQueue(
102 const DeferredStartRenderHost* const_host) {
103 // This odd code is needed because StartMonitoringHost() gives us a const
104 // host, but we need a non-const one for
105 // RemoveDeferredStartRenderHostObserver().
106 for (DeferredStartRenderHost* host : in_queue_) {
107 if (host == const_host) {
108 host->RemoveDeferredStartRenderHostObserver(this);
109 in_queue_.erase(host); // uhoh, iterator invalidated!
110 break;
111 }
112 }
113 }
114
115 void LoadMonitoringExtensionHostQueue::FinishMonitoring() { 102 void LoadMonitoringExtensionHostQueue::FinishMonitoring() {
116 CHECK(started_); 103 CHECK(started_);
117 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumQueued", 104 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumQueued",
118 num_queued_); 105 num_queued_);
119 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumLoaded", 106 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumLoaded",
120 num_loaded_); 107 num_loaded_);
121 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.MaxInQueue", 108 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.MaxInQueue",
122 max_in_queue_); 109 max_waiting_loading_);
123 UMA_HISTOGRAM_COUNTS_100( 110 UMA_HISTOGRAM_COUNTS_100(
124 "Extensions.ExtensionHostMonitoring.MaxActiveLoading", 111 "Extensions.ExtensionHostMonitoring.MaxActiveLoading",
125 max_active_loading_); 112 max_active_loading_);
126 if (!finished_callback_.is_null()) { 113 if (!finished_callback_.is_null()) {
127 finished_callback_.Run(num_queued_, num_loaded_, max_in_queue_, 114 finished_callback_.Run(num_queued_, num_loaded_, max_waiting_loading_,
128 max_active_loading_); 115 max_active_loading_);
129 } 116 }
130 } 117 }
131 118
132 } // namespace extensions 119 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698