diff options
author | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 18:25:57 +0000 |
---|---|---|
committer | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 18:25:57 +0000 |
commit | 267864ead556030ad3413bcb8e466cbdc31986bb (patch) | |
tree | ab373536392771465b31367f037b0866b39fb851 /extensions | |
parent | 779a78fb020cba65f0038a0e7818893ebb509877 (diff) | |
download | chromium_src-267864ead556030ad3413bcb8e466cbdc31986bb.zip chromium_src-267864ead556030ad3413bcb8e466cbdc31986bb.tar.gz chromium_src-267864ead556030ad3413bcb8e466cbdc31986bb.tar.bz2 |
Initial chrome.mdns API.
BUG=280900
TBR=erg
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=221619
Review URL: https://chromiumcodereview.appspot.com/23437015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/common/event_filtering_info.cc | 6 | ||||
-rw-r--r-- | extensions/common/event_filtering_info.h | 7 | ||||
-rw-r--r-- | extensions/common/event_matcher.cc | 17 | ||||
-rw-r--r-- | extensions/common/event_matcher.h | 4 |
4 files changed, 30 insertions, 4 deletions
diff --git a/extensions/common/event_filtering_info.cc b/extensions/common/event_filtering_info.cc index 29566e8..cc46f96 100644 --- a/extensions/common/event_filtering_info.cc +++ b/extensions/common/event_filtering_info.cc @@ -38,11 +38,15 @@ scoped_ptr<base::Value> EventFilteringInfo::AsValue() const { if (has_instance_id_) result->SetInteger("instanceId", instance_id_); + + if (!service_type_.empty()) + result->SetString("serviceType", service_type_); + return result.PassAs<base::Value>(); } bool EventFilteringInfo::IsEmpty() const { - return !has_url_; + return !has_url_ && service_type_.empty(); } } // namespace extensions diff --git a/extensions/common/event_filtering_info.h b/extensions/common/event_filtering_info.h index 86309ab..a358798 100644 --- a/extensions/common/event_filtering_info.h +++ b/extensions/common/event_filtering_info.h @@ -28,6 +28,9 @@ class EventFilteringInfo { ~EventFilteringInfo(); void SetURL(const GURL& url); void SetInstanceID(int instance_id); + void SetServiceType(const std::string& service_type) { + service_type_ = service_type; + } bool has_url() const { return has_url_; } const GURL& url() const { return url_; } @@ -35,12 +38,16 @@ class EventFilteringInfo { bool has_instance_id() const { return has_instance_id_; } int instance_id() const { return instance_id_; } + bool has_service_type() const { return !service_type_.empty(); } + const std::string& service_type() const { return service_type_; } + scoped_ptr<base::Value> AsValue() const; bool IsEmpty() const; private: bool has_url_; GURL url_; + std::string service_type_; bool has_instance_id_; int instance_id_; diff --git a/extensions/common/event_matcher.cc b/extensions/common/event_matcher.cc index ad76c89..8ae022a 100644 --- a/extensions/common/event_matcher.cc +++ b/extensions/common/event_matcher.cc @@ -12,6 +12,8 @@ const char kUrlFiltersKey[] = "url"; namespace extensions { +const char kEventFilterServiceTypeKey[] = "serviceType"; + EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, int routing_id) : filter_(filter.Pass()), @@ -23,10 +25,13 @@ EventMatcher::~EventMatcher() { bool EventMatcher::MatchNonURLCriteria( const EventFilteringInfo& event_info) const { - if (!event_info.has_instance_id()) - return true; + if (event_info.has_instance_id()) { + return event_info.instance_id() == GetInstanceID(); + } - return event_info.instance_id() == GetInstanceID(); + const std::string& service_type_filter = GetServiceTypeFilter(); + return service_type_filter.empty() || + service_type_filter == event_info.service_type(); } int EventMatcher::GetURLFilterCount() const { @@ -48,6 +53,12 @@ int EventMatcher::HasURLFilters() const { return GetURLFilterCount() != 0; } +std::string EventMatcher::GetServiceTypeFilter() const { + std::string service_type_filter; + filter_->GetStringASCII(kEventFilterServiceTypeKey, &service_type_filter); + return service_type_filter; +} + int EventMatcher::GetInstanceID() const { int instance_id = 0; filter_->GetInteger("instanceId", &instance_id); diff --git a/extensions/common/event_matcher.h b/extensions/common/event_matcher.h index 7843fce..bd0ce7b 100644 --- a/extensions/common/event_matcher.h +++ b/extensions/common/event_matcher.h @@ -12,6 +12,8 @@ namespace extensions { class EventFilteringInfo; +extern const char kEventFilterServiceTypeKey[]; + // Matches EventFilteringInfos against a set of criteria. This is intended to // be used by EventFilter which performs efficient URL matching across // potentially many EventMatchers itself. This is why this class only exposes @@ -29,6 +31,8 @@ class EventMatcher { int GetURLFilterCount() const; bool GetURLFilter(int i, base::DictionaryValue** url_filter_out); + std::string GetServiceTypeFilter() const; + int HasURLFilters() const; int GetInstanceID() const; |