| 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_IMPL_H_ | 5 #ifndef CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ |
| 6 #define CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ | 6 #define CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 public: | 24 public: |
| 25 ~DeviceCapabilitiesImpl() override; | 25 ~DeviceCapabilitiesImpl() override; |
| 26 | 26 |
| 27 // DeviceCapabilities implementation: | 27 // DeviceCapabilities implementation: |
| 28 void Register(const std::string& key, Validator* validator) override; | 28 void Register(const std::string& key, Validator* validator) override; |
| 29 void Unregister(const std::string& key, const Validator* validator) override; | 29 void Unregister(const std::string& key, const Validator* validator) override; |
| 30 Validator* GetValidator(const std::string& key) const override; | 30 Validator* GetValidator(const std::string& key) const override; |
| 31 bool BluetoothSupported() const override; | 31 bool BluetoothSupported() const override; |
| 32 bool DisplaySupported() const override; | 32 bool DisplaySupported() const override; |
| 33 bool HiResAudioSupported() const override; | 33 bool HiResAudioSupported() const override; |
| 34 scoped_ptr<base::Value> GetCapability(const std::string& path) const override; | 34 std::unique_ptr<base::Value> GetCapability( |
| 35 const std::string& path) const override; |
| 35 scoped_refptr<Data> GetData() const override; | 36 scoped_refptr<Data> GetData() const override; |
| 36 void SetCapability(const std::string& path, | 37 void SetCapability(const std::string& path, |
| 37 scoped_ptr<base::Value> proposed_value) override; | 38 std::unique_ptr<base::Value> proposed_value) override; |
| 38 void MergeDictionary(const base::DictionaryValue& dict_value) override; | 39 void MergeDictionary(const base::DictionaryValue& dict_value) override; |
| 39 void AddCapabilitiesObserver(Observer* observer) override; | 40 void AddCapabilitiesObserver(Observer* observer) override; |
| 40 void RemoveCapabilitiesObserver(Observer* observer) override; | 41 void RemoveCapabilitiesObserver(Observer* observer) override; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 class ValidatorInfo : public base::SupportsWeakPtr<ValidatorInfo> { | 44 class ValidatorInfo : public base::SupportsWeakPtr<ValidatorInfo> { |
| 44 public: | 45 public: |
| 45 explicit ValidatorInfo(Validator* validator); | 46 explicit ValidatorInfo(Validator* validator); |
| 46 ~ValidatorInfo(); | 47 ~ValidatorInfo(); |
| 47 | 48 |
| 48 Validator* validator() const { return validator_; } | 49 Validator* validator() const { return validator_; } |
| 49 | 50 |
| 50 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { | 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { |
| 51 return task_runner_; | 52 return task_runner_; |
| 52 } | 53 } |
| 53 | 54 |
| 54 void Validate(const std::string& path, | 55 void Validate(const std::string& path, |
| 55 scoped_ptr<base::Value> proposed_value) const; | 56 std::unique_ptr<base::Value> proposed_value) const; |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 Validator* const validator_; | 59 Validator* const validator_; |
| 59 // TaskRunner of thread that validator_ was registered on | 60 // TaskRunner of thread that validator_ was registered on |
| 60 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 61 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(ValidatorInfo); | 63 DISALLOW_COPY_AND_ASSIGN(ValidatorInfo); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 // For DeviceCapabilitiesImpl() | 66 // For DeviceCapabilitiesImpl() |
| 66 friend class DeviceCapabilities; | 67 friend class DeviceCapabilities; |
| 67 // For SetValidatedValueInternal() | 68 // For SetValidatedValueInternal() |
| 68 friend class DeviceCapabilities::Validator; | 69 friend class DeviceCapabilities::Validator; |
| 69 | 70 |
| 70 // Map from capability key to corresponding ValidatorInfo. Gets updated | 71 // Map from capability key to corresponding ValidatorInfo. Gets updated |
| 71 // in Register()/Unregister(). | 72 // in Register()/Unregister(). |
| 72 typedef base::ScopedPtrHashMap<std::string, scoped_ptr<ValidatorInfo>> | 73 typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<ValidatorInfo>> |
| 73 ValidatorMap; | 74 ValidatorMap; |
| 74 | 75 |
| 75 // Internal constructor used by static DeviceCapabilities::Create*() methods. | 76 // Internal constructor used by static DeviceCapabilities::Create*() methods. |
| 76 DeviceCapabilitiesImpl(); | 77 DeviceCapabilitiesImpl(); |
| 77 | 78 |
| 78 void SetValidatedValue(const std::string& path, | 79 void SetValidatedValue(const std::string& path, |
| 79 scoped_ptr<base::Value> new_value) override; | 80 std::unique_ptr<base::Value> new_value) override; |
| 80 | 81 |
| 81 // Lock for reading/writing data_ pointer | 82 // Lock for reading/writing data_ pointer |
| 82 mutable base::Lock data_lock_; | 83 mutable base::Lock data_lock_; |
| 83 // Lock for reading/writing validator_map_ | 84 // Lock for reading/writing validator_map_ |
| 84 mutable base::Lock validation_lock_; | 85 mutable base::Lock validation_lock_; |
| 85 | 86 |
| 86 scoped_refptr<Data> data_; | 87 scoped_refptr<Data> data_; |
| 87 // TaskRunner for capability writes. All internal writes to data_ must occur | 88 // TaskRunner for capability writes. All internal writes to data_ must occur |
| 88 // on task_runner_for_writes_'s thread. | 89 // on task_runner_for_writes_'s thread. |
| 89 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_writes_; | 90 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_writes_; |
| 90 | 91 |
| 91 ValidatorMap validator_map_; | 92 ValidatorMap validator_map_; |
| 92 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; | 93 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilitiesImpl); | 95 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilitiesImpl); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 } // namespace chromecast | 98 } // namespace chromecast |
| 98 | 99 |
| 99 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ | 100 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ |
| OLD | NEW |