| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/common/event_filtering_info.h" | 5 #include "extensions/common/event_filtering_info.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 | 12 |
| 12 namespace extensions { | 13 namespace extensions { |
| 13 | 14 |
| 14 EventFilteringInfo::EventFilteringInfo() | 15 EventFilteringInfo::EventFilteringInfo() |
| 15 : has_url_(false), | 16 : has_url_(false), |
| 16 has_instance_id_(false), | 17 has_instance_id_(false), |
| 17 instance_id_(0), | 18 instance_id_(0), |
| 18 has_window_type_(false), | 19 has_window_type_(false), |
| 19 has_window_exposed_by_default_(false) {} | 20 has_window_exposed_by_default_(false) {} |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 void EventFilteringInfo::SetURL(const GURL& url) { | 38 void EventFilteringInfo::SetURL(const GURL& url) { |
| 38 url_ = url; | 39 url_ = url; |
| 39 has_url_ = true; | 40 has_url_ = true; |
| 40 } | 41 } |
| 41 | 42 |
| 42 void EventFilteringInfo::SetInstanceID(int instance_id) { | 43 void EventFilteringInfo::SetInstanceID(int instance_id) { |
| 43 instance_id_ = instance_id; | 44 instance_id_ = instance_id; |
| 44 has_instance_id_ = true; | 45 has_instance_id_ = true; |
| 45 } | 46 } |
| 46 | 47 |
| 47 std::unique_ptr<base::Value> EventFilteringInfo::AsValue() const { | 48 std::unique_ptr<base::DictionaryValue> EventFilteringInfo::AsValue() const { |
| 48 if (IsEmpty()) | 49 auto result = base::MakeUnique<base::DictionaryValue>(); |
| 49 return base::Value::CreateNullValue(); | |
| 50 | |
| 51 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); | |
| 52 if (has_url_) | 50 if (has_url_) |
| 53 result->SetString("url", url_.spec()); | 51 result->SetString("url", url_.spec()); |
| 54 | 52 |
| 55 if (has_instance_id_) | 53 if (has_instance_id_) |
| 56 result->SetInteger("instanceId", instance_id_); | 54 result->SetInteger("instanceId", instance_id_); |
| 57 | 55 |
| 58 if (!service_type_.empty()) | 56 if (!service_type_.empty()) |
| 59 result->SetString("serviceType", service_type_); | 57 result->SetString("serviceType", service_type_); |
| 60 | 58 |
| 61 if (has_window_type_) | 59 if (has_window_type_) |
| 62 result->SetString("windowType", window_type_); | 60 result->SetString("windowType", window_type_); |
| 63 | 61 |
| 64 if (has_window_exposed_by_default_) | 62 if (has_window_exposed_by_default_) |
| 65 result->SetBoolean("windowExposedByDefault", window_exposed_by_default_); | 63 result->SetBoolean("windowExposedByDefault", window_exposed_by_default_); |
| 66 | 64 |
| 67 return std::move(result); | 65 return result; |
| 68 } | |
| 69 | |
| 70 bool EventFilteringInfo::IsEmpty() const { | |
| 71 return !has_window_type_ && !has_url_ && service_type_.empty() && | |
| 72 !has_instance_id_ && !has_window_exposed_by_default_; | |
| 73 } | 66 } |
| 74 | 67 |
| 75 } // namespace extensions | 68 } // namespace extensions |
| OLD | NEW |