OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ | 5 #ifndef COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ |
6 #define COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ | 6 #define COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/values.h" |
15 #include "components/cloud_devices/common/description_items.h" | 17 #include "components/cloud_devices/common/description_items.h" |
16 | 18 |
17 // Implementation of templates defined in header file. | 19 // Implementation of templates defined in header file. |
18 // This file should be included from CC file with implementation of device | 20 // This file should be included from CC file with implementation of device |
19 // specific capabilities. | 21 // specific capabilities. |
20 | 22 |
21 namespace cloud_devices { | 23 namespace cloud_devices { |
22 | 24 |
23 template <class Option, class Traits> | 25 template <class Option, class Traits> |
24 ListCapability<Option, Traits>::ListCapability() { | 26 ListCapability<Option, Traits>::ListCapability() { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 121 } |
120 AddDefaultOption(option, is_default); | 122 AddDefaultOption(option, is_default); |
121 } | 123 } |
122 return IsValid(); | 124 return IsValid(); |
123 } | 125 } |
124 | 126 |
125 template <class Option, class Traits> | 127 template <class Option, class Traits> |
126 void SelectionCapability<Option, Traits>::SaveTo( | 128 void SelectionCapability<Option, Traits>::SaveTo( |
127 CloudDeviceDescription* description) const { | 129 CloudDeviceDescription* description) const { |
128 DCHECK(IsValid()); | 130 DCHECK(IsValid()); |
129 base::ListValue* options_list = new base::ListValue; | 131 auto options_list = base::MakeUnique<base::ListValue>(); |
130 description->CreateItem(Traits::GetCapabilityPath()) | |
131 ->Set(json::kKeyOption, options_list); | |
132 for (size_t i = 0; i < options_.size(); ++i) { | 132 for (size_t i = 0; i < options_.size(); ++i) { |
133 std::unique_ptr<base::DictionaryValue> option_value( | 133 auto option_value = base::MakeUnique<base::DictionaryValue>(); |
134 new base::DictionaryValue); | |
135 if (base::checked_cast<int>(i) == default_idx_) | 134 if (base::checked_cast<int>(i) == default_idx_) |
136 option_value->SetBoolean(json::kKeyIsDefault, true); | 135 option_value->SetBoolean(json::kKeyIsDefault, true); |
137 Traits::Save(options_[i], option_value.get()); | 136 Traits::Save(options_[i], option_value.get()); |
138 options_list->Append(std::move(option_value)); | 137 options_list->Append(std::move(option_value)); |
139 } | 138 } |
| 139 description->CreateItem(Traits::GetCapabilityPath()) |
| 140 ->Set(json::kKeyOption, std::move(options_list)); |
140 } | 141 } |
141 | 142 |
142 template <class Traits> | 143 template <class Traits> |
143 BooleanCapability<Traits>::BooleanCapability() { | 144 BooleanCapability<Traits>::BooleanCapability() { |
144 Reset(); | 145 Reset(); |
145 } | 146 } |
146 | 147 |
147 template <class Traits> | 148 template <class Traits> |
148 BooleanCapability<Traits>::~BooleanCapability() { | 149 BooleanCapability<Traits>::~BooleanCapability() { |
149 } | 150 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 template <class Option, class Traits> | 251 template <class Option, class Traits> |
251 void TicketItem<Option, Traits>::SaveTo( | 252 void TicketItem<Option, Traits>::SaveTo( |
252 CloudDeviceDescription* description) const { | 253 CloudDeviceDescription* description) const { |
253 DCHECK(IsValid()); | 254 DCHECK(IsValid()); |
254 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath())); | 255 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath())); |
255 } | 256 } |
256 | 257 |
257 } // namespace cloud_devices | 258 } // namespace cloud_devices |
258 | 259 |
259 #endif // COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ | 260 #endif // COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ |
OLD | NEW |