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

Side by Side 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: Use a map and counts Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
6 #define CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
7
8 #include <map>
9
10 #include "base/macros.h"
11 #include "base/memory/singleton.h"
12
13 enum class KeepAliveOrigin;
14
15 class KeepAliveRegistry {
16 public:
17 static KeepAliveRegistry* GetInstance();
18
19 bool WillKeepAlive() const;
20
21 protected:
22 KeepAliveRegistry();
23 virtual ~KeepAliveRegistry();
24
25 // Prevent the browser from closing. Called when a KeepAlive is first
26 // registered.
27 virtual void HugBrowser();
sky 2016/02/25 00:25:18 'hug', eh? How about PinBrowser(), PreventBrowserF
dgn 2016/02/25 17:19:46 Removed, since I'm not mocking the method anymore.
28
29 // Let the browser close. Called when the last KeepAlive is unregistered.
30 virtual void ReleaseBrowser();
sky 2016/02/25 00:25:18 I'm not a fan of virtual functions like this just
dgn 2016/02/25 17:19:46 I wanted to check the call that has external effec
31
32 private:
33 friend struct base::DefaultSingletonTraits<KeepAliveRegistry>;
34 friend class KeepAliveRegistryTest;
35 // Friend to be able to use Register/Unregister
36 friend class ScopedKeepAlive;
37
38 // Allows to provide a specific instance for testing purpose. At the end
39 // of the test, reset it by setting it to |nullptr|.
40 static void SetInstanceForTesting(KeepAliveRegistry* new_instance);
41
42 // Add/Remove entries. Do not use directly, use ScopedKeepAlive instead.
43 void Register(KeepAliveOrigin origin);
44 void Unregister(KeepAliveOrigin origin);
45
46 // Tracks the registered KeepAlives, storing the origin and the number of
47 // registered KeepAlives for each.
48 std::map<KeepAliveOrigin, int> registered_keep_alives_;
49
50 // Total number of registered KeepAlives
51 int registered_count_;
sky 2016/02/25 00:25:18 You need to initialize this to 0.
dgn 2016/02/25 17:19:46 Thanks. Done.
52
53 DISALLOW_COPY_AND_ASSIGN(KeepAliveRegistry);
54 };
55
56 #endif // CHROME_BROWSER_LIFETIME_KEEP_ALIVE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698