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

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

Issue 1012823002: Revert of Make LoadMonitoringExtensionHostQueue remove itself as an ExtensionHost observer at the... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_awaiting_loading_(0u), 30 max_in_queue_(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 host->AddDeferredStartRenderHostObserver(this); 59 if (in_queue_.insert(host).second) {
60 if (awaiting_loading_.insert(host).second) {
61 ++num_queued_; 60 ++num_queued_;
62 max_awaiting_loading_ = 61 max_in_queue_ = std::max(max_in_queue_, in_queue_.size());
63 std::max(max_awaiting_loading_, awaiting_loading_.size()); 62 host->AddDeferredStartRenderHostObserver(this);
64 } 63 }
65 } 64 }
66 65
67 void LoadMonitoringExtensionHostQueue::Remove(DeferredStartRenderHost* host) { 66 void LoadMonitoringExtensionHostQueue::Remove(DeferredStartRenderHost* host) {
68 delegate_->Remove(host); 67 delegate_->Remove(host);
69 host->RemoveDeferredStartRenderHostObserver(this); 68 RemoveFromQueue(host);
70 } 69 }
71 70
72 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStartLoading( 71 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStartLoading(
73 const DeferredStartRenderHost* host) { 72 const DeferredStartRenderHost* host) {
74 StartMonitoringHost(host); 73 StartMonitoringHost(host);
75 } 74 }
76 75
77 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStopLoading( 76 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDidStopLoading(
78 const DeferredStartRenderHost* host) { 77 const DeferredStartRenderHost* host) {
79 FinishMonitoringHost(host); 78 FinishMonitoringHost(host);
80 } 79 }
81 80
82 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDestroyed( 81 void LoadMonitoringExtensionHostQueue::OnDeferredStartRenderHostDestroyed(
83 const DeferredStartRenderHost* host) { 82 const DeferredStartRenderHost* host) {
84 FinishMonitoringHost(host); 83 FinishMonitoringHost(host);
85 } 84 }
86 85
87 void LoadMonitoringExtensionHostQueue::StartMonitoringHost( 86 void LoadMonitoringExtensionHostQueue::StartMonitoringHost(
88 const DeferredStartRenderHost* host) { 87 const DeferredStartRenderHost* host) {
89 awaiting_loading_.erase(host);
90 if (active_loading_.insert(host).second) { 88 if (active_loading_.insert(host).second) {
91 max_active_loading_ = std::max(max_active_loading_, active_loading_.size()); 89 max_active_loading_ = std::max(max_active_loading_, active_loading_.size());
92 } 90 }
91 RemoveFromQueue(host);
93 } 92 }
94 93
95 void LoadMonitoringExtensionHostQueue::FinishMonitoringHost( 94 void LoadMonitoringExtensionHostQueue::FinishMonitoringHost(
96 const DeferredStartRenderHost* host) { 95 const DeferredStartRenderHost* host) {
97 if (active_loading_.erase(host)) { 96 if (active_loading_.erase(host)) {
98 ++num_loaded_; 97 ++num_loaded_;
99 } 98 }
100 } 99 }
101 100
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
102 void LoadMonitoringExtensionHostQueue::FinishMonitoring() { 115 void LoadMonitoringExtensionHostQueue::FinishMonitoring() {
103 CHECK(started_); 116 CHECK(started_);
104 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumQueued", 117 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumQueued",
105 num_queued_); 118 num_queued_);
106 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumLoaded", 119 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.NumLoaded",
107 num_loaded_); 120 num_loaded_);
108 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.MaxInQueue", 121 UMA_HISTOGRAM_COUNTS_100("Extensions.ExtensionHostMonitoring.MaxInQueue",
109 max_awaiting_loading_); 122 max_in_queue_);
110 UMA_HISTOGRAM_COUNTS_100( 123 UMA_HISTOGRAM_COUNTS_100(
111 "Extensions.ExtensionHostMonitoring.MaxActiveLoading", 124 "Extensions.ExtensionHostMonitoring.MaxActiveLoading",
112 max_active_loading_); 125 max_active_loading_);
113 if (!finished_callback_.is_null()) { 126 if (!finished_callback_.is_null()) {
114 finished_callback_.Run(num_queued_, num_loaded_, max_awaiting_loading_, 127 finished_callback_.Run(num_queued_, num_loaded_, max_in_queue_,
115 max_active_loading_); 128 max_active_loading_);
116 } 129 }
117 } 130 }
118 131
119 } // namespace extensions 132 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698