| 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 #ifndef CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ | 6 #define CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 bool IsRestartAllowed() const; | 33 bool IsRestartAllowed() const; |
| 34 bool IsOriginRegistered(KeepAliveOrigin origin) const; | 34 bool IsOriginRegistered(KeepAliveOrigin origin) const; |
| 35 | 35 |
| 36 void AddObserver(KeepAliveStateObserver* observer); | 36 void AddObserver(KeepAliveStateObserver* observer); |
| 37 void RemoveObserver(KeepAliveStateObserver* observer); | 37 void RemoveObserver(KeepAliveStateObserver* observer); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 friend struct base::DefaultSingletonTraits<KeepAliveRegistry>; | 40 friend struct base::DefaultSingletonTraits<KeepAliveRegistry>; |
| 41 // Friend to be able to use Register/Unregister | 41 // Friend to be able to use Register/Unregister |
| 42 friend class ScopedKeepAlive; | 42 friend class ScopedKeepAlive; |
| 43 #ifndef NDEBUG | 43 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 44 friend std::ostream& operator<<(std::ostream& out, | 44 friend std::ostream& operator<<(std::ostream& out, |
| 45 const KeepAliveRegistry& registry); | 45 const KeepAliveRegistry& registry); |
| 46 #endif // NDEBUG | 46 #endif |
| 47 | 47 |
| 48 KeepAliveRegistry(); | 48 KeepAliveRegistry(); |
| 49 ~KeepAliveRegistry(); | 49 ~KeepAliveRegistry(); |
| 50 | 50 |
| 51 // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead. | 51 // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead. |
| 52 void Register(KeepAliveOrigin origin, KeepAliveRestartOption restart); | 52 void Register(KeepAliveOrigin origin, KeepAliveRestartOption restart); |
| 53 void Unregister(KeepAliveOrigin origin, KeepAliveRestartOption restart); | 53 void Unregister(KeepAliveOrigin origin, KeepAliveRestartOption restart); |
| 54 | 54 |
| 55 // Methods called when a specific aspect of the state of the registry changes. | 55 // Methods called when a specific aspect of the state of the registry changes. |
| 56 void OnKeepAliveStateChanged(bool new_keeping_alive); | 56 void OnKeepAliveStateChanged(bool new_keeping_alive); |
| 57 void OnRestartAllowedChanged(bool new_restart_allowed); | 57 void OnRestartAllowedChanged(bool new_restart_allowed); |
| 58 | 58 |
| 59 // Tracks the registered KeepAlives, storing the origin and the number of | 59 // Tracks the registered KeepAlives, storing the origin and the number of |
| 60 // registered KeepAlives for each. | 60 // registered KeepAlives for each. |
| 61 std::map<KeepAliveOrigin, int> registered_keep_alives_; | 61 std::map<KeepAliveOrigin, int> registered_keep_alives_; |
| 62 | 62 |
| 63 // Total number of registered KeepAlives | 63 // Total number of registered KeepAlives |
| 64 int registered_count_; | 64 int registered_count_; |
| 65 | 65 |
| 66 // Number of registered keep alives that have KeepAliveRestartOption::ENABLED. | 66 // Number of registered keep alives that have KeepAliveRestartOption::ENABLED. |
| 67 int restart_allowed_count_; | 67 int restart_allowed_count_; |
| 68 | 68 |
| 69 base::ObserverList<KeepAliveStateObserver> observers_; | 69 base::ObserverList<KeepAliveStateObserver> observers_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry); | 71 DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 #ifndef NDEBUG | 74 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 75 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry); | 75 std::ostream& operator<<(std::ostream& out, const KeepAliveRegistry& registry); |
| 76 #endif // ndef NDEBUG | 76 #endif |
| 77 | 77 |
| 78 #endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ | 78 #endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ |
| OLD | NEW |