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

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

Issue 171683020: Use to base::checked_cast. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « components/cloud_devices/description_items.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ 5 #ifndef COMPONENTS_CLOUD_DEVICES_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_
6 #define COMPONENTS_CLOUD_DEVICES_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ 6 #define COMPONENTS_CLOUD_DEVICES_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/numerics/safe_conversions.h"
10 #include "components/cloud_devices/description_items.h" 11 #include "components/cloud_devices/description_items.h"
11 12
12 // Implementation of templates defined in header file. 13 // Implementation of templates defined in header file.
13 // This file should be included from CC file with implementation of device 14 // This file should be included from CC file with implementation of device
14 // specific capabilities. 15 // specific capabilities.
15 16
16 namespace cloud_devices { 17 namespace cloud_devices {
17 18
18 template <class Option, class Traits> 19 template <class Option, class Traits>
19 ListCapability<Option, Traits>::ListCapability() { 20 ListCapability<Option, Traits>::ListCapability() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 SelectionCapability<Option, Traits>::~SelectionCapability() { } 77 SelectionCapability<Option, Traits>::~SelectionCapability() { }
77 78
78 template <class Option, class Traits> 79 template <class Option, class Traits>
79 bool SelectionCapability<Option, Traits>::IsValid() const { 80 bool SelectionCapability<Option, Traits>::IsValid() const {
80 if (empty()) 81 if (empty())
81 return false; // This type of capabilities can't be empty 82 return false; // This type of capabilities can't be empty
82 for (size_t i = 0; i < options_.size(); ++i) { 83 for (size_t i = 0; i < options_.size(); ++i) {
83 if (!Traits::IsValid(options_[i])) 84 if (!Traits::IsValid(options_[i]))
84 return false; 85 return false;
85 } 86 }
86 return default_idx_ >= 0 && default_idx_ < static_cast<int>(size()); 87 return default_idx_ >= 0 && default_idx_ < base::checked_cast<int>(size());
87 } 88 }
88 89
89 template <class Option, class Traits> 90 template <class Option, class Traits>
90 bool SelectionCapability<Option, Traits>::LoadFrom( 91 bool SelectionCapability<Option, Traits>::LoadFrom(
91 const CloudDeviceDescription& description) { 92 const CloudDeviceDescription& description) {
92 Reset(); 93 Reset();
93 const base::DictionaryValue* item = 94 const base::DictionaryValue* item =
94 description.GetItem(Traits::GetCapabilityPath()); 95 description.GetItem(Traits::GetCapabilityPath());
95 if (!item) 96 if (!item)
96 return false; 97 return false;
(...skipping 20 matching lines...) Expand all
117 template <class Option, class Traits> 118 template <class Option, class Traits>
118 void SelectionCapability<Option, Traits>::SaveTo( 119 void SelectionCapability<Option, Traits>::SaveTo(
119 CloudDeviceDescription* description) const { 120 CloudDeviceDescription* description) const {
120 DCHECK(IsValid()); 121 DCHECK(IsValid());
121 base::ListValue* options_list = new base::ListValue; 122 base::ListValue* options_list = new base::ListValue;
122 description->CreateItem(Traits::GetCapabilityPath())->Set(json::kKeyOption, 123 description->CreateItem(Traits::GetCapabilityPath())->Set(json::kKeyOption,
123 options_list); 124 options_list);
124 for (size_t i = 0; i < options_.size(); ++i) { 125 for (size_t i = 0; i < options_.size(); ++i) {
125 base::DictionaryValue* option_value = new base::DictionaryValue; 126 base::DictionaryValue* option_value = new base::DictionaryValue;
126 options_list->Append(option_value); 127 options_list->Append(option_value);
127 if (static_cast<int>(i) == default_idx_) 128 if (base::checked_cast<int>(i) == default_idx_)
128 option_value->SetBoolean(json::kKeyIsDefault, true); 129 option_value->SetBoolean(json::kKeyIsDefault, true);
129 Traits::Save(options_[i], option_value); 130 Traits::Save(options_[i], option_value);
130 } 131 }
131 } 132 }
132 133
133 template <class Traits> 134 template <class Traits>
134 BooleanCapability<Traits>::BooleanCapability() { 135 BooleanCapability<Traits>::BooleanCapability() {
135 Reset(); 136 Reset();
136 } 137 }
137 138
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 template <class Option, class Traits> 204 template <class Option, class Traits>
204 void TicketItem<Option, Traits>::SaveTo( 205 void TicketItem<Option, Traits>::SaveTo(
205 CloudDeviceDescription* description) const { 206 CloudDeviceDescription* description) const {
206 DCHECK(IsValid()); 207 DCHECK(IsValid());
207 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath())); 208 Traits::Save(value(), description->CreateItem(Traits::GetTicketItemPath()));
208 } 209 }
209 210
210 } // namespace cloud_devices 211 } // namespace cloud_devices
211 212
212 #endif // COMPONENTS_CLOUD_DEVICES_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_ 213 #endif // COMPONENTS_CLOUD_DEVICES_DESCRIPTION_DESCRIPTION_ITEMS_INL_H_
OLDNEW
« no previous file with comments | « components/cloud_devices/description_items.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698