Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: ios/chrome/browser/callback_counter.h

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/callback_counter.h
diff --git a/ios/chrome/browser/callback_counter.h b/ios/chrome/browser/callback_counter.h
new file mode 100644
index 0000000000000000000000000000000000000000..45118765f8c2e6ace80797f6ed3192749ab1d947
--- /dev/null
+++ b/ios/chrome/browser/callback_counter.h
@@ -0,0 +1,42 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_
+#define IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/threading/thread.h"
+
+// A helper class that keeps count of the number of pending callbacks that need
+// to be received. Calls |final_callback| when all callbacks have been received.
+// All methods (except the destructor) must be called on the same thread.
+class CallbackCounter : public base::RefCounted<CallbackCounter> {
+ public:
+ typedef base::Callback<void()> FinalCallback;
+
+ explicit CallbackCounter(const FinalCallback& final_callback);
+
+ // Increments the count of pending callbacks.
+ void IncrementCount();
+ // Decrements the count of pending callbacks.
+ void DecrementCount();
+
+ private:
+ friend class base::RefCounted<CallbackCounter>;
+
+ ~CallbackCounter();
+
+ // The number of callbacks that still need to be received.
+ unsigned callback_count_;
+ // The callback that is finally called when all callbacks have been received
+ // (when the |callback_count_| goes down to 0).
+ FinalCallback final_callback_;
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(CallbackCounter);
+};
+
+#endif // IOS_CHROME_BROWSER_CALLBACK_COUNTER_H_
« no previous file with comments | « ios/chrome/browser/browsing_data/browsing_data_removal_controller_unittest.mm ('k') | ios/chrome/browser/callback_counter.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698