| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "ios/chrome/browser/callback_counter.h" | 5 #include "ios/chrome/browser/callback_counter.h" | 
| 6 | 6 | 
|  | 7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
|  | 8 #error "This file requires ARC support." | 
|  | 9 #endif | 
|  | 10 | 
| 7 CallbackCounter::CallbackCounter(const FinalCallback& final_callback) | 11 CallbackCounter::CallbackCounter(const FinalCallback& final_callback) | 
| 8     : callback_count_(0U), final_callback_(final_callback) { | 12     : callback_count_(0U), final_callback_(final_callback) { | 
| 9   DCHECK(!final_callback.is_null()); | 13   DCHECK(!final_callback.is_null()); | 
| 10 } | 14 } | 
| 11 | 15 | 
| 12 CallbackCounter::~CallbackCounter() { | 16 CallbackCounter::~CallbackCounter() { | 
| 13   DCHECK_EQ(0U, callback_count_); | 17   DCHECK_EQ(0U, callback_count_); | 
| 14 } | 18 } | 
| 15 | 19 | 
| 16 void CallbackCounter::IncrementCount() { | 20 void CallbackCounter::IncrementCount() { | 
| 17   DCHECK(thread_checker_.CalledOnValidThread()); | 21   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 18   DCHECK(!final_callback_.is_null()); | 22   DCHECK(!final_callback_.is_null()); | 
| 19   ++callback_count_; | 23   ++callback_count_; | 
| 20 } | 24 } | 
| 21 | 25 | 
| 22 void CallbackCounter::DecrementCount() { | 26 void CallbackCounter::DecrementCount() { | 
| 23   DCHECK(thread_checker_.CalledOnValidThread()); | 27   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 24   DCHECK(callback_count_); | 28   DCHECK(callback_count_); | 
| 25 | 29 | 
| 26   --callback_count_; | 30   --callback_count_; | 
| 27   if (callback_count_ == 0) { | 31   if (callback_count_ == 0) { | 
| 28     final_callback_.Run(); | 32     final_callback_.Run(); | 
| 29     final_callback_.Reset(); | 33     final_callback_.Reset(); | 
| 30   } | 34   } | 
| 31 } | 35 } | 
| OLD | NEW | 
|---|