| 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 <memory> |
| 8 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> |
| 9 | 11 |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list_threadsafe.h" | 14 #include "base/observer_list_threadsafe.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "chromecast/base/device_capabilities.h" | 16 #include "chromecast/base/device_capabilities.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 DISALLOW_COPY_AND_ASSIGN(ValidatorInfo); | 64 DISALLOW_COPY_AND_ASSIGN(ValidatorInfo); |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 // For DeviceCapabilitiesImpl() | 67 // For DeviceCapabilitiesImpl() |
| 67 friend class DeviceCapabilities; | 68 friend class DeviceCapabilities; |
| 68 // For SetValidatedValueInternal() | 69 // For SetValidatedValueInternal() |
| 69 friend class DeviceCapabilities::Validator; | 70 friend class DeviceCapabilities::Validator; |
| 70 | 71 |
| 71 // Map from capability key to corresponding ValidatorInfo. Gets updated | 72 // Map from capability key to corresponding ValidatorInfo. Gets updated |
| 72 // in Register()/Unregister(). | 73 // in Register()/Unregister(). |
| 73 typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<ValidatorInfo>> | 74 using ValidatorMap = |
| 74 ValidatorMap; | 75 std::unordered_map<std::string, std::unique_ptr<ValidatorInfo>>; |
| 75 | 76 |
| 76 // Internal constructor used by static DeviceCapabilities::Create*() methods. | 77 // Internal constructor used by static DeviceCapabilities::Create*() methods. |
| 77 DeviceCapabilitiesImpl(); | 78 DeviceCapabilitiesImpl(); |
| 78 | 79 |
| 79 void SetValidatedValue(const std::string& path, | 80 void SetValidatedValue(const std::string& path, |
| 80 std::unique_ptr<base::Value> new_value) override; | 81 std::unique_ptr<base::Value> new_value) override; |
| 81 | 82 |
| 82 // Lock for reading/writing data_ pointer | 83 // Lock for reading/writing data_ pointer |
| 83 mutable base::Lock data_lock_; | 84 mutable base::Lock data_lock_; |
| 84 // Lock for reading/writing validator_map_ | 85 // Lock for reading/writing validator_map_ |
| 85 mutable base::Lock validation_lock_; | 86 mutable base::Lock validation_lock_; |
| 86 | 87 |
| 87 scoped_refptr<Data> data_; | 88 scoped_refptr<Data> data_; |
| 88 // TaskRunner for capability writes. All internal writes to data_ must occur | 89 // TaskRunner for capability writes. All internal writes to data_ must occur |
| 89 // on task_runner_for_writes_'s thread. | 90 // on task_runner_for_writes_'s thread. |
| 90 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_writes_; | 91 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_writes_; |
| 91 | 92 |
| 92 ValidatorMap validator_map_; | 93 ValidatorMap validator_map_; |
| 93 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; | 94 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; |
| 94 | 95 |
| 95 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilitiesImpl); | 96 DISALLOW_COPY_AND_ASSIGN(DeviceCapabilitiesImpl); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 } // namespace chromecast | 99 } // namespace chromecast |
| 99 | 100 |
| 100 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ | 101 #endif // CHROMECAST_BASE_DEVICE_CAPABILITIES_IMPL_H_ |
| OLD | NEW |