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

Unified Diff: ash/launcher/scoped_observer_with_duplicated_sources.h

Issue 23534023: ash: Minor cleanup, move more files from launcher to shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
« no previous file with comments | « ash/launcher/overflow_button.cc ('k') | ash/launcher/scoped_observer_with_duplicated_sources_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/launcher/scoped_observer_with_duplicated_sources.h
diff --git a/ash/launcher/scoped_observer_with_duplicated_sources.h b/ash/launcher/scoped_observer_with_duplicated_sources.h
deleted file mode 100644
index 60b10f9fae82fe251265685c53f96dba7557b922..0000000000000000000000000000000000000000
--- a/ash/launcher/scoped_observer_with_duplicated_sources.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2013 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 ASH_LAUNCHER_SCOPED_OBSERVER_WITH_DUPLICATED_SOURCES_H_
-#define ASH_LAUNCHER_SCOPED_OBSERVER_WITH_DUPLICATED_SOURCES_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-
-// ScopedObserverWithDuplicatedSources is used to keep track of the set of
-// sources an object has attached itself to as an observer. When
-// ScopedObserverWithDuplicatedSources is destroyed it removes the object as an
-// observer from all sources it has been added to.
-// ScopedObserverWithDuplicatedSources adds |observer| once for a particular
-// source, no matter how many times Add() is invoked. Additionaly |observer| is
-// only removed once Remove() is invoked the same number of times as Add().
-
-template <class Source, class Observer>
-class ScopedObserverWithDuplicatedSources {
- public:
- explicit ScopedObserverWithDuplicatedSources(Observer* observer)
- : observer_(observer) {}
-
- ~ScopedObserverWithDuplicatedSources() {
- typename SourceToAddCountMap::const_iterator iter =
- counted_sources_.begin();
- for (; iter != counted_sources_.end(); ++iter)
- iter->first->RemoveObserver(observer_);
- }
-
- // Adds the object passed to the constructor only once as an observer on
- // |source|.
- void Add(Source* source) {
- if (counted_sources_.find(source) == counted_sources_.end())
- source->AddObserver(observer_);
- counted_sources_[source]++;
- }
-
- // Only remove the object passed to the constructor as an observer from
- // |source| when Remove() is invoked the same number of times as Add().
- void Remove(Source* source) {
- typename SourceToAddCountMap::iterator iter =
- counted_sources_.find(source);
- DCHECK(iter != counted_sources_.end() && iter->second > 0);
-
- if (--iter->second == 0) {
- counted_sources_.erase(source);
- source->RemoveObserver(observer_);
- }
- }
-
- bool IsObserving(Source* source) const {
- return counted_sources_.find(source) != counted_sources_.end();
- }
-
- private:
- typedef std::map<Source*, int> SourceToAddCountMap;
-
- Observer* observer_;
-
- // Map Source and its adding count.
- std::map<Source*, int> counted_sources_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedObserverWithDuplicatedSources);
-};
-
-#endif // ASH_LAUNCHER_SCOPED_OBSERVER_WITH_DUPLICATED_SOURCES_H_
« no previous file with comments | « ash/launcher/overflow_button.cc ('k') | ash/launcher/scoped_observer_with_duplicated_sources_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698