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..3f19b4e7dc1f7abb62af72f5c71e33421c634c10 |
--- /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(); |
+} |
+ |
+void KeepAliveRegistry::Register(const KeepAliveOptions* option) { |
+ registered_keep_alives_.insert(option); |
+ LOG(ERROR) << "DGN - Increment"; |
Bernhard Bauer
2016/02/22 18:19:38
You'll remember to remove these before committing,
dgn
2016/02/22 19:07:19
Yup, removed now.
|
+ // 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_); |
+ LOG(ERROR) << "DGN - Decrement"; |
+ |
+ // 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(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// Private methods |
+ |
+KeepAliveRegistry::KeepAliveRegistry() {} |
+ |
+KeepAliveRegistry::~KeepAliveRegistry() { |
+ DCHECK_EQ(0u, registered_keep_alives_.size()); |
+} |