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

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

Issue 2439493002: Reduce usage of FOR_EACH_OBSERVER macro in chrome/browser (Closed)
Patch Set: Created 4 years, 2 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 "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/lifetime/application_lifetime.h" 8 #include "chrome/browser/lifetime/application_lifetime.h"
9 #include "chrome/browser/lifetime/keep_alive_state_observer.h" 9 #include "chrome/browser/lifetime/keep_alive_state_observer.h"
10 #include "chrome/browser/lifetime/keep_alive_types.h" 10 #include "chrome/browser/lifetime/keep_alive_types.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 if (new_restart_allowed != old_restart_allowed) 130 if (new_restart_allowed != old_restart_allowed)
131 OnRestartAllowedChanged(new_restart_allowed); 131 OnRestartAllowedChanged(new_restart_allowed);
132 132
133 DVLOG(1) << "New state of the KeepAliveRegistry:" << *this; 133 DVLOG(1) << "New state of the KeepAliveRegistry:" << *this;
134 } 134 }
135 135
136 void KeepAliveRegistry::OnKeepAliveStateChanged(bool new_keeping_alive) { 136 void KeepAliveRegistry::OnKeepAliveStateChanged(bool new_keeping_alive) {
137 DVLOG(1) << "Notifying KeepAliveStateObservers: KeepingAlive changed to: " 137 DVLOG(1) << "Notifying KeepAliveStateObservers: KeepingAlive changed to: "
138 << new_keeping_alive; 138 << new_keeping_alive;
139 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, 139 for (KeepAliveStateObserver& observer : observers_)
140 OnKeepAliveStateChanged(new_keeping_alive)); 140 observer.OnKeepAliveStateChanged(new_keeping_alive);
141 } 141 }
142 142
143 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { 143 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) {
144 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " 144 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: "
145 << new_restart_allowed; 145 << new_restart_allowed;
146 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, 146 for (KeepAliveStateObserver& observer : observers_)
147 OnKeepAliveRestartStateChanged(new_restart_allowed)); 147 observer.OnKeepAliveRestartStateChanged(new_restart_allowed);
148 } 148 }
149 149
150 void KeepAliveRegistry::DecrementCount(KeepAliveOrigin origin, 150 void KeepAliveRegistry::DecrementCount(KeepAliveOrigin origin,
151 OriginMap* keep_alive_map) { 151 OriginMap* keep_alive_map) {
152 int new_count = --keep_alive_map->at(origin); 152 int new_count = --keep_alive_map->at(origin);
153 DCHECK_GE(keep_alive_map->at(origin), 0); 153 DCHECK_GE(keep_alive_map->at(origin), 0);
154 if (new_count == 0) 154 if (new_count == 0)
155 keep_alive_map->erase(origin); 155 keep_alive_map->erase(origin);
156 } 156 }
157 157
158 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { 158 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) {
159 out << "{registered_count_=" << registry.registered_count_ 159 out << "{registered_count_=" << registry.registered_count_
160 << ", restart_allowed_count_=" << registry.restart_allowed_count_ 160 << ", restart_allowed_count_=" << registry.restart_allowed_count_
161 << ", KeepAlives=["; 161 << ", KeepAlives=[";
162 for (auto counts_per_origin_it : registry.registered_keep_alives_) { 162 for (auto counts_per_origin_it : registry.registered_keep_alives_) {
163 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) 163 if (counts_per_origin_it != *registry.registered_keep_alives_.begin())
164 out << ", "; 164 out << ", ";
165 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second 165 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second
166 << ")"; 166 << ")";
167 } 167 }
168 out << "]}"; 168 out << "]}";
169 return out; 169 return out;
170 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_service.cc ('k') | chrome/browser/local_discovery/service_discovery_client_mdns.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698