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.

     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 #include "base/revocable_store.h"
     7 #include "base/logging.h"
     9 RevocableStore::Revocable::Revocable(RevocableStore* store)
    10     : store_reference_(store->owning_reference_) {
    11   // We AddRef() the owning reference.
    12   DCHECK(store_reference_->store());
    13   store_reference_->store()->Add(this);
    14 }
    16 RevocableStore::Revocable::~Revocable() {
    17   if (!revoked()) {
    18     // Notify the store of our destruction.
    19     --(store_reference_->store()->count_);
    20   }
    21 }
    23 RevocableStore::RevocableStore() : count_(0) {
    24   // Create a new owning reference.
    25   owning_reference_ = new StoreRef(this);
    26 }
    28 RevocableStore::~RevocableStore() {
    29   // Revoke all the items in the store.
    30   owning_reference_->set_store(NULL);
    31 }
    33 void RevocableStore::Add(Revocable* item) {
    34   DCHECK(!item->revoked());
    35   ++count_;
    36 }
    38 void RevocableStore::RevokeAll() {
    39   // We revoke all the existing items in the store and reset our count.
    40   owning_reference_->set_store(NULL);
    41   count_ = 0;
    43   // Then we create a new owning reference for new items that get added.
    44   // This Release()s the old owning reference, allowing it to be freed after
    45   // all the items that were in the store are eventually destroyed.
    46   owning_reference_ = new StoreRef(this);
    47 }

mercurial