| 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 // Should only happen in tests. |
| 101 if (!g_browser_process) |
| 102 return; |
| 103 |
| 99 if (new_keeping_alive) { | 104 if (new_keeping_alive) { |
| 100 DVLOG(1) << "KeepAliveRegistry is now keeping the browser alive."; | 105 DVLOG(1) << "KeepAliveRegistry is now keeping the browser alive."; |
| 101 chrome::IncrementKeepAliveCount(); | 106 g_browser_process->AddRefModule(); |
| 102 } else { | 107 } else { |
| 103 DVLOG(1) << "KeepAliveRegistry stopped keeping the browser alive."; | 108 DVLOG(1) << "KeepAliveRegistry stopped keeping the browser alive."; |
| 104 chrome::DecrementKeepAliveCount(); | 109 g_browser_process->ReleaseModule(); |
| 110 chrome::CloseAllBrowsersIfNeeded(); |
| 105 } | 111 } |
| 106 } | 112 } |
| 107 | 113 |
| 108 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { | 114 void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) { |
| 109 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " | 115 DVLOG(1) << "Notifying KeepAliveStateObservers: Restart changed to: " |
| 110 << new_restart_allowed; | 116 << new_restart_allowed; |
| 111 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, | 117 FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_, |
| 112 OnKeepAliveRestartStateChanged(new_restart_allowed)); | 118 OnKeepAliveRestartStateChanged(new_restart_allowed)); |
| 113 } | 119 } |
| 114 | 120 |
| 115 #ifndef NDEBUG | 121 #ifndef NDEBUG |
| 116 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { | 122 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry) { |
| 117 out << "{KeepingAlive=" << registry.IsKeepingAlive() | 123 out << "{KeepingAlive=" << registry.IsKeepingAlive() |
| 118 << ", RestartAllowed=" << registry.IsRestartAllowed() << ", KeepAlives=["; | 124 << ", RestartAllowed=" << registry.IsRestartAllowed() << ", KeepAlives=["; |
| 119 for (auto counts_per_origin_it : registry.registered_keep_alives_) { | 125 for (auto counts_per_origin_it : registry.registered_keep_alives_) { |
| 120 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) | 126 if (counts_per_origin_it != *registry.registered_keep_alives_.begin()) |
| 121 out << ", "; | 127 out << ", "; |
| 122 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second | 128 out << counts_per_origin_it.first << " (" << counts_per_origin_it.second |
| 123 << ")"; | 129 << ")"; |
| 124 } | 130 } |
| 125 out << "]}"; | 131 out << "]}"; |
| 126 return out; | 132 return out; |
| 127 } | 133 } |
| 128 #endif // ndef NDEBUG | 134 #endif // ndef NDEBUG |
| OLD | NEW |