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

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: 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 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 #include "chrome/browser/lifetime/keep_alive_options.h"
10
11 namespace {
12
13 // Helper function to remove one item from the multisets.
14 void RemoveOne(const KeepAliveOptions* key,
15 std::multiset<const KeepAliveOptions*>& container) {
16 auto it = container.find(key);
17 DCHECK(it != container.end());
18 container.erase(it);
19 }
20
21 } // namespace
22
23 ////////////////////////////////////////////////////////////////////////////////
24 // Public methods
25
26 // static
27 KeepAliveRegistry* KeepAliveRegistry::GetInstance() {
28 return base::Singleton<KeepAliveRegistry>::get();
29 }
30
31 void KeepAliveRegistry::Register(const KeepAliveOptions* option) {
32 registered_keep_alives_.insert(option);
33 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.
34 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate
35 // that in this class progressively as mechanisms are merged.
36 if (registered_keep_alives_.size() == 1)
37 chrome::IncrementKeepAliveCount();
38 }
39
40 void KeepAliveRegistry::Unregister(const KeepAliveOptions* option) {
41 RemoveOne(option, registered_keep_alives_);
42 LOG(ERROR) << "DGN - Decrement";
43
44 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate
45 // that in this class progressively as mechanisms are merged.
46 if (registered_keep_alives_.size() == 0)
47 chrome::DecrementKeepAliveCount();
48 }
49
50 ////////////////////////////////////////////////////////////////////////////////
51 // Private methods
52
53 KeepAliveRegistry::KeepAliveRegistry() {}
54
55 KeepAliveRegistry::~KeepAliveRegistry() {
56 DCHECK_EQ(0u, registered_keep_alives_.size());
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698