OLD | NEW |
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/lifetime/application_lifetime.h" | 8 #include "chrome/browser/lifetime/application_lifetime.h" |
8 #include "chrome/browser/lifetime/keep_alive_state_observer.h" | 9 #include "chrome/browser/lifetime/keep_alive_state_observer.h" |
9 #include "chrome/browser/lifetime/keep_alive_types.h" | 10 #include "chrome/browser/lifetime/keep_alive_types.h" |
10 | 11 |
11 //////////////////////////////////////////////////////////////////////////////// | 12 //////////////////////////////////////////////////////////////////////////////// |
12 // Public methods | 13 // Public methods |
13 | 14 |
14 // static | 15 // static |
15 KeepAliveRegistry* KeepAliveRegistry::GetInstance() { | 16 KeepAliveRegistry* KeepAliveRegistry::GetInstance() { |
16 return base::Singleton<KeepAliveRegistry>::get(); | 17 return base::Singleton<KeepAliveRegistry>::get(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (new_restart_allowed != old_restart_allowed) | 90 if (new_restart_allowed != old_restart_allowed) |
90 OnRestartAllowedChanged(new_restart_allowed); | 91 OnRestartAllowedChanged(new_restart_allowed); |
91 | 92 |
92 if (new_keeping_alive != old_keeping_alive) | 93 if (new_keeping_alive != old_keeping_alive) |
93 OnKeepingAliveChanged(new_keeping_alive); | 94 OnKeepingAliveChanged(new_keeping_alive); |
94 | 95 |
95 DVLOG(1) << "New state of the KeepAliveRegistry: " << *this; | 96 DVLOG(1) << "New state of the KeepAliveRegistry: " << *this; |
96 } | 97 } |
97 | 98 |
98 void KeepAliveRegistry::OnKeepingAliveChanged(bool new_keeping_alive) { | 99 void KeepAliveRegistry::OnKeepingAliveChanged(bool new_keeping_alive) { |
| 100 // Although we should have a browser process, if there is none, |
| 101 // there is nothing to do. |
| 102 if (!g_browser_process) |
| 103 return; |
| 104 |
99 if (new_keeping_alive) { | 105 if (new_keeping_alive) { |
100 DVLOG(1) << "KeepAliveRegistry is now keeping the browser alive."; | 106 DVLOG(1) << "KeepAliveRegistry is now keeping the browser alive."; |
101 chrome::IncrementKeepAliveCount(); | 107 g_browser_process->AddRefModule(); |
102 } else { | 108 } else { |
103 DVLOG(1) << "KeepAliveRegistry stopped keeping the browser alive."; | 109 DVLOG(1) << "KeepAliveRegistry stopped keeping the browser alive."; |
104 chrome::DecrementKeepAliveCount(); | 110 g_browser_process->ReleaseModule(); |
| 111 chrome::CloseAllBrowsersIfNeeded(); |
105 } | 112 } |
106 } | 113 } |
107 | 114 |
108 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { | 115 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { |
109 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " | 116 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " |
110 << new_restart_allowed; | 117 << new_restart_allowed; |
111 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, | 118 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, |
112 OnKeepAliveRestartStateChanged(new_restart_allowed)); | 119 OnKeepAliveRestartStateChanged(new_restart_allowed)); |
113 } | 120 } |
114 | 121 |
115 #ifndef NDEBUG | 122 #ifndef NDEBUG |
116 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { | 123 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { |
117 out << "{KeepingAlive=" << registry.IsKeepingAlive() | 124 out << "{KeepingAlive=" << registry.IsKeepingAlive() |
118 << ", RestartAllowed=" << registry.IsRestartAllowed() << ", KeepAlives=["; | 125 << ", RestartAllowed=" << registry.IsRestartAllowed() << ", KeepAlives=["; |
119 for (auto counts_per_origin_it : registry.registered_keep_alives_) { | 126 for (auto counts_per_origin_it : registry.registered_keep_alives_) { |
120 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) | 127 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) |
121 out << ", "; | 128 out << ", "; |
122 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second | 129 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second |
123 << ")"; | 130 << ")"; |
124 } | 131 } |
125 out << "]}"; | 132 out << "]}"; |
126 return out; | 133 return out; |
127 } | 134 } |
128 #endif // ndef NDEBUG | 135 #endif // ndef NDEBUG |
OLD | NEW |