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

Unified Diff: ios/web/weak_nsobject_counter.h

Issue 988383002: Upstream various ios/web utilities and helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-public-upstreaming
Patch Set: Created 5 years, 9 months 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/web/weak_nsobject_counter.h
diff --git a/ios/web/weak_nsobject_counter.h b/ios/web/weak_nsobject_counter.h
new file mode 100644
index 0000000000000000000000000000000000000000..f5fb62fa75d493d58f0df78232fe2f661a45d59c
--- /dev/null
+++ b/ios/web/weak_nsobject_counter.h
@@ -0,0 +1,35 @@
+// Copyright 2014 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_WEB_WEAK_NSOBJECT_COUNTER_H_
+#define IOS_WEB_WEAK_NSOBJECT_COUNTER_H_
+
+#import <Foundation/Foundation.h>
+
+#include "base/memory/linked_ptr.h"
+#include "base/threading/non_thread_safe.h"
+
+namespace web {
+
+// WeakNSObjectCounter is a class to maintain a counter of all the objects
+// that are added using |Insert| that are alive.
+// This class is not thread safe and objects must be destroyed and created on
+// the same thread.
+// TODO(stuartmorgan): Remove this once ARC is supported.
+class WeakNSObjectCounter : public base::NonThreadSafe {
+ public:
+ WeakNSObjectCounter();
+ ~WeakNSObjectCounter();
+ // Inserts an object. |object| cannot be nil.
+ void Insert(id object);
+ // Returns the count of all active objects that have been inserted.
+ NSUInteger Size() const;
+ private:
+ // The object that maintains the number of active items.
+ linked_ptr<NSUInteger> counter_;
+};
+
+} // namespace web
+
+#endif // IOS_WEB_WEAK_NSOBJECT_COUNTER_H_

Powered by Google App Engine
This is Rietveld 408576698