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

Side by Side 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: 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 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 #include "chrome/browser/lifetime/keep_alive_registry.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/lifetime/application_lifetime.h"
9
10 namespace {
11
12 // Helper function to remove one token from the multisets.
13 void RemoveOne(const std::string& key, std::multiset<std::string>& container) {
14 auto it = container.find(key);
15 DCHECK(it != container.end());
16 container.erase(it);
17 }
18
19 } // namespace
20
21 // static
22 KeepAliveRegistry* KeepAliveRegistry::GetInstance() {
23 return base::Singleton<KeepAliveRegistry>::get();
24 }
25
26 KeepAliveRegistry::KeepAliveRegistry() {}
sky 2016/02/19 21:02:49 nit: make declaration/definition order match (see
dgn 2016/02/22 18:01:19 Done.
27
28 KeepAliveRegistry::~KeepAliveRegistry() {
29 DCHECK_EQ(0u, registered_tokens_.size());
30 }
31
32 void KeepAliveRegistry::RegisterToken(const std::string& token) {
33 DCHECK(!token.empty());
34
35 registered_tokens_.insert(token);
36
37 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate
38 // that in this class progressively as mechanisms are merged.
39 if (registered_tokens_.size() == 1)
40 chrome::IncrementKeepAliveCount();
41 }
42
43 void KeepAliveRegistry::UnregisterToken(const std::string& token) {
44 RemoveOne(token, registered_tokens_);
45
46 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate
47 // that in this class progressively as mechanisms are merged.
48 if (registered_tokens_.size() == 0)
49 chrome::DecrementKeepAliveCount();
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698