diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-05 01:04:57 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-05 01:04:57 +0000 |
commit | d9e559d917fb5e7f9ffb518a233c7008d1fb6c9f (patch) | |
tree | a46f1a17e11759f5ccf18ab07dfc627f4098d89c /chrome/common/extensions/value_counter.cc | |
parent | e49a5816217cf42405b7e228d661f31625dc0fb8 (diff) | |
download | chromium_src-d9e559d917fb5e7f9ffb518a233c7008d1fb6c9f.zip chromium_src-d9e559d917fb5e7f9ffb518a233c7008d1fb6c9f.tar.gz chromium_src-d9e559d917fb5e7f9ffb518a233c7008d1fb6c9f.tar.bz2 |
Filtered events.
Makes web_navigation events support filters, eg:
chrome.webNavigation.onBeforeCommitted.addListener(callback, {url: [{hostSuffix: 'google.com'}]});
Now callback will only be called when the event has a URL with a host suffix of google.com.
BUG=121479
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=143872
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=143874
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=143896
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=145145
Review URL: https://chromiumcodereview.appspot.com/10514013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145484 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/value_counter.cc')
-rw-r--r-- | chrome/common/extensions/value_counter.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/common/extensions/value_counter.cc b/chrome/common/extensions/value_counter.cc new file mode 100644 index 0000000..156e3ad --- /dev/null +++ b/chrome/common/extensions/value_counter.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2012 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. + +#include "chrome/common/extensions/value_counter.h" + +#include "base/values.h" + +#include <algorithm> + +namespace extensions { + +ValueCounter::ValueCounter() { +} + +ValueCounter::~ValueCounter() { +} + +ValueCounter::Entry::Entry(const base::Value& value) + : value_(value.DeepCopy()), + count_(1) { +} + +ValueCounter::Entry::~Entry() { +} + +int ValueCounter::Entry::Increment() { + return ++count_; +} + +int ValueCounter::Entry::Decrement() { + return --count_; +} + +int ValueCounter::Add(const base::Value& value) { + return AddImpl(value, true); +} + +int ValueCounter::Remove(const base::Value& value) { + for (EntryList::iterator it = entries_.begin(); it != entries_.end(); it++) { + (*it)->value()->GetType(); + if ((*it)->value()->Equals(&value)) { + int remaining = (*it)->Decrement(); + if (remaining == 0) { + std::swap(*it, entries_.back()); + entries_.pop_back(); + } + return remaining; + } + } + return 0; +} + +int ValueCounter::AddIfMissing(const base::Value& value) { + return AddImpl(value, false); +} + +int ValueCounter::AddImpl(const base::Value& value, bool increment) { + for (EntryList::iterator it = entries_.begin(); it != entries_.end(); it++) { + if ((*it)->value()->Equals(&value)) + return increment ? (*it)->Increment() : (*it)->count(); + } + entries_.push_back(linked_ptr<Entry>(new Entry(value))); + return 1; +} + +} // namespace extensions |