Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Copyright (c) 2006-2008 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 BASE_REVOCABLE_STORE_H_
6 #define BASE_REVOCABLE_STORE_H_
8 #include "base/ref_counted.h"
10 // |RevocableStore| is a container of items that can be removed from the store.
11 class RevocableStore {
12 public:
13 // A |StoreRef| is used to link the |RevocableStore| to its items. There is
14 // one StoreRef per store, and each item holds a reference to it. If the
15 // store wishes to revoke its items, it sets |store_| to null. Items are
16 // permitted to release their reference to the |StoreRef| when they no longer
17 // require the store.
18 class StoreRef : public base::RefCounted<StoreRef> {
19 public:
20 StoreRef(RevocableStore* store) : store_(store) { }
22 void set_store(RevocableStore* store) { store_ = store; }
23 RevocableStore* store() const { return store_; }
25 private:
26 RevocableStore* store_;
28 DISALLOW_EVIL_CONSTRUCTORS(StoreRef);
29 };
31 // An item in the store. On construction, the object adds itself to the
32 // store.
33 class Revocable {
34 public:
35 Revocable(RevocableStore* store);
36 ~Revocable();
38 // This item has been revoked if it no longer has a pointer to the store.
39 bool revoked() const { return !store_reference_->store(); }
41 private:
42 // We hold a reference to the store through this ref pointer. We release
43 // this reference on destruction.
44 scoped_refptr<StoreRef> store_reference_;
46 DISALLOW_EVIL_CONSTRUCTORS(Revocable);
47 };
49 RevocableStore();
50 ~RevocableStore();
52 // Revokes all the items in the store.
53 void RevokeAll();
55 // Returns true if there are no items in the store.
56 bool empty() const { return count_ == 0; }
58 private:
59 friend class Revocable;
61 // Adds an item to the store. To add an item to the store, construct it
62 // with a pointer to the store.
63 void Add(Revocable* item);
65 // This is the reference the unrevoked items in the store hold.
66 scoped_refptr<StoreRef> owning_reference_;
68 // The number of unrevoked items in the store.
69 int count_;
71 DISALLOW_EVIL_CONSTRUCTORS(RevocableStore);
72 };
74 #endif // BASE_REVOCABLE_STORE_H_