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

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

Issue 1708343002: Add ScopedKeepAlive to c/b/lifetime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove KeepAliveOrigin::TEST 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
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.cc ('k') | chrome/browser/lifetime/keep_alive_registry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/lifetime/keep_alive_registry.h
diff --git a/chrome/browser/lifetime/keep_alive_registry.h b/chrome/browser/lifetime/keep_alive_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..db47677f1f173c8610af362c2ab38f2c8d25bac0
--- /dev/null
+++ b/chrome/browser/lifetime/keep_alive_registry.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
+#define CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
+
+#include <map>
+
+#include "base/macros.h"
+#include "base/memory/singleton.h"
+
+enum class KeepAliveOrigin;
+
+class KeepAliveRegistry {
+ public:
+ static KeepAliveRegistry* GetInstance();
+
+ bool WillKeepAlive() const;
+
+ private:
+ friend struct base::DefaultSingletonTraits<KeepAliveRegistry>;
+ // Friend to be able to use Register/Unregister
+ friend class ScopedKeepAlive;
+
+ KeepAliveRegistry();
+ ~KeepAliveRegistry();
+
+ // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead.
+ void Register(KeepAliveOrigin origin);
+ void Unregister(KeepAliveOrigin origin);
+
+ // Tracks the registered KeepAlives, storing the origin and the number of
+ // registered KeepAlives for each.
+ std::map<KeepAliveOrigin, int> registered_keep_alives_;
+
+ // Total number of registered KeepAlives
+ int registered_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry);
+};
+
+#endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.cc ('k') | chrome/browser/lifetime/keep_alive_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698