Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: components/cloud_devices/common/description_items_inl.h

Issue 2287733002: Switch //components away from base::ListValue::Append(Value*) overload. (Closed)
Patch Set: Test fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <utility>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/numerics/safe_conversions.h" 14 #include "base/numerics/safe_conversions.h"
13 #include "components/cloud_devices/common/description_items.h" 15 #include "components/cloud_devices/common/description_items.h"
14 16
15 // Implementation of templates defined in header file. 17 // Implementation of templates defined in header file.
16 // This file should be included from CC file with implementation of device 18 // This file should be included from CC file with implementation of device
17 // specific capabilities. 19 // specific capabilities.
18 20
19 namespace cloud_devices { 21 namespace cloud_devices {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return IsValid(); 60 return IsValid();
59 } 61 }
60 62
61 template <class Option, class Traits> 63 template <class Option, class Traits>
62 void ListCapability<Option, Traits>::SaveTo( 64 void ListCapability<Option, Traits>::SaveTo(
63 CloudDeviceDescription* description) const { 65 CloudDeviceDescription* description) const {
64 DCHECK(IsValid()); 66 DCHECK(IsValid());
65 base::ListValue* options_list = 67 base::ListValue* options_list =
66 description->CreateListItem(Traits::GetCapabilityPath()); 68 description->CreateListItem(Traits::GetCapabilityPath());
67 for (size_t i = 0; i < options_.size(); ++i) { 69 for (size_t i = 0; i < options_.size(); ++i) {
68 base::DictionaryValue* option_value = new base::DictionaryValue; 70 std::unique_ptr<base::DictionaryValue> option_value(
69 options_list->Append(option_value); 71 new base::DictionaryValue);
70 Traits::Save(options_[i], option_value); 72 Traits::Save(options_[i], option_value.get());
73 options_list->Append(std::move(option_value));
blundell 2016/08/29 07:39:15 similar question for my own understanding: is the
dcheng 2016/08/30 17:41:55 It is: one way to think of it is move constructors
71 } 74 }
72 } 75 }
73 76
74 template <class Option, class Traits> 77 template <class Option, class Traits>
75 SelectionCapability<Option, Traits>::SelectionCapability() { 78 SelectionCapability<Option, Traits>::SelectionCapability() {
76 Reset(); 79 Reset();
77 } 80 }
78 81
79 template <class Option, class Traits> 82 template <class Option, class Traits>
80 SelectionCapability<Option, Traits>::~SelectionCapability() { 83 SelectionCapability<Option, Traits>::~SelectionCapability() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 123 }
121 124
122 template <class Option, class Traits> 125 template <class Option, class Traits>
123 void SelectionCapability<Option, Traits>::SaveTo( 126 void SelectionCapability<Option, Traits>::SaveTo(
124 CloudDeviceDescription* description) const { 127 CloudDeviceDescription* description) const {
125 DCHECK(IsValid()); 128 DCHECK(IsValid());
126 base::ListValue* options_list = new base::ListValue; 129 base::ListValue* options_list = new base::ListValue;
127 description->CreateItem(Traits::GetCapabilityPath()) 130 description->CreateItem(Traits::GetCapabilityPath())
128 ->Set(json::kKeyOption, options_list); 131 ->Set(json::kKeyOption, options_list);
129 for (size_t i = 0; i < options_.size(); ++i) { 132 for (size_t i = 0; i < options_.size(); ++i) {
130 base::DictionaryValue* option_value = new base::DictionaryValue; 133 std::unique_ptr<base::DictionaryValue> option_value(
131 options_list->Append(option_value); 134 new base::DictionaryValue);
132 if (base::checked_cast<int>(i) == default_idx_) 135 if (base::checked_cast<int>(i) == default_idx_)
133 option_value->SetBoolean(json::kKeyIsDefault, true); 136 option_value->SetBoolean(json::kKeyIsDefault, true);
134 Traits::Save(options_[i], option_value); 137 Traits::Save(options_[i], option_value.get());
138 options_list->Append(std::move(option_value));
135 } 139 }
136 } 140 }
137 141
138 template <class Traits> 142 template <class Traits>
139 BooleanCapability<Traits>::BooleanCapability() { 143 BooleanCapability<Traits>::BooleanCapability() {
140 Reset(); 144 Reset();
141 } 145 }
142 146
143 template <class Traits> 147 template <class Traits>
144 BooleanCapability<Traits>::~BooleanCapability() { 148 BooleanCapability<Traits>::~BooleanCapability() {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 template <class Option, class Traits> 250 template <class Option, class Traits>
247 void TicketItem<Option, Traits>::SaveTo( 251 void TicketItem<Option, Traits>::SaveTo(
248 CloudDeviceDescription* description) const { 252 CloudDeviceDescription* description) const {
249 DCHECK(IsValid()); 253 DCHECK(IsValid());
250 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath())); 254 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath()));
251 } 255 }
252 256
253 } // namespace cloud_devices 257 } // namespace cloud_devices
254 258
255 #endif // COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ 259 #endif // COMPONENTS_CLOUD_DEVICES_COMMON_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698