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

Side by Side Diff: chrome/browser/lifetime/keep_alive_registry.cc

Issue 2861223003: Record keep alive registry's state in stability instrumentation (Closed)
Patch Set: Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/lifetime/keep_alive_registry.h" 5 #include "chrome/browser/lifetime/keep_alive_registry.h"
6 6
7 #include "build/build_config.h"
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/lifetime/application_lifetime.h" 9 #include "chrome/browser/lifetime/application_lifetime.h"
9 #include "chrome/browser/lifetime/keep_alive_state_observer.h" 10 #include "chrome/browser/lifetime/keep_alive_state_observer.h"
10 #include "chrome/browser/lifetime/keep_alive_types.h" 11 #include "chrome/browser/lifetime/keep_alive_types.h"
11 12
13 #if defined(OS_WIN)
bcwhite 2017/05/08 15:37:59 Why do this only on Windows?
manzagop (departed) 2017/05/08 16:12:59 I recently re-jigged the build targets for reuse b
14 #include "components/browser_watcher/stability_data_names.h"
15 #include "components/browser_watcher/stability_debugging.h"
16 #endif // defined(OS_WIN)
17
12 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
13 // Public methods 19 // Public methods
14 20
15 // static 21 // static
16 KeepAliveRegistry* KeepAliveRegistry::GetInstance() { 22 KeepAliveRegistry* KeepAliveRegistry::GetInstance() {
17 return base::Singleton<KeepAliveRegistry>::get(); 23 return base::Singleton<KeepAliveRegistry>::get();
18 } 24 }
19 25
20 bool KeepAliveRegistry::IsKeepingAlive() const { 26 bool KeepAliveRegistry::IsKeepingAlive() const {
21 return registered_count_ > 0; 27 return registered_count_ > 0;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 135
130 if (new_restart_allowed != old_restart_allowed) 136 if (new_restart_allowed != old_restart_allowed)
131 OnRestartAllowedChanged(new_restart_allowed); 137 OnRestartAllowedChanged(new_restart_allowed);
132 138
133 DVLOG(1) << "New state of the KeepAliveRegistry:" << *this; 139 DVLOG(1) << "New state of the KeepAliveRegistry:" << *this;
134 } 140 }
135 141
136 void KeepAliveRegistry::OnKeepAliveStateChanged(bool new_keeping_alive) { 142 void KeepAliveRegistry::OnKeepAliveStateChanged(bool new_keeping_alive) {
137 DVLOG(1) << "Notifying KeepAliveStateObservers: KeepingAlive changed to: " 143 DVLOG(1) << "Notifying KeepAliveStateObservers: KeepingAlive changed to: "
138 << new_keeping_alive; 144 << new_keeping_alive;
145 #if defined(OS_WIN)
146 browser_watcher::SetStabilityDataBool(browser_watcher::kStabilityKeepAlive,
147 new_keeping_alive);
148 #endif // defined(OS_WIN)
139 for (KeepAliveStateObserver& observer : observers_) 149 for (KeepAliveStateObserver& observer : observers_)
140 observer.OnKeepAliveStateChanged(new_keeping_alive); 150 observer.OnKeepAliveStateChanged(new_keeping_alive);
141 } 151 }
142 152
143 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { 153 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) {
144 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " 154 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: "
145 << new_restart_allowed; 155 << new_restart_allowed;
156 #if defined(OS_WIN)
157 browser_watcher::SetStabilityDataBool(
158 browser_watcher::kStabilityRestartAllowed, new_restart_allowed);
159 #endif // defined(OS_WIN)
146 for (KeepAliveStateObserver& observer : observers_) 160 for (KeepAliveStateObserver& observer : observers_)
147 observer.OnKeepAliveRestartStateChanged(new_restart_allowed); 161 observer.OnKeepAliveRestartStateChanged(new_restart_allowed);
148 } 162 }
149 163
150 void KeepAliveRegistry::DecrementCount(KeepAliveOrigin origin, 164 void KeepAliveRegistry::DecrementCount(KeepAliveOrigin origin,
151 OriginMap* keep_alive_map) { 165 OriginMap* keep_alive_map) {
152 int new_count = --keep_alive_map->at(origin); 166 int new_count = --keep_alive_map->at(origin);
153 DCHECK_GE(keep_alive_map->at(origin), 0); 167 DCHECK_GE(keep_alive_map->at(origin), 0);
154 if (new_count == 0) 168 if (new_count == 0)
155 keep_alive_map->erase(origin); 169 keep_alive_map->erase(origin);
156 } 170 }
157 171
158 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { 172 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) {
159 out << "{registered_count_=" << registry.registered_count_ 173 out << "{registered_count_=" << registry.registered_count_
160 << ", restart_allowed_count_=" << registry.restart_allowed_count_ 174 << ", restart_allowed_count_=" << registry.restart_allowed_count_
161 << ", KeepAlives=["; 175 << ", KeepAlives=[";
162 for (auto counts_per_origin_it : registry.registered_keep_alives_) { 176 for (auto counts_per_origin_it : registry.registered_keep_alives_) {
163 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) 177 if (counts_per_origin_it != *registry.registered_keep_alives_.begin())
164 out << ", "; 178 out << ", ";
165 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second 179 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second
166 << ")"; 180 << ")";
167 } 181 }
168 out << "]}"; 182 out << "]}";
169 return out; 183 return out;
170 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698