Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // Helper function to remove one token from the multisets. | |
|
Bernhard Bauer
2016/02/19 17:39:28
Empty line after opening the namespace.
dgn
2016/02/19 18:04:28
Done.
| |
| 12 void RemoveOne(const std::string& key, std::multiset<std::string>& container) { | |
| 13 auto it = container.find(key); | |
| 14 if (it != container.end()) | |
|
Bernhard Bauer
2016/02/19 17:39:28
I would DCHECK this -- it shouldn't be possible to
dgn
2016/02/19 18:04:28
Done.
| |
| 15 container.erase(it); | |
| 16 } | |
| 17 } | |
|
Bernhard Bauer
2016/02/19 17:39:28
// namespace
dgn
2016/02/19 18:04:28
Done.
| |
| 18 | |
| 19 // static | |
| 20 KeepAliveRegistry* KeepAliveRegistry::GetInstance() { | |
| 21 return base::Singleton<KeepAliveRegistry>::get(); | |
| 22 } | |
| 23 | |
| 24 KeepAliveRegistry::KeepAliveRegistry() {} | |
| 25 | |
| 26 KeepAliveRegistry::~KeepAliveRegistry() { | |
| 27 DCHECK_EQ(registered_tokens_.size(), 0u); | |
|
Bernhard Bauer
2016/02/19 17:39:28
Put the expected value first for nicer error messa
dgn
2016/02/19 18:04:28
Done.
| |
| 28 DCHECK_EQ(reset_allowed_tokens_.size(), 0u); | |
| 29 } | |
| 30 | |
| 31 void KeepAliveRegistry::RegisterToken(const std::string& token, | |
| 32 OptimizationOptions opt) { | |
| 33 DCHECK(!token.empty()); | |
| 34 | |
| 35 registered_tokens_.insert(token); | |
| 36 | |
| 37 if (opt == OptimizationOptions::RESTART_ALLOWED) | |
| 38 reset_allowed_tokens_.insert(token); | |
| 39 | |
| 40 // TODO(dgn): If this is the first non RESTART_ALLOWED token, we are now busy. | |
| 41 | |
| 42 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate | |
| 43 // that in this class progressively as mechanisms are merged. | |
| 44 if (registered_tokens_.size() == 1) | |
| 45 chrome::IncrementKeepAliveCount(); | |
| 46 } | |
| 47 | |
| 48 void KeepAliveRegistry::UnregisterToken(const std::string& token, | |
| 49 OptimizationOptions opt) { | |
| 50 RemoveOne(token, registered_tokens_); | |
| 51 | |
| 52 if (opt == OptimizationOptions::RESTART_ALLOWED) | |
| 53 RemoveOne(token, reset_allowed_tokens_); | |
| 54 | |
| 55 // TODO(dgn): If this is the last non RESTART_ALLOWED token, we are now idle. | |
| 56 | |
| 57 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate | |
| 58 // that in this class progressively as mechanisms are merged. | |
| 59 if (registered_tokens_.size() == 0) | |
| 60 chrome::DecrementKeepAliveCount(); | |
| 61 } | |
| OLD | NEW |