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

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

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
« no previous file with comments | « ios/chrome/browser/callback_counter.h ('k') | ios/chrome/browser/callback_counter_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/callback_counter.mm
diff --git a/ios/chrome/browser/callback_counter.mm b/ios/chrome/browser/callback_counter.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ffe4642a4a74c757ee034b591249d46afba7b1a6
--- /dev/null
+++ b/ios/chrome/browser/callback_counter.mm
@@ -0,0 +1,31 @@
+// 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.
+
+#include "ios/chrome/browser/callback_counter.h"
+
+CallbackCounter::CallbackCounter(const FinalCallback& final_callback)
+ : callback_count_(0U), final_callback_(final_callback) {
+ DCHECK(!final_callback.is_null());
+}
+
+CallbackCounter::~CallbackCounter() {
+ DCHECK_EQ(0U, callback_count_);
+}
+
+void CallbackCounter::IncrementCount() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!final_callback_.is_null());
+ ++callback_count_;
+}
+
+void CallbackCounter::DecrementCount() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(callback_count_);
+
+ --callback_count_;
+ if (callback_count_ == 0) {
+ final_callback_.Run();
+ final_callback_.Reset();
+ }
+}
« no previous file with comments | « ios/chrome/browser/callback_counter.h ('k') | ios/chrome/browser/callback_counter_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698