Chromium Code Reviews| Index: components/cloud_devices/description_items.h |
| diff --git a/components/cloud_devices/description_items.h b/components/cloud_devices/description_items.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e042b203d4203004fc56c950a6e40735a9d20d1 |
| --- /dev/null |
| +++ b/components/cloud_devices/description_items.h |
| @@ -0,0 +1,220 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_CLOUD_DEVICES_CAPABILITY_INTERFACES_H_ |
| +#define COMPONENTS_CLOUD_DEVICES_CAPABILITY_INTERFACES_H_ |
| + |
| +// Defines common templates that could be used to create device specific |
| +// capabilities and print tickets. |
| + |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| + |
| +#include "components/cloud_devices/cloud_device_description.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace cloud_devices { |
| + |
| +// Represents CDD capability that stored JSON list. |
|
Noam Samuel
2014/02/03 20:30:34
Nit: Rephrase as
"Represents a CDD capability tha
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Ex: "capability": [ {<VALUE>}, {<VALUE>}, {<VALUE>} ] |
|
Noam Samuel
2014/02/03 20:30:34
Nit: Since the key is not literally the word capab
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Option specifies data type for <VALUE>. |
| +// Traits specifies how <VALUE> is stored in JSON and semantical validation. |
|
Noam Samuel
2014/02/03 20:30:34
Nit: Semantical->Semantic
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +template <class Option, class Traits> |
|
Noam Samuel
2014/02/03 20:30:34
Please write in a comment somewhere the interface
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +class ListCapability { |
| + public: |
| + ListCapability(); |
| + ~ListCapability(); |
| + |
| + bool LoadFrom(const CloudDeviceDescription& description); |
| + void SaveTo(CloudDeviceDescription* description) const; |
| + |
| + void Reset() { |
| + options_.clear(); |
| + } |
| + |
| + bool IsValid() const; |
| + |
| + bool empty() const { |
| + return options_.empty(); |
| + } |
| + |
| + size_t size() const { |
| + return options_.size(); |
| + } |
| + |
| + const Option& operator[](size_t i) const { |
| + return options_[i]; |
| + } |
| + |
| + bool Contains(const Option& option) const{ |
| + return std::find(options_.begin(), options_.end(), option) != |
| + options_.end(); |
| + } |
| + |
| + void AddOption(const Option& option) { |
| + options_.push_back(option); |
| + } |
| + |
| + private: |
| + typedef std::vector<Option> OptionVector; |
| + OptionVector options_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ListCapability); |
| +}; |
| + |
| +// Represents CDD capability stored as JSON list with default_value value. |
| +// Ex: "capability": { "option": [{ "is_default": true, <VALUE>}, {<VALUE>} ]} |
|
Noam Samuel
2014/02/03 20:30:34
Ditto on "capability"
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Option specifies data type for <VALUE>. |
| +// Traits specifies how <VALUE> is stored in JSON and semantical validation. |
| +template <class Option, class Traits> |
| +class SelectionCapability { |
| + public: |
| + SelectionCapability(); |
| + ~SelectionCapability(); |
| + |
| + bool LoadFrom(const CloudDeviceDescription& description); |
| + void SaveTo(CloudDeviceDescription* description) const; |
| + |
| + void Reset() { |
| + options_.clear(); |
| + default_idx_ = 0; |
| + } |
| + |
| + bool IsValid() const; |
| + |
| + bool empty() const { |
| + return options_.empty(); |
| + } |
| + |
| + size_t size() const { |
| + return options_.size(); |
| + } |
| + |
| + const Option& operator[](size_t i) const { |
| + return options_[i]; |
| + } |
| + |
| + bool Contains(const Option& option) const{ |
| + return std::find(options_.begin(), options_.end(), option) != |
| + options_.end(); |
| + } |
| + |
| + const Option& GetDefault() const { |
| + return options_[default_idx_]; |
| + } |
| + |
| + void AddOption(const Option& option) { |
| + AddDefaultOption(option, false); |
| + } |
| + |
| + void AddDefaultOption(const Option& option, bool is_default) { |
| + bool no_default = (default_idx_ >= size()); |
|
Noam Samuel
2014/02/03 20:30:34
Why not use a signed default_idx_ == -1?
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| + options_.push_back(option); |
| + if (is_default) { |
| + DCHECK(no_default); |
| + // Point to the last element. |
| + default_idx_ = size() - 1; |
| + } else { |
| + if (no_default) { |
| + // Move default index after the last element. |
| + default_idx_ = size(); |
| + } |
| + } |
| + } |
| + |
| + private: |
| + typedef std::vector<Option> OptionVector; |
| + |
| + OptionVector options_; |
| + size_t default_idx_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SelectionCapability); |
| +}; |
| + |
| +// Represents CDD capability that can be true or false. |
| +// Ex: "capability": { "default_value": true } |
|
Noam Samuel
2014/02/03 20:30:34
Ditto on "capability"
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Traits specifies how <VALUE> is stored in JSON and semantical validation. |
| +template <class Traits> |
| +class BooleanCapability { |
| + public: |
| + BooleanCapability(); |
| + ~BooleanCapability(); |
| + |
| + bool LoadFrom(const CloudDeviceDescription& description); |
| + void SaveTo(CloudDeviceDescription* description) const; |
| + |
| + void Reset() { |
| + default_value_ = false; |
| + } |
| + |
| + void set_default_value(bool value) { |
| + default_value_ = value; |
| + } |
| + |
| + bool default_value() const { |
| + return default_value_; |
| + } |
| + |
| + private: |
| + bool default_value_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BooleanCapability); |
| +}; |
| + |
| +// Represents CDD capability that only existence is important for us. |
|
Noam Samuel
2014/02/03 20:30:34
Nit: that->for which
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Ex: "capability": { } |
|
Noam Samuel
2014/02/03 20:30:34
Ditto on "capability"
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Traits specifies how <VALUE> is stored in JSON and semantical validation. |
| +template <class Traits> |
| +class EmptyCapability { |
| + public: |
| + EmptyCapability() {}; |
| + ~EmptyCapability() {}; |
| + |
| + bool LoadFrom(const CloudDeviceDescription& description); |
| + void SaveTo(CloudDeviceDescription* description) const; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(EmptyCapability); |
| +}; |
| + |
| +// Represents CJT items. |
| +// Ex: "capability": {<VALUE>} |
|
Noam Samuel
2014/02/03 20:30:34
Ditto on "capability"
Vitaly Buka (NO REVIEWS)
2014/02/03 22:06:52
Done.
|
| +// Option specifies data type for <VALUE>. |
| +// Traits specifies how <VALUE> is stored in JSON and semantical validation. |
| +template <class Option, class Traits> |
| +class TicketItem { |
| + public: |
| + TicketItem(); |
| + ~TicketItem(); |
| + |
| + bool LoadFrom(const CloudDeviceDescription& description); |
| + void SaveTo(CloudDeviceDescription* description) const; |
| + |
| + void Reset() { |
| + value_ = Option(); |
| + } |
| + |
| + bool IsValid() const; |
| + |
| + const Option& value() const { |
| + return value_; |
| + } |
| + |
| + void set_value(const Option& value) { |
| + value_ = value; |
| + } |
| + |
| + private: |
| + Option value_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TicketItem); |
| +}; |
| + |
| +} // namespace cloud_devices |
| + |
| +#endif // COMPONENTS_CLOUD_DEVICES_CAPABILITY_INTERFACES_H_ |