Commit c7a025a7 authored by Junbo Ke's avatar Junbo Ke Committed by Chromium LUCI CQ

[Chromecast] Avoid using heap allocated base::Value in DeviceCapabilities.

Also migrated off base::DictionaryValue.

Bug: internal b/156555613
Merge-With: eureka-internal/514526
Merge-With: eureka-internal/514525
Merge-With: eureka-internal/514524
Merge-With: eureka-internal/514186
Merge-With: eureka-internal/513401
Merge-With: eureka-internal/513298
Merge-With: eureka-internal/513381
Merge-With: eureka-internal/513294
Merge-With: eureka-internal/513296
Merge-With: eureka-internal/513299
Test: cast_base_unittests
Change-Id: If06e412cd0d8eab2374e6567a87832d6a225d9a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612108
Commit-Queue: Junbo Ke <juke@chromium.org>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarLuke Halliwell (slow) <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846411}
parent 2ea79437
...@@ -10,11 +10,7 @@ ...@@ -10,11 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/values.h"
namespace base {
class DictionaryValue;
class Value;
}
namespace chromecast { namespace chromecast {
...@@ -84,7 +80,7 @@ class DeviceCapabilities { ...@@ -84,7 +80,7 @@ class DeviceCapabilities {
// to it must be handled serially. Returns response through // to it must be handled serially. Returns response through
// SetPublicValidatedValue() or SetPrivateValidatedValue(). // SetPublicValidatedValue() or SetPrivateValidatedValue().
virtual void Validate(const std::string& path, virtual void Validate(const std::string& path,
std::unique_ptr<base::Value> proposed_value) = 0; base::Value proposed_value) = 0;
protected: protected:
explicit Validator(DeviceCapabilities* capabilities); explicit Validator(DeviceCapabilities* capabilities);
...@@ -99,9 +95,9 @@ class DeviceCapabilities { ...@@ -99,9 +95,9 @@ class DeviceCapabilities {
// TODO(seantopping): Change this interface so that Validators are not the // TODO(seantopping): Change this interface so that Validators are not the
// only means of accessing private capabilities. // only means of accessing private capabilities.
void SetPublicValidatedValue(const std::string& path, void SetPublicValidatedValue(const std::string& path,
std::unique_ptr<base::Value> new_value) const; base::Value new_value) const;
void SetPrivateValidatedValue(const std::string& path, void SetPrivateValidatedValue(const std::string& path,
std::unique_ptr<base::Value> new_value) const; base::Value new_value) const;
private: private:
DeviceCapabilities* const capabilities_; DeviceCapabilities* const capabilities_;
...@@ -115,9 +111,7 @@ class DeviceCapabilities { ...@@ -115,9 +111,7 @@ class DeviceCapabilities {
class Data : public base::RefCountedThreadSafe<Data> { class Data : public base::RefCountedThreadSafe<Data> {
public: public:
// Accessor for complete capabilities in dictionary format. // Accessor for complete capabilities in dictionary format.
const base::DictionaryValue& dictionary() const { const base::Value& dictionary() const { return dictionary_; }
return *dictionary_.get();
}
// Accessor for complete capabilities string in JSON format. // Accessor for complete capabilities string in JSON format.
const std::string& json_string() const { return json_string_; } const std::string& json_string() const { return json_string_; }
...@@ -131,11 +125,11 @@ class DeviceCapabilities { ...@@ -131,11 +125,11 @@ class DeviceCapabilities {
// Constructs empty dictionary with no capabilities. // Constructs empty dictionary with no capabilities.
Data(); Data();
// Uses |dictionary| as capabilities dictionary. // Uses |dictionary| as capabilities dictionary.
explicit Data(std::unique_ptr<const base::DictionaryValue> dictionary); explicit Data(base::Value dictionary);
~Data(); ~Data();
const std::unique_ptr<const base::DictionaryValue> dictionary_; const base::Value dictionary_;
const std::string json_string_; std::string json_string_;
DISALLOW_COPY_AND_ASSIGN(Data); DISALLOW_COPY_AND_ASSIGN(Data);
}; };
...@@ -196,8 +190,7 @@ class DeviceCapabilities { ...@@ -196,8 +190,7 @@ class DeviceCapabilities {
// Returns a deep copy of the value at |path|. If the capability at |path| // Returns a deep copy of the value at |path|. If the capability at |path|
// does not exist, a null scoped_ptr is returned. // does not exist, a null scoped_ptr is returned.
virtual std::unique_ptr<base::Value> GetCapability( virtual base::Value GetCapability(const std::string& path) const = 0;
const std::string& path) const = 0;
// Use this method to access dictionary and JSON string. No deep copying is // Use this method to access dictionary and JSON string. No deep copying is
// performed, so this method is inexpensive. Note that any capability updates // performed, so this method is inexpensive. Note that any capability updates
...@@ -223,11 +216,11 @@ class DeviceCapabilities { ...@@ -223,11 +216,11 @@ class DeviceCapabilities {
// classify the value as public or private via SetPublicValidatedValue() or // classify the value as public or private via SetPublicValidatedValue() or
// SetPrivateValidatedValue() respectively. // SetPrivateValidatedValue() respectively.
virtual void SetCapability(const std::string& path, virtual void SetCapability(const std::string& path,
std::unique_ptr<base::Value> proposed_value) = 0; base::Value proposed_value) = 0;
// Iterates through entries in |dict_value| and calls SetCapability() for // Iterates through entries in |dict_value| and calls SetCapability() for
// each one. This method is asynchronous. // each one. This method is asynchronous.
virtual void MergeDictionary(const base::DictionaryValue& dict_value) = 0; virtual void MergeDictionary(const base::Value& dict_value) = 0;
// Adds/removes an observer. It doesn't take the ownership of |observer|. // Adds/removes an observer. It doesn't take the ownership of |observer|.
virtual void AddCapabilitiesObserver(Observer* observer) = 0; virtual void AddCapabilitiesObserver(Observer* observer) = 0;
...@@ -241,20 +234,17 @@ class DeviceCapabilities { ...@@ -241,20 +234,17 @@ class DeviceCapabilities {
// Creates empty dictionary with no capabilities. // Creates empty dictionary with no capabilities.
static scoped_refptr<Data> CreateData(); static scoped_refptr<Data> CreateData();
// Uses |dictionary| as capabilities dictionary. // Uses |dictionary| as capabilities dictionary.
static scoped_refptr<Data> CreateData( static scoped_refptr<Data> CreateData(base::Value dictionary);
std::unique_ptr<const base::DictionaryValue> dictionary);
private: private:
// Internally update the capability residing at |path| to |new_value|. This // Internally update the capability residing at |path| to |new_value|. This
// capability will be visible in GetAllData() and GetPublicData(). // capability will be visible in GetAllData() and GetPublicData().
virtual void SetPublicValidatedValue( virtual void SetPublicValidatedValue(const std::string& path,
const std::string& path, base::Value new_value) = 0;
std::unique_ptr<base::Value> new_value) = 0;
// Similar to SetPublicValidatedValue(), but this capability will only be // Similar to SetPublicValidatedValue(), but this capability will only be
// visible in GetAllData(). // visible in GetAllData().
virtual void SetPrivateValidatedValue( virtual void SetPrivateValidatedValue(const std::string& path,
const std::string& path, base::Value new_value) = 0;
std::unique_ptr<base::Value> new_value) = 0;
DISALLOW_COPY_AND_ASSIGN(DeviceCapabilities); DISALLOW_COPY_AND_ASSIGN(DeviceCapabilities);
}; };
......
This diff is collapsed.
...@@ -33,13 +33,12 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities { ...@@ -33,13 +33,12 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
bool BluetoothSupported() const override; bool BluetoothSupported() const override;
bool DisplaySupported() const override; bool DisplaySupported() const override;
bool HiResAudioSupported() const override; bool HiResAudioSupported() const override;
std::unique_ptr<base::Value> GetCapability( base::Value GetCapability(const std::string& path) const override;
const std::string& path) const override;
scoped_refptr<Data> GetAllData() const override; scoped_refptr<Data> GetAllData() const override;
scoped_refptr<Data> GetPublicData() const override; scoped_refptr<Data> GetPublicData() const override;
void SetCapability(const std::string& path, void SetCapability(const std::string& path,
std::unique_ptr<base::Value> proposed_value) override; base::Value proposed_value) override;
void MergeDictionary(const base::DictionaryValue& dict_value) override; void MergeDictionary(const base::Value& dict_value) override;
void AddCapabilitiesObserver(Observer* observer) override; void AddCapabilitiesObserver(Observer* observer) override;
void RemoveCapabilitiesObserver(Observer* observer) override; void RemoveCapabilitiesObserver(Observer* observer) override;
...@@ -55,8 +54,7 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities { ...@@ -55,8 +54,7 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
return task_runner_; return task_runner_;
} }
void Validate(const std::string& path, void Validate(const std::string& path, base::Value proposed_value) const;
std::unique_ptr<base::Value> proposed_value) const;
private: private:
Validator* const validator_; Validator* const validator_;
...@@ -78,17 +76,15 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities { ...@@ -78,17 +76,15 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
DeviceCapabilitiesImpl(); DeviceCapabilitiesImpl();
void SetPublicValidatedValue(const std::string& path, void SetPublicValidatedValue(const std::string& path,
std::unique_ptr<base::Value> new_value) override; base::Value new_value) override;
void SetPrivateValidatedValue( void SetPrivateValidatedValue(const std::string& path,
const std::string& path, base::Value new_value) override;
std::unique_ptr<base::Value> new_value) override;
void SetValidatedValueInternal(const std::string& path, void SetValidatedValueInternal(const std::string& path,
std::unique_ptr<base::Value> new_value); base::Value new_value);
scoped_refptr<Data> GenerateDataWithNewValue( scoped_refptr<Data> GenerateDataWithNewValue(const base::Value& dict,
const base::DictionaryValue& dict,
const std::string& path, const std::string& path,
std::unique_ptr<base::Value> new_value); base::Value new_value);
// Lock for reading/writing all_data_ or public_data_ pointers // Lock for reading/writing all_data_ or public_data_ pointers
mutable base::Lock data_lock_; mutable base::Lock data_lock_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment