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 #ifndef IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_ |
| 6 #define IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/threading/thread.h" |
| 12 |
| 13 // A helper class that keeps count of the number of pending callbacks that need |
| 14 // to be received. Calls |final_callback| when all callbacks have been received. |
| 15 // All methods (except the destructor) must be called on the same thread. |
| 16 class CallbackCounter : public base::RefCounted<CallbackCounter> { |
| 17 public: |
| 18 typedef base::Callback<void()> FinalCallback; |
| 19 |
| 20 explicit CallbackCounter(const FinalCallback& final_callback); |
| 21 |
| 22 // Increments the count of pending callbacks. |
| 23 void IncrementCount(); |
| 24 // Decrements the count of pending callbacks. |
| 25 void DecrementCount(); |
| 26 |
| 27 private: |
| 28 friend class base::RefCounted<CallbackCounter>; |
| 29 |
| 30 ~CallbackCounter(); |
| 31 |
| 32 // The number of callbacks that still need to be received. |
| 33 unsigned callback_count_; |
| 34 // The callback that is finally called when all callbacks have been received |
| 35 // (when the |callback_count_| goes down to 0). |
| 36 FinalCallback final_callback_; |
| 37 base::ThreadChecker thread_checker_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(CallbackCounter); |
| 40 }; |
| 41 |
| 42 #endif // IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_ |
OLD | NEW |