OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ios/chrome/browser/callback_counter.h" |
| 6 |
| 7 CallbackCounter::CallbackCounter(const FinalCallback& final_callback) |
| 8 : callback_count_(0U), final_callback_(final_callback) { |
| 9 DCHECK(!final_callback.is_null()); |
| 10 } |
| 11 |
| 12 CallbackCounter::~CallbackCounter() { |
| 13 DCHECK_EQ(0U, callback_count_); |
| 14 } |
| 15 |
| 16 void CallbackCounter::IncrementCount() { |
| 17 DCHECK(thread_checker_.CalledOnValidThread()); |
| 18 DCHECK(!final_callback_.is_null()); |
| 19 ++callback_count_; |
| 20 } |
| 21 |
| 22 void CallbackCounter::DecrementCount() { |
| 23 DCHECK(thread_checker_.CalledOnValidThread()); |
| 24 DCHECK(callback_count_); |
| 25 |
| 26 --callback_count_; |
| 27 if (callback_count_ == 0) { |
| 28 final_callback_.Run(); |
| 29 final_callback_.Reset(); |
| 30 } |
| 31 } |
OLD | NEW |