Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1589)

Unified Diff: chrome/browser/lifetime/keep_alive_registry.cc

Issue 1708343002: Add ScopedKeepAlive to c/b/lifetime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address PS7 comments, replace strings by a struct ptr, chromeappdelegate ctor takes a boolean Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}

Powered by Google App Engine
This is Rietveld 408576698