ipc/chromium/src/base/revocable_store.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/revocable_store.h"
michael@0 6
michael@0 7 #include "base/logging.h"
michael@0 8
michael@0 9 RevocableStore::Revocable::Revocable(RevocableStore* store)
michael@0 10 : store_reference_(store->owning_reference_) {
michael@0 11 // We AddRef() the owning reference.
michael@0 12 DCHECK(store_reference_->store());
michael@0 13 store_reference_->store()->Add(this);
michael@0 14 }
michael@0 15
michael@0 16 RevocableStore::Revocable::~Revocable() {
michael@0 17 if (!revoked()) {
michael@0 18 // Notify the store of our destruction.
michael@0 19 --(store_reference_->store()->count_);
michael@0 20 }
michael@0 21 }
michael@0 22
michael@0 23 RevocableStore::RevocableStore() : count_(0) {
michael@0 24 // Create a new owning reference.
michael@0 25 owning_reference_ = new StoreRef(this);
michael@0 26 }
michael@0 27
michael@0 28 RevocableStore::~RevocableStore() {
michael@0 29 // Revoke all the items in the store.
michael@0 30 owning_reference_->set_store(NULL);
michael@0 31 }
michael@0 32
michael@0 33 void RevocableStore::Add(Revocable* item) {
michael@0 34 DCHECK(!item->revoked());
michael@0 35 ++count_;
michael@0 36 }
michael@0 37
michael@0 38 void RevocableStore::RevokeAll() {
michael@0 39 // We revoke all the existing items in the store and reset our count.
michael@0 40 owning_reference_->set_store(NULL);
michael@0 41 count_ = 0;
michael@0 42
michael@0 43 // Then we create a new owning reference for new items that get added.
michael@0 44 // This Release()s the old owning reference, allowing it to be freed after
michael@0 45 // all the items that were in the store are eventually destroyed.
michael@0 46 owning_reference_ = new StoreRef(this);
michael@0 47 }

mercurial