| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ | 5 #ifndef CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ |
| 6 #define CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ | 6 #define CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // The instance should be created early enough for all managers to register | 97 // The instance should be created early enough for all managers to register |
| 98 // themselves, and then live long enough for all managers to unregister. | 98 // themselves, and then live long enough for all managers to unregister. |
| 99 static scoped_ptr<DeviceCapabilities> Create(); | 99 static scoped_ptr<DeviceCapabilities> Create(); |
| 100 // Creates an instance where all the default capabilities are initialized | 100 // Creates an instance where all the default capabilities are initialized |
| 101 // to a predefined default value, and no Validators are registered. For use | 101 // to a predefined default value, and no Validators are registered. For use |
| 102 // only in unit tests. | 102 // only in unit tests. |
| 103 static scoped_ptr<DeviceCapabilities> CreateForTesting(); | 103 static scoped_ptr<DeviceCapabilities> CreateForTesting(); |
| 104 | 104 |
| 105 // Registers a Validator for a capability. A given key must only be | 105 // Registers a Validator for a capability. A given key must only be |
| 106 // registered once, and must be unregistered before calling Register() again. | 106 // registered once, and must be unregistered before calling Register() again. |
| 107 // The capability also gets added to the class with an initial value passed | 107 // If the capability has a value of Dictionary type, |key| must be just |
| 108 // in. If the capability has a value of Dictionary type, |key| must be just | |
| 109 // the capability's top-level key and not include path expansions to levels | 108 // the capability's top-level key and not include path expansions to levels |
| 110 // farther down. For example, "foo" is a valid value for |key|, but "foo.bar" | 109 // farther down. For example, "foo" is a valid value for |key|, but "foo.bar" |
| 111 // is not. Note that if "foo.bar" is updated in SetCapability(), the | 110 // is not. Note that if "foo.bar" is updated in SetCapability(), the |
| 112 // Validate() method for "foo"'s Validator will be called, with a |path| of | 111 // Validate() method for "foo"'s Validator will be called, with a |path| of |
| 113 // "foo.bar". Both Register() and Unregister() must be called on cast | 112 // "foo.bar". Both Register() and Unregister() must be called on cast |
| 114 // receiver main thread; the Validator provided will also be called on cast | 113 // receiver main thread; the Validator provided will also be called on cast |
| 115 // receiver main thread. | 114 // receiver main thread. Note that this method does not add or modify |
| 115 // the capability. To do this, SetCapability() should be called, or |
| 116 // Validators can call SetValidatedValue(). |
| 116 virtual void Register(const std::string& key, | 117 virtual void Register(const std::string& key, |
| 117 scoped_ptr<base::Value> init_value, | |
| 118 Validator* validator) = 0; | 118 Validator* validator) = 0; |
| 119 // Unregisters Validator for |key| and removes capability. |validator| | 119 // Unregisters Validator for |key|. |validator| argument must match |
| 120 // argument must match |validator| argument that was passed in to Register() | 120 // |validator| argument that was passed in to Register() for |key|. Note that |
| 121 // for |key|. | 121 // the capability and its value remain untouched. |
| 122 virtual void Unregister(const std::string& key, | 122 virtual void Unregister(const std::string& key, |
| 123 const Validator* validator) = 0; | 123 const Validator* validator) = 0; |
| 124 // Gets the Validator currently registered for |key|. Returns nullptr if |
| 125 // no Validator is registered. |
| 126 virtual Validator* GetValidator(const std::string& key) const = 0; |
| 124 | 127 |
| 125 // Accessors for default capabilities. Note that the capability must be added | 128 // Accessors for default capabilities. Note that the capability must be added |
| 126 // through Register() or SetCapability() before accessors are called. | 129 // through SetCapability() or SetValidatedValue() (for Validators) before |
| 130 // accessors are called. |
| 127 virtual bool BluetoothSupported() const = 0; | 131 virtual bool BluetoothSupported() const = 0; |
| 128 virtual bool DisplaySupported() const = 0; | 132 virtual bool DisplaySupported() const = 0; |
| 129 | 133 |
| 130 // Gets the value of |path|. If capability at |path| does not exist, | 134 // Gets the value of |path|. If capability at |path| does not exist, |
| 131 // |out_value| remains untouched. Returns true if the capability has been | 135 // |out_value| remains untouched. Returns true if the capability has been |
| 132 // successfully retrieved. Note that this does NOT perform a deep copy, and | 136 // successfully retrieved. Note that this does NOT perform a deep copy, and |
| 133 // DeviceCapabilities still owns the memory returned through |out_value|. | 137 // DeviceCapabilities still owns the memory returned through |out_value|. |
| 134 virtual bool GetCapability(const std::string& path, | 138 virtual bool GetCapability(const std::string& path, |
| 135 const base::Value** out_value) const = 0; | 139 const base::Value** out_value) const = 0; |
| 136 | 140 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 165 // Does actual internal update of |path| to |new_value|. | 169 // Does actual internal update of |path| to |new_value|. |
| 166 virtual void SetValidatedValueInternal(const std::string& path, | 170 virtual void SetValidatedValueInternal(const std::string& path, |
| 167 scoped_ptr<base::Value> new_value) = 0; | 171 scoped_ptr<base::Value> new_value) = 0; |
| 168 | 172 |
| 169 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilities); | 173 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilities); |
| 170 }; | 174 }; |
| 171 | 175 |
| 172 } // namespace chromecast | 176 } // namespace chromecast |
| 173 | 177 |
| 174 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ | 178 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_H_ |
| OLD | NEW |