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 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
namespace base {
class DictionaryValue;
class Value;
}
#include "base/values.h"
namespace chromecast {
......@@ -84,7 +80,7 @@ class DeviceCapabilities {
// to it must be handled serially. Returns response through
// SetPublicValidatedValue() or SetPrivateValidatedValue().
virtual void Validate(const std::string& path,
std::unique_ptr<base::Value> proposed_value) = 0;
base::Value proposed_value) = 0;
protected:
explicit Validator(DeviceCapabilities* capabilities);
......@@ -99,9 +95,9 @@ class DeviceCapabilities {
// TODO(seantopping): Change this interface so that Validators are not the
// only means of accessing private capabilities.
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,
std::unique_ptr<base::Value> new_value) const;
base::Value new_value) const;
private:
DeviceCapabilities* const capabilities_;
......@@ -115,9 +111,7 @@ class DeviceCapabilities {
class Data : public base::RefCountedThreadSafe<Data> {
public:
// Accessor for complete capabilities in dictionary format.
const base::DictionaryValue& dictionary() const {
return *dictionary_.get();
}
const base::Value& dictionary() const { return dictionary_; }
// Accessor for complete capabilities string in JSON format.
const std::string& json_string() const { return json_string_; }
......@@ -131,11 +125,11 @@ class DeviceCapabilities {
// Constructs empty dictionary with no capabilities.
Data();
// Uses |dictionary| as capabilities dictionary.
explicit Data(std::unique_ptr<const base::DictionaryValue> dictionary);
explicit Data(base::Value dictionary);
~Data();
const std::unique_ptr<const base::DictionaryValue> dictionary_;
const std::string json_string_;
const base::Value dictionary_;
std::string json_string_;
DISALLOW_COPY_AND_ASSIGN(Data);
};
......@@ -196,8 +190,7 @@ class DeviceCapabilities {
// Returns a deep copy of the value at |path|. If the capability at |path|
// does not exist, a null scoped_ptr is returned.
virtual std::unique_ptr<base::Value> GetCapability(
const std::string& path) const = 0;
virtual base::Value GetCapability(const std::string& path) const = 0;
// Use this method to access dictionary and JSON string. No deep copying is
// performed, so this method is inexpensive. Note that any capability updates
......@@ -223,11 +216,11 @@ class DeviceCapabilities {
// classify the value as public or private via SetPublicValidatedValue() or
// SetPrivateValidatedValue() respectively.
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
// 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|.
virtual void AddCapabilitiesObserver(Observer* observer) = 0;
......@@ -241,20 +234,17 @@ class DeviceCapabilities {
// Creates empty dictionary with no capabilities.
static scoped_refptr<Data> CreateData();
// Uses |dictionary| as capabilities dictionary.
static scoped_refptr<Data> CreateData(
std::unique_ptr<const base::DictionaryValue> dictionary);
static scoped_refptr<Data> CreateData(base::Value dictionary);
private:
// Internally update the capability residing at |path| to |new_value|. This
// capability will be visible in GetAllData() and GetPublicData().
virtual void SetPublicValidatedValue(
const std::string& path,
std::unique_ptr<base::Value> new_value) = 0;
virtual void SetPublicValidatedValue(const std::string& path,
base::Value new_value) = 0;
// Similar to SetPublicValidatedValue(), but this capability will only be
// visible in GetAllData().
virtual void SetPrivateValidatedValue(
const std::string& path,
std::unique_ptr<base::Value> new_value) = 0;
virtual void SetPrivateValidatedValue(const std::string& path,
base::Value new_value) = 0;
DISALLOW_COPY_AND_ASSIGN(DeviceCapabilities);
};
......
This diff is collapsed.
......@@ -33,13 +33,12 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
bool BluetoothSupported() const override;
bool DisplaySupported() const override;
bool HiResAudioSupported() const override;
std::unique_ptr<base::Value> GetCapability(
const std::string& path) const override;
base::Value GetCapability(const std::string& path) const override;
scoped_refptr<Data> GetAllData() const override;
scoped_refptr<Data> GetPublicData() const override;
void SetCapability(const std::string& path,
std::unique_ptr<base::Value> proposed_value) override;
void MergeDictionary(const base::DictionaryValue& dict_value) override;
base::Value proposed_value) override;
void MergeDictionary(const base::Value& dict_value) override;
void AddCapabilitiesObserver(Observer* observer) override;
void RemoveCapabilitiesObserver(Observer* observer) override;
......@@ -55,8 +54,7 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
return task_runner_;
}
void Validate(const std::string& path,
std::unique_ptr<base::Value> proposed_value) const;
void Validate(const std::string& path, base::Value proposed_value) const;
private:
Validator* const validator_;
......@@ -78,17 +76,15 @@ class DeviceCapabilitiesImpl : public DeviceCapabilities {
DeviceCapabilitiesImpl();
void SetPublicValidatedValue(const std::string& path,
std::unique_ptr<base::Value> new_value) override;
void SetPrivateValidatedValue(
const std::string& path,
std::unique_ptr<base::Value> new_value) override;
base::Value new_value) override;
void SetPrivateValidatedValue(const std::string& path,
base::Value new_value) override;
void SetValidatedValueInternal(const std::string& path,
std::unique_ptr<base::Value> new_value);
base::Value new_value);
scoped_refptr<Data> GenerateDataWithNewValue(
const base::DictionaryValue& dict,
const std::string& path,
std::unique_ptr<base::Value> new_value);
scoped_refptr<Data> GenerateDataWithNewValue(const base::Value& dict,
const std::string& path,
base::Value new_value);
// Lock for reading/writing all_data_ or public_data_ pointers
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