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..670954535468a866105cdd12abcee8a44d2188f8 |
--- /dev/null |
+++ b/chrome/browser/lifetime/keep_alive_registry.cc |
@@ -0,0 +1,57 @@ |
+// 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" |
+#include "chrome/browser/lifetime/keep_alive_options.h" |
+ |
+namespace { |
+ |
+// Helper function to remove one item from the multisets. |
+void RemoveOne(const KeepAliveOptions* key, |
+ std::multiset<const KeepAliveOptions*>& container) { |
+ auto it = container.find(key); |
+ DCHECK(it != container.end()); |
+ container.erase(it); |
+} |
+ |
+} // namespace |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// Public methods |
+ |
+// static |
+KeepAliveRegistry* KeepAliveRegistry::GetInstance() { |
+ return base::Singleton<KeepAliveRegistry>::get(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// Private methods |
+ |
+KeepAliveRegistry::KeepAliveRegistry() {} |
+ |
+KeepAliveRegistry::~KeepAliveRegistry() { |
+ DCHECK_EQ(0u, registered_keep_alives_.size()); |
+} |
+ |
+void KeepAliveRegistry::Register(const KeepAliveOptions* option) { |
+ registered_keep_alives_.insert(option); |
+ |
+ // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
+ // that in this class progressively as mechanisms are merged. |
+ if (registered_keep_alives_.size() == 1) |
+ chrome::IncrementKeepAliveCount(); |
+} |
+ |
+void KeepAliveRegistry::Unregister(const KeepAliveOptions* option) { |
+ RemoveOne(option, registered_keep_alives_); |
+ |
+ |
+ // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
+ // that in this class progressively as mechanisms are merged. |
+ if (registered_keep_alives_.size() == 0) |
+ chrome::DecrementKeepAliveCount(); |
+} |