Chromium Code Reviews| 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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/observer_list.h" | |
| 13 #include "chrome/browser/lifetime/keep_alive_types.h" | |
| 12 | 14 |
| 13 namespace keep_alive { | 15 namespace keep_alive { |
| 14 enum class Origin; | 16 enum class Origin; |
| 17 enum class RestartOption; | |
| 15 } | 18 } |
| 19 class KeepAliveStateObserver; | |
| 16 | 20 |
| 17 class KeepAliveRegistry { | 21 class KeepAliveRegistry { |
| 18 public: | 22 public: |
| 19 static KeepAliveRegistry* GetInstance(); | 23 static KeepAliveRegistry* GetInstance(); |
| 20 | 24 |
| 25 void AddObserver(KeepAliveStateObserver* observer); | |
| 26 void RemoveObserver(KeepAliveStateObserver* observer); | |
| 27 | |
| 21 private: | 28 private: |
| 29 struct KeepAliveState { | |
|
Bernhard Bauer
2016/02/24 16:54:34
Do you need this as a struct? It seems a bit easie
dgn
2016/02/24 19:08:32
Makes it easier to use compute/compare state
| |
| 30 bool is_keeping_alive; | |
| 31 keep_alive::RestartOption restart; | |
|
Bernhard Bauer
2016/02/24 16:54:34
I'd be okay with keeping this as a boolean; I only
dgn
2016/02/24 19:08:32
Thanks, I did it initially because I was comparing
| |
| 32 }; | |
| 33 | |
| 22 friend struct base::DefaultSingletonTraits<KeepAliveRegistry>; | 34 friend struct base::DefaultSingletonTraits<KeepAliveRegistry>; |
| 23 // Friend to be able to use Register/Unregister | 35 // Friend to be able to use Register/Unregister |
| 24 friend class ScopedKeepAlive; | 36 friend class ScopedKeepAlive; |
| 25 | 37 |
| 26 KeepAliveRegistry(); | 38 KeepAliveRegistry(); |
| 27 ~KeepAliveRegistry(); | 39 ~KeepAliveRegistry(); |
| 28 | 40 |
| 29 // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead. | 41 // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead. |
| 30 void Register(keep_alive::Origin origin); | 42 void Register(keep_alive::Origin origin, keep_alive::RestartOption restart); |
| 31 void Unregister(keep_alive::Origin origin); | 43 void Unregister(keep_alive::Origin origin, keep_alive::RestartOption restart); |
| 44 | |
| 45 KeepAliveState ComputeCurrentState() const; | |
| 46 void NotifyOfStateDifferences(const KeepAliveState& previous_state); | |
| 47 | |
| 48 void DumpRegistryIfDebug() const; | |
| 32 | 49 |
| 33 std::multiset<keep_alive::Origin> registered_keep_alives_; | 50 std::multiset<keep_alive::Origin> registered_keep_alives_; |
| 51 std::multiset<keep_alive::Origin> restart_allowed_keep_alives_; | |
| 52 | |
| 53 KeepAliveState state_; | |
|
Bernhard Bauer
2016/02/24 16:54:34
Hm... so, this is really defined by the two sets a
dgn
2016/02/24 19:08:32
Ok, I did that way in PS1 and ended up storing it
| |
| 54 | |
| 55 base::ObserverList<KeepAliveStateObserver> observers_; | |
| 34 | 56 |
| 35 DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry); | 57 DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry); |
| 36 }; | 58 }; |
| 37 | 59 |
| 38 #endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ | 60 #endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_ |
| OLD | NEW |