Index: chrome/browser/lifetime/keep_alive_registry.cc |
diff --git a/chrome/browser/lifetime/keep_alive_registry.cc b/chrome/browser/lifetime/keep_alive_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d42bfb89e03a6a060b983efba871b0a9a20b8e7 |
--- /dev/null |
+++ b/chrome/browser/lifetime/keep_alive_registry.cc |
@@ -0,0 +1,50 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/lifetime/keep_alive_registry.h" |
+ |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/lifetime/application_lifetime.h" |
+ |
+namespace { |
+ |
+// Helper function to remove one token from the multisets. |
+void RemoveOne(const std::string& key, std::multiset<std::string>& container) { |
+ auto it = container.find(key); |
+ DCHECK(it != container.end()); |
+ container.erase(it); |
+} |
+ |
+} // namespace |
+ |
+// static |
+KeepAliveRegistry* KeepAliveRegistry::GetInstance() { |
+ return base::Singleton<KeepAliveRegistry>::get(); |
+} |
+ |
+KeepAliveRegistry::KeepAliveRegistry() {} |
sky
2016/02/19 21:02:49
nit: make declaration/definition order match (see
dgn
2016/02/22 18:01:19
Done.
|
+ |
+KeepAliveRegistry::~KeepAliveRegistry() { |
+ DCHECK_EQ(0u, registered_tokens_.size()); |
+} |
+ |
+void KeepAliveRegistry::RegisterToken(const std::string& token) { |
+ DCHECK(!token.empty()); |
+ |
+ registered_tokens_.insert(token); |
+ |
+ // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
+ // that in this class progressively as mechanisms are merged. |
+ if (registered_tokens_.size() == 1) |
+ chrome::IncrementKeepAliveCount(); |
+} |
+ |
+void KeepAliveRegistry::UnregisterToken(const std::string& token) { |
+ RemoveOne(token, registered_tokens_); |
+ |
+ // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
+ // that in this class progressively as mechanisms are merged. |
+ if (registered_tokens_.size() == 0) |
+ chrome::DecrementKeepAliveCount(); |
+} |