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 #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 } | |
| OLD | NEW |