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 //////////////////////////////////////////////////////////////////////////////// |
| 32 // Private methods |
| 33 |
| 34 KeepAliveRegistry::KeepAliveRegistry() {} |
| 35 |
| 36 KeepAliveRegistry::~KeepAliveRegistry() { |
| 37 DCHECK_EQ(0u, registered_keep_alives_.size()); |
| 38 } |
| 39 |
| 40 void KeepAliveRegistry::Register(const KeepAliveOptions* option) { |
| 41 registered_keep_alives_.insert(option); |
| 42 |
| 43 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
| 44 // that in this class progressively as mechanisms are merged. |
| 45 if (registered_keep_alives_.size() == 1) |
| 46 chrome::IncrementKeepAliveCount(); |
| 47 } |
| 48 |
| 49 void KeepAliveRegistry::Unregister(const KeepAliveOptions* option) { |
| 50 RemoveOne(option, registered_keep_alives_); |
| 51 |
| 52 |
| 53 // TODO(dgn): We currently use the plain KeepAliveCount. We will integrate |
| 54 // that in this class progressively as mechanisms are merged. |
| 55 if (registered_keep_alives_.size() == 0) |
| 56 chrome::DecrementKeepAliveCount(); |
| 57 } |
OLD | NEW |