1 // Copyright 2014 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.
5 #ifndef IOS_WEB_WEAK_NSOBJECT_COUNTER_H_
6 #define IOS_WEB_WEAK_NSOBJECT_COUNTER_H_
8 #import <Foundation/Foundation.h>
10 #include "base/memory/linked_ptr.h"
11 #include "base/threading/non_thread_safe.h"
15 // WeakNSObjectCounter is a class to maintain a counter of all the objects
16 // that are added using |Insert| that are alive.
17 // This class is not thread safe and objects must be destroyed and created on
19 // TODO(stuartmorgan): Remove this once ARC is supported.
20 class WeakNSObjectCounter
: public base::NonThreadSafe
{
22 WeakNSObjectCounter();
23 ~WeakNSObjectCounter();
24 // Inserts an object. |object| cannot be nil.
25 void Insert(id object
);
26 // Returns the count of all active objects that have been inserted.
27 NSUInteger
Size() const;
29 // The object that maintains the number of active items.
30 linked_ptr
<NSUInteger
> counter_
;
35 #endif // IOS_WEB_WEAK_NSOBJECT_COUNTER_H_