Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / event_filtering_info.cc
blob877f2c5caba9664feb9ba8a6b512fcbddb516369
1 // Copyright (c) 2012 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 "extensions/common/event_filtering_info.h"
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
10 namespace extensions {
12 EventFilteringInfo::EventFilteringInfo()
13 : has_url_(false),
14 has_instance_id_(false),
15 instance_id_(0) {
18 EventFilteringInfo::~EventFilteringInfo() {
21 void EventFilteringInfo::SetURL(const GURL& url) {
22 url_ = url;
23 has_url_ = true;
26 void EventFilteringInfo::SetInstanceID(int instance_id) {
27 instance_id_ = instance_id;
28 has_instance_id_ = true;
31 scoped_ptr<base::Value> EventFilteringInfo::AsValue() const {
32 if (IsEmpty())
33 return scoped_ptr<base::Value>(base::Value::CreateNullValue());
35 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
36 if (has_url_)
37 result->SetString("url", url_.spec());
39 if (has_instance_id_)
40 result->SetInteger("instanceId", instance_id_);
42 if (!service_type_.empty())
43 result->SetString("serviceType", service_type_);
45 return result.PassAs<base::Value>();
48 bool EventFilteringInfo::IsEmpty() const {
49 return !has_url_ && service_type_.empty() && !has_instance_id_;
52 } // namespace extensions