Commit 16d6f53c authored by dcheng's avatar dcheng Committed by Commit bot

Use StringPiece more in base::Value interfaces.

Many of these functions are called with string literals.
This leads to two problems:
- Implicit construction of std::string generates a
  surprising amount of code, since STL code is often
  inlined.
- We construct a temporary string, immediately copy it,
  and then throw away the original temporary.

Effect of this CL on an official Linux binary:
 before: 100.41 MiB
  after: 99.56 MiB

BUG=none

Review-Url: https://codereview.chromium.org/2278723003
Cr-Commit-Position: refs/heads/master@{#414450}
parent b8df2228
...@@ -61,7 +61,7 @@ class DictionaryHiddenRootValue : public DictionaryValue { ...@@ -61,7 +61,7 @@ class DictionaryHiddenRootValue : public DictionaryValue {
// Not overriding DictionaryValue::Remove because it just calls through to // Not overriding DictionaryValue::Remove because it just calls through to
// the method below. // the method below.
bool RemoveWithoutPathExpansion(const std::string& key, bool RemoveWithoutPathExpansion(StringPiece key,
std::unique_ptr<Value>* out) override { std::unique_ptr<Value>* out) override {
// If the caller won't take ownership of the removed value, just call up. // If the caller won't take ownership of the removed value, just call up.
if (!out) if (!out)
......
...@@ -251,9 +251,8 @@ bool FundamentalValue::Equals(const Value* other) const { ...@@ -251,9 +251,8 @@ bool FundamentalValue::Equals(const Value* other) const {
///////////////////// StringValue //////////////////// ///////////////////// StringValue ////////////////////
StringValue::StringValue(const std::string& in_value) StringValue::StringValue(StringPiece in_value)
: Value(TYPE_STRING), : Value(TYPE_STRING), value_(in_value.as_string()) {
value_(in_value) {
DCHECK(IsStringUTF8(in_value)); DCHECK(IsStringUTF8(in_value));
} }
...@@ -376,9 +375,9 @@ bool DictionaryValue::GetAsDictionary(const DictionaryValue** out_value) const { ...@@ -376,9 +375,9 @@ bool DictionaryValue::GetAsDictionary(const DictionaryValue** out_value) const {
return true; return true;
} }
bool DictionaryValue::HasKey(const std::string& key) const { bool DictionaryValue::HasKey(StringPiece key) const {
DCHECK(IsStringUTF8(key)); DCHECK(IsStringUTF8(key));
auto current_entry = dictionary_.find(key); auto current_entry = dictionary_.find(key.as_string());
DCHECK((current_entry == dictionary_.end()) || current_entry->second); DCHECK((current_entry == dictionary_.end()) || current_entry->second);
return current_entry != dictionary_.end(); return current_entry != dictionary_.end();
} }
...@@ -387,12 +386,11 @@ void DictionaryValue::Clear() { ...@@ -387,12 +386,11 @@ void DictionaryValue::Clear() {
dictionary_.clear(); dictionary_.clear();
} }
void DictionaryValue::Set(const std::string& path, void DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
std::unique_ptr<Value> in_value) {
DCHECK(IsStringUTF8(path)); DCHECK(IsStringUTF8(path));
DCHECK(in_value); DCHECK(in_value);
std::string current_path(path); std::string current_path(path.as_string());
DictionaryValue* current_dictionary = this; DictionaryValue* current_dictionary = this;
for (size_t delimiter_position = current_path.find('.'); for (size_t delimiter_position = current_path.find('.');
delimiter_position != std::string::npos; delimiter_position != std::string::npos;
...@@ -413,64 +411,62 @@ void DictionaryValue::Set(const std::string& path, ...@@ -413,64 +411,62 @@ void DictionaryValue::Set(const std::string& path,
std::move(in_value)); std::move(in_value));
} }
void DictionaryValue::Set(const std::string& path, Value* in_value) { void DictionaryValue::Set(StringPiece path, Value* in_value) {
Set(path, WrapUnique(in_value)); Set(path, WrapUnique(in_value));
} }
void DictionaryValue::SetBoolean(const std::string& path, bool in_value) { void DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
Set(path, new FundamentalValue(in_value)); Set(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetInteger(const std::string& path, int in_value) { void DictionaryValue::SetInteger(StringPiece path, int in_value) {
Set(path, new FundamentalValue(in_value)); Set(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetDouble(const std::string& path, double in_value) { void DictionaryValue::SetDouble(StringPiece path, double in_value) {
Set(path, new FundamentalValue(in_value)); Set(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetString(const std::string& path, void DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
const std::string& in_value) { Set(path, new StringValue(in_value.as_string()));
Set(path, new StringValue(in_value));
} }
void DictionaryValue::SetString(const std::string& path, void DictionaryValue::SetString(StringPiece path, const string16& in_value) {
const string16& in_value) {
Set(path, new StringValue(in_value)); Set(path, new StringValue(in_value));
} }
void DictionaryValue::SetWithoutPathExpansion(const std::string& key, void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
std::unique_ptr<Value> in_value) { std::unique_ptr<Value> in_value) {
dictionary_[key] = std::move(in_value); dictionary_[key.as_string()] = std::move(in_value);
} }
void DictionaryValue::SetWithoutPathExpansion(const std::string& key, void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
Value* in_value) { Value* in_value) {
SetWithoutPathExpansion(key, WrapUnique(in_value)); SetWithoutPathExpansion(key, WrapUnique(in_value));
} }
void DictionaryValue::SetBooleanWithoutPathExpansion( void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path,
const std::string& path, bool in_value) { bool in_value) {
SetWithoutPathExpansion(path, new FundamentalValue(in_value)); SetWithoutPathExpansion(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetIntegerWithoutPathExpansion( void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path,
const std::string& path, int in_value) { int in_value) {
SetWithoutPathExpansion(path, new FundamentalValue(in_value)); SetWithoutPathExpansion(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetDoubleWithoutPathExpansion( void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path,
const std::string& path, double in_value) { double in_value) {
SetWithoutPathExpansion(path, new FundamentalValue(in_value)); SetWithoutPathExpansion(path, new FundamentalValue(in_value));
} }
void DictionaryValue::SetStringWithoutPathExpansion( void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
const std::string& path, const std::string& in_value) { StringPiece in_value) {
SetWithoutPathExpansion(path, new StringValue(in_value)); SetWithoutPathExpansion(path, new StringValue(in_value.as_string()));
} }
void DictionaryValue::SetStringWithoutPathExpansion( void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
const std::string& path, const string16& in_value) { const string16& in_value) {
SetWithoutPathExpansion(path, new StringValue(in_value)); SetWithoutPathExpansion(path, new StringValue(in_value));
} }
...@@ -503,8 +499,7 @@ bool DictionaryValue::Get(StringPiece path, Value** out_value) { ...@@ -503,8 +499,7 @@ bool DictionaryValue::Get(StringPiece path, Value** out_value) {
const_cast<const Value**>(out_value)); const_cast<const Value**>(out_value));
} }
bool DictionaryValue::GetBoolean(const std::string& path, bool DictionaryValue::GetBoolean(StringPiece path, bool* bool_value) const {
bool* bool_value) const {
const Value* value; const Value* value;
if (!Get(path, &value)) if (!Get(path, &value))
return false; return false;
...@@ -512,8 +507,7 @@ bool DictionaryValue::GetBoolean(const std::string& path, ...@@ -512,8 +507,7 @@ bool DictionaryValue::GetBoolean(const std::string& path,
return value->GetAsBoolean(bool_value); return value->GetAsBoolean(bool_value);
} }
bool DictionaryValue::GetInteger(const std::string& path, bool DictionaryValue::GetInteger(StringPiece path, int* out_value) const {
int* out_value) const {
const Value* value; const Value* value;
if (!Get(path, &value)) if (!Get(path, &value))
return false; return false;
...@@ -521,8 +515,7 @@ bool DictionaryValue::GetInteger(const std::string& path, ...@@ -521,8 +515,7 @@ bool DictionaryValue::GetInteger(const std::string& path,
return value->GetAsInteger(out_value); return value->GetAsInteger(out_value);
} }
bool DictionaryValue::GetDouble(const std::string& path, bool DictionaryValue::GetDouble(StringPiece path, double* out_value) const {
double* out_value) const {
const Value* value; const Value* value;
if (!Get(path, &value)) if (!Get(path, &value))
return false; return false;
...@@ -530,7 +523,7 @@ bool DictionaryValue::GetDouble(const std::string& path, ...@@ -530,7 +523,7 @@ bool DictionaryValue::GetDouble(const std::string& path,
return value->GetAsDouble(out_value); return value->GetAsDouble(out_value);
} }
bool DictionaryValue::GetString(const std::string& path, bool DictionaryValue::GetString(StringPiece path,
std::string* out_value) const { std::string* out_value) const {
const Value* value; const Value* value;
if (!Get(path, &value)) if (!Get(path, &value))
...@@ -539,8 +532,7 @@ bool DictionaryValue::GetString(const std::string& path, ...@@ -539,8 +532,7 @@ bool DictionaryValue::GetString(const std::string& path,
return value->GetAsString(out_value); return value->GetAsString(out_value);
} }
bool DictionaryValue::GetString(const std::string& path, bool DictionaryValue::GetString(StringPiece path, string16* out_value) const {
string16* out_value) const {
const Value* value; const Value* value;
if (!Get(path, &value)) if (!Get(path, &value))
return false; return false;
...@@ -548,7 +540,7 @@ bool DictionaryValue::GetString(const std::string& path, ...@@ -548,7 +540,7 @@ bool DictionaryValue::GetString(const std::string& path,
return value->GetAsString(out_value); return value->GetAsString(out_value);
} }
bool DictionaryValue::GetStringASCII(const std::string& path, bool DictionaryValue::GetStringASCII(StringPiece path,
std::string* out_value) const { std::string* out_value) const {
std::string out; std::string out;
if (!GetString(path, &out)) if (!GetString(path, &out))
...@@ -563,7 +555,7 @@ bool DictionaryValue::GetStringASCII(const std::string& path, ...@@ -563,7 +555,7 @@ bool DictionaryValue::GetStringASCII(const std::string& path,
return true; return true;
} }
bool DictionaryValue::GetBinary(const std::string& path, bool DictionaryValue::GetBinary(StringPiece path,
const BinaryValue** out_value) const { const BinaryValue** out_value) const {
const Value* value; const Value* value;
bool result = Get(path, &value); bool result = Get(path, &value);
...@@ -576,8 +568,7 @@ bool DictionaryValue::GetBinary(const std::string& path, ...@@ -576,8 +568,7 @@ bool DictionaryValue::GetBinary(const std::string& path,
return true; return true;
} }
bool DictionaryValue::GetBinary(const std::string& path, bool DictionaryValue::GetBinary(StringPiece path, BinaryValue** out_value) {
BinaryValue** out_value) {
return static_cast<const DictionaryValue&>(*this).GetBinary( return static_cast<const DictionaryValue&>(*this).GetBinary(
path, path,
const_cast<const BinaryValue**>(out_value)); const_cast<const BinaryValue**>(out_value));
...@@ -603,7 +594,7 @@ bool DictionaryValue::GetDictionary(StringPiece path, ...@@ -603,7 +594,7 @@ bool DictionaryValue::GetDictionary(StringPiece path,
const_cast<const DictionaryValue**>(out_value)); const_cast<const DictionaryValue**>(out_value));
} }
bool DictionaryValue::GetList(const std::string& path, bool DictionaryValue::GetList(StringPiece path,
const ListValue** out_value) const { const ListValue** out_value) const {
const Value* value; const Value* value;
bool result = Get(path, &value); bool result = Get(path, &value);
...@@ -616,16 +607,16 @@ bool DictionaryValue::GetList(const std::string& path, ...@@ -616,16 +607,16 @@ bool DictionaryValue::GetList(const std::string& path,
return true; return true;
} }
bool DictionaryValue::GetList(const std::string& path, ListValue** out_value) { bool DictionaryValue::GetList(StringPiece path, ListValue** out_value) {
return static_cast<const DictionaryValue&>(*this).GetList( return static_cast<const DictionaryValue&>(*this).GetList(
path, path,
const_cast<const ListValue**>(out_value)); const_cast<const ListValue**>(out_value));
} }
bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
const Value** out_value) const { const Value** out_value) const {
DCHECK(IsStringUTF8(key)); DCHECK(IsStringUTF8(key));
auto entry_iterator = dictionary_.find(key); auto entry_iterator = dictionary_.find(key.as_string());
if (entry_iterator == dictionary_.end()) if (entry_iterator == dictionary_.end())
return false; return false;
...@@ -634,14 +625,14 @@ bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, ...@@ -634,14 +625,14 @@ bool DictionaryValue::GetWithoutPathExpansion(const std::string& key,
return true; return true;
} }
bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
Value** out_value) { Value** out_value) {
return static_cast<const DictionaryValue&>(*this).GetWithoutPathExpansion( return static_cast<const DictionaryValue&>(*this).GetWithoutPathExpansion(
key, key,
const_cast<const Value**>(out_value)); const_cast<const Value**>(out_value));
} }
bool DictionaryValue::GetBooleanWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetBooleanWithoutPathExpansion(StringPiece key,
bool* out_value) const { bool* out_value) const {
const Value* value; const Value* value;
if (!GetWithoutPathExpansion(key, &value)) if (!GetWithoutPathExpansion(key, &value))
...@@ -650,7 +641,7 @@ bool DictionaryValue::GetBooleanWithoutPathExpansion(const std::string& key, ...@@ -650,7 +641,7 @@ bool DictionaryValue::GetBooleanWithoutPathExpansion(const std::string& key,
return value->GetAsBoolean(out_value); return value->GetAsBoolean(out_value);
} }
bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetIntegerWithoutPathExpansion(StringPiece key,
int* out_value) const { int* out_value) const {
const Value* value; const Value* value;
if (!GetWithoutPathExpansion(key, &value)) if (!GetWithoutPathExpansion(key, &value))
...@@ -659,7 +650,7 @@ bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::string& key, ...@@ -659,7 +650,7 @@ bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::string& key,
return value->GetAsInteger(out_value); return value->GetAsInteger(out_value);
} }
bool DictionaryValue::GetDoubleWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetDoubleWithoutPathExpansion(StringPiece key,
double* out_value) const { double* out_value) const {
const Value* value; const Value* value;
if (!GetWithoutPathExpansion(key, &value)) if (!GetWithoutPathExpansion(key, &value))
...@@ -669,7 +660,7 @@ bool DictionaryValue::GetDoubleWithoutPathExpansion(const std::string& key, ...@@ -669,7 +660,7 @@ bool DictionaryValue::GetDoubleWithoutPathExpansion(const std::string& key,
} }
bool DictionaryValue::GetStringWithoutPathExpansion( bool DictionaryValue::GetStringWithoutPathExpansion(
const std::string& key, StringPiece key,
std::string* out_value) const { std::string* out_value) const {
const Value* value; const Value* value;
if (!GetWithoutPathExpansion(key, &value)) if (!GetWithoutPathExpansion(key, &value))
...@@ -678,7 +669,7 @@ bool DictionaryValue::GetStringWithoutPathExpansion( ...@@ -678,7 +669,7 @@ bool DictionaryValue::GetStringWithoutPathExpansion(
return value->GetAsString(out_value); return value->GetAsString(out_value);
} }
bool DictionaryValue::GetStringWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetStringWithoutPathExpansion(StringPiece key,
string16* out_value) const { string16* out_value) const {
const Value* value; const Value* value;
if (!GetWithoutPathExpansion(key, &value)) if (!GetWithoutPathExpansion(key, &value))
...@@ -688,7 +679,7 @@ bool DictionaryValue::GetStringWithoutPathExpansion(const std::string& key, ...@@ -688,7 +679,7 @@ bool DictionaryValue::GetStringWithoutPathExpansion(const std::string& key,
} }
bool DictionaryValue::GetDictionaryWithoutPathExpansion( bool DictionaryValue::GetDictionaryWithoutPathExpansion(
const std::string& key, StringPiece key,
const DictionaryValue** out_value) const { const DictionaryValue** out_value) const {
const Value* value; const Value* value;
bool result = GetWithoutPathExpansion(key, &value); bool result = GetWithoutPathExpansion(key, &value);
...@@ -702,7 +693,7 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion( ...@@ -702,7 +693,7 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion(
} }
bool DictionaryValue::GetDictionaryWithoutPathExpansion( bool DictionaryValue::GetDictionaryWithoutPathExpansion(
const std::string& key, StringPiece key,
DictionaryValue** out_value) { DictionaryValue** out_value) {
const DictionaryValue& const_this = const DictionaryValue& const_this =
static_cast<const DictionaryValue&>(*this); static_cast<const DictionaryValue&>(*this);
...@@ -712,7 +703,7 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion( ...@@ -712,7 +703,7 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion(
} }
bool DictionaryValue::GetListWithoutPathExpansion( bool DictionaryValue::GetListWithoutPathExpansion(
const std::string& key, StringPiece key,
const ListValue** out_value) const { const ListValue** out_value) const {
const Value* value; const Value* value;
bool result = GetWithoutPathExpansion(key, &value); bool result = GetWithoutPathExpansion(key, &value);
...@@ -725,7 +716,7 @@ bool DictionaryValue::GetListWithoutPathExpansion( ...@@ -725,7 +716,7 @@ bool DictionaryValue::GetListWithoutPathExpansion(
return true; return true;
} }
bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, bool DictionaryValue::GetListWithoutPathExpansion(StringPiece key,
ListValue** out_value) { ListValue** out_value) {
return return
static_cast<const DictionaryValue&>(*this).GetListWithoutPathExpansion( static_cast<const DictionaryValue&>(*this).GetListWithoutPathExpansion(
...@@ -733,10 +724,10 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, ...@@ -733,10 +724,10 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key,
const_cast<const ListValue**>(out_value)); const_cast<const ListValue**>(out_value));
} }
bool DictionaryValue::Remove(const std::string& path, bool DictionaryValue::Remove(StringPiece path,
std::unique_ptr<Value>* out_value) { std::unique_ptr<Value>* out_value) {
DCHECK(IsStringUTF8(path)); DCHECK(IsStringUTF8(path));
std::string current_path(path); std::string current_path(path.as_string());
DictionaryValue* current_dictionary = this; DictionaryValue* current_dictionary = this;
size_t delimiter_position = current_path.rfind('.'); size_t delimiter_position = current_path.rfind('.');
if (delimiter_position != std::string::npos) { if (delimiter_position != std::string::npos) {
...@@ -751,10 +742,10 @@ bool DictionaryValue::Remove(const std::string& path, ...@@ -751,10 +742,10 @@ bool DictionaryValue::Remove(const std::string& path,
} }
bool DictionaryValue::RemoveWithoutPathExpansion( bool DictionaryValue::RemoveWithoutPathExpansion(
const std::string& key, StringPiece key,
std::unique_ptr<Value>* out_value) { std::unique_ptr<Value>* out_value) {
DCHECK(IsStringUTF8(key)); DCHECK(IsStringUTF8(key));
auto entry_iterator = dictionary_.find(key); auto entry_iterator = dictionary_.find(key.as_string());
if (entry_iterator == dictionary_.end()) if (entry_iterator == dictionary_.end())
return false; return false;
...@@ -764,7 +755,7 @@ bool DictionaryValue::RemoveWithoutPathExpansion( ...@@ -764,7 +755,7 @@ bool DictionaryValue::RemoveWithoutPathExpansion(
return true; return true;
} }
bool DictionaryValue::RemovePath(const std::string& path, bool DictionaryValue::RemovePath(StringPiece path,
std::unique_ptr<Value>* out_value) { std::unique_ptr<Value>* out_value) {
bool result = false; bool result = false;
size_t delimiter_position = path.find('.'); size_t delimiter_position = path.find('.');
...@@ -772,7 +763,7 @@ bool DictionaryValue::RemovePath(const std::string& path, ...@@ -772,7 +763,7 @@ bool DictionaryValue::RemovePath(const std::string& path,
if (delimiter_position == std::string::npos) if (delimiter_position == std::string::npos)
return RemoveWithoutPathExpansion(path, out_value); return RemoveWithoutPathExpansion(path, out_value);
const std::string subdict_path = path.substr(0, delimiter_position); StringPiece subdict_path = path.substr(0, delimiter_position);
DictionaryValue* subdict = NULL; DictionaryValue* subdict = NULL;
if (!GetDictionary(subdict_path, &subdict)) if (!GetDictionary(subdict_path, &subdict))
return false; return false;
...@@ -1068,8 +1059,8 @@ void ListValue::AppendDouble(double in_value) { ...@@ -1068,8 +1059,8 @@ void ListValue::AppendDouble(double in_value) {
Append(new FundamentalValue(in_value)); Append(new FundamentalValue(in_value));
} }
void ListValue::AppendString(const std::string& in_value) { void ListValue::AppendString(StringPiece in_value) {
Append(new StringValue(in_value)); Append(new StringValue(in_value.as_string()));
} }
void ListValue::AppendString(const string16& in_value) { void ListValue::AppendString(const string16& in_value) {
......
...@@ -149,7 +149,7 @@ class BASE_EXPORT FundamentalValue : public Value { ...@@ -149,7 +149,7 @@ class BASE_EXPORT FundamentalValue : public Value {
class BASE_EXPORT StringValue : public Value { class BASE_EXPORT StringValue : public Value {
public: public:
// Initializes a StringValue with a UTF-8 narrow character string. // Initializes a StringValue with a UTF-8 narrow character string.
explicit StringValue(const std::string& in_value); explicit StringValue(StringPiece in_value);
// Initializes a StringValue with a string16. // Initializes a StringValue with a string16.
explicit StringValue(const string16& in_value); explicit StringValue(const string16& in_value);
...@@ -223,7 +223,7 @@ class BASE_EXPORT DictionaryValue : public Value { ...@@ -223,7 +223,7 @@ class BASE_EXPORT DictionaryValue : public Value {
bool GetAsDictionary(const DictionaryValue** out_value) const override; bool GetAsDictionary(const DictionaryValue** out_value) const override;
// Returns true if the current dictionary has a value for the given key. // Returns true if the current dictionary has a value for the given key.
bool HasKey(const std::string& key) const; bool HasKey(StringPiece key) const;
// Returns the number of Values in this dictionary. // Returns the number of Values in this dictionary.
size_t size() const { return dictionary_.size(); } size_t size() const { return dictionary_.size(); }
...@@ -241,32 +241,31 @@ class BASE_EXPORT DictionaryValue : public Value { ...@@ -241,32 +241,31 @@ class BASE_EXPORT DictionaryValue : public Value {
// If the key at any step of the way doesn't exist, or exists but isn't // If the key at any step of the way doesn't exist, or exists but isn't
// a DictionaryValue, a new DictionaryValue will be created and attached // a DictionaryValue, a new DictionaryValue will be created and attached
// to the path in that location. |in_value| must be non-null. // to the path in that location. |in_value| must be non-null.
void Set(const std::string& path, std::unique_ptr<Value> in_value); void Set(StringPiece path, std::unique_ptr<Value> in_value);
// Deprecated version of the above. TODO(estade): remove. // Deprecated version of the above. TODO(estade): remove.
void Set(const std::string& path, Value* in_value); void Set(StringPiece path, Value* in_value);
// Convenience forms of Set(). These methods will replace any existing // Convenience forms of Set(). These methods will replace any existing
// value at that path, even if it has a different type. // value at that path, even if it has a different type.
void SetBoolean(const std::string& path, bool in_value); void SetBoolean(StringPiece path, bool in_value);
void SetInteger(const std::string& path, int in_value); void SetInteger(StringPiece path, int in_value);
void SetDouble(const std::string& path, double in_value); void SetDouble(StringPiece path, double in_value);
void SetString(const std::string& path, const std::string& in_value); void SetString(StringPiece path, StringPiece in_value);
void SetString(const std::string& path, const string16& in_value); void SetString(StringPiece path, const string16& in_value);
// Like Set(), but without special treatment of '.'. This allows e.g. URLs to // Like Set(), but without special treatment of '.'. This allows e.g. URLs to
// be used as paths. // be used as paths.
void SetWithoutPathExpansion(const std::string& key, void SetWithoutPathExpansion(StringPiece key,
std::unique_ptr<Value> in_value); std::unique_ptr<Value> in_value);
// Deprecated version of the above. TODO(estade): remove. // Deprecated version of the above. TODO(estade): remove.
void SetWithoutPathExpansion(const std::string& key, Value* in_value); void SetWithoutPathExpansion(StringPiece key, Value* in_value);
// Convenience forms of SetWithoutPathExpansion(). // Convenience forms of SetWithoutPathExpansion().
void SetBooleanWithoutPathExpansion(const std::string& path, bool in_value); void SetBooleanWithoutPathExpansion(StringPiece path, bool in_value);
void SetIntegerWithoutPathExpansion(const std::string& path, int in_value); void SetIntegerWithoutPathExpansion(StringPiece path, int in_value);
void SetDoubleWithoutPathExpansion(const std::string& path, double in_value); void SetDoubleWithoutPathExpansion(StringPiece path, double in_value);
void SetStringWithoutPathExpansion(const std::string& path, void SetStringWithoutPathExpansion(StringPiece path, StringPiece in_value);
const std::string& in_value); void SetStringWithoutPathExpansion(StringPiece path,
void SetStringWithoutPathExpansion(const std::string& path,
const string16& in_value); const string16& in_value);
// Gets the Value associated with the given path starting from this object. // Gets the Value associated with the given path starting from this object.
...@@ -284,46 +283,41 @@ class BASE_EXPORT DictionaryValue : public Value { ...@@ -284,46 +283,41 @@ class BASE_EXPORT DictionaryValue : public Value {
// and the return value will be true if the path is valid and the value at // and the return value will be true if the path is valid and the value at
// the end of the path can be returned in the form specified. // the end of the path can be returned in the form specified.
// |out_value| is optional and will only be set if non-NULL. // |out_value| is optional and will only be set if non-NULL.
bool GetBoolean(const std::string& path, bool* out_value) const; bool GetBoolean(StringPiece path, bool* out_value) const;
bool GetInteger(const std::string& path, int* out_value) const; bool GetInteger(StringPiece path, int* out_value) const;
// Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as
// doubles. // doubles.
bool GetDouble(const std::string& path, double* out_value) const; bool GetDouble(StringPiece path, double* out_value) const;
bool GetString(const std::string& path, std::string* out_value) const; bool GetString(StringPiece path, std::string* out_value) const;
bool GetString(const std::string& path, string16* out_value) const; bool GetString(StringPiece path, string16* out_value) const;
bool GetStringASCII(const std::string& path, std::string* out_value) const; bool GetStringASCII(StringPiece path, std::string* out_value) const;
bool GetBinary(const std::string& path, const BinaryValue** out_value) const; bool GetBinary(StringPiece path, const BinaryValue** out_value) const;
bool GetBinary(const std::string& path, BinaryValue** out_value); bool GetBinary(StringPiece path, BinaryValue** out_value);
bool GetDictionary(StringPiece path, bool GetDictionary(StringPiece path,
const DictionaryValue** out_value) const; const DictionaryValue** out_value) const;
bool GetDictionary(StringPiece path, DictionaryValue** out_value); bool GetDictionary(StringPiece path, DictionaryValue** out_value);
bool GetList(const std::string& path, const ListValue** out_value) const; bool GetList(StringPiece path, const ListValue** out_value) const;
bool GetList(const std::string& path, ListValue** out_value); bool GetList(StringPiece path, ListValue** out_value);
// Like Get(), but without special treatment of '.'. This allows e.g. URLs to // Like Get(), but without special treatment of '.'. This allows e.g. URLs to
// be used as paths. // be used as paths.
bool GetWithoutPathExpansion(const std::string& key, bool GetWithoutPathExpansion(StringPiece key, const Value** out_value) const;
const Value** out_value) const; bool GetWithoutPathExpansion(StringPiece key, Value** out_value);
bool GetWithoutPathExpansion(const std::string& key, Value** out_value); bool GetBooleanWithoutPathExpansion(StringPiece key, bool* out_value) const;
bool GetBooleanWithoutPathExpansion(const std::string& key, bool GetIntegerWithoutPathExpansion(StringPiece key, int* out_value) const;
bool* out_value) const; bool GetDoubleWithoutPathExpansion(StringPiece key, double* out_value) const;
bool GetIntegerWithoutPathExpansion(const std::string& key, bool GetStringWithoutPathExpansion(StringPiece key,
int* out_value) const;
bool GetDoubleWithoutPathExpansion(const std::string& key,
double* out_value) const;
bool GetStringWithoutPathExpansion(const std::string& key,
std::string* out_value) const; std::string* out_value) const;
bool GetStringWithoutPathExpansion(const std::string& key, bool GetStringWithoutPathExpansion(StringPiece key,
string16* out_value) const; string16* out_value) const;
bool GetDictionaryWithoutPathExpansion( bool GetDictionaryWithoutPathExpansion(
const std::string& key, StringPiece key,
const DictionaryValue** out_value) const; const DictionaryValue** out_value) const;
bool GetDictionaryWithoutPathExpansion(const std::string& key, bool GetDictionaryWithoutPathExpansion(StringPiece key,
DictionaryValue** out_value); DictionaryValue** out_value);
bool GetListWithoutPathExpansion(const std::string& key, bool GetListWithoutPathExpansion(StringPiece key,
const ListValue** out_value) const; const ListValue** out_value) const;
bool GetListWithoutPathExpansion(const std::string& key, bool GetListWithoutPathExpansion(StringPiece key, ListValue** out_value);
ListValue** out_value);
// Removes the Value with the specified path from this dictionary (or one // Removes the Value with the specified path from this dictionary (or one
// of its child dictionaries, if the path is more than just a local key). // of its child dictionaries, if the path is more than just a local key).
...@@ -331,18 +325,16 @@ class BASE_EXPORT DictionaryValue : public Value { ...@@ -331,18 +325,16 @@ class BASE_EXPORT DictionaryValue : public Value {
// |out_value|. If |out_value| is NULL, the removed value will be deleted. // |out_value|. If |out_value| is NULL, the removed value will be deleted.
// This method returns true if |path| is a valid path; otherwise it will // This method returns true if |path| is a valid path; otherwise it will
// return false and the DictionaryValue object will be unchanged. // return false and the DictionaryValue object will be unchanged.
virtual bool Remove(const std::string& path, virtual bool Remove(StringPiece path, std::unique_ptr<Value>* out_value);
std::unique_ptr<Value>* out_value);
// Like Remove(), but without special treatment of '.'. This allows e.g. URLs // Like Remove(), but without special treatment of '.'. This allows e.g. URLs
// to be used as paths. // to be used as paths.
virtual bool RemoveWithoutPathExpansion(const std::string& key, virtual bool RemoveWithoutPathExpansion(StringPiece key,
std::unique_ptr<Value>* out_value); std::unique_ptr<Value>* out_value);
// Removes a path, clearing out all dictionaries on |path| that remain empty // Removes a path, clearing out all dictionaries on |path| that remain empty
// after removing the value at |path|. // after removing the value at |path|.
virtual bool RemovePath(const std::string& path, virtual bool RemovePath(StringPiece path, std::unique_ptr<Value>* out_value);
std::unique_ptr<Value>* out_value);
// Makes a copy of |this| but doesn't include empty dictionaries and lists in // Makes a copy of |this| but doesn't include empty dictionaries and lists in
// the copy. This never returns NULL, even if |this| itself is empty. // the copy. This never returns NULL, even if |this| itself is empty.
...@@ -472,7 +464,7 @@ class BASE_EXPORT ListValue : public Value { ...@@ -472,7 +464,7 @@ class BASE_EXPORT ListValue : public Value {
void AppendBoolean(bool in_value); void AppendBoolean(bool in_value);
void AppendInteger(int in_value); void AppendInteger(int in_value);
void AppendDouble(double in_value); void AppendDouble(double in_value);
void AppendString(const std::string& in_value); void AppendString(StringPiece in_value);
void AppendString(const string16& in_value); void AppendString(const string16& in_value);
void AppendStrings(const std::vector<std::string>& in_values); void AppendStrings(const std::vector<std::string>& in_values);
void AppendStrings(const std::vector<string16>& in_values); void AppendStrings(const std::vector<string16>& in_values);
......
...@@ -171,7 +171,7 @@ void PluginsPageHandler::SetPluginAlwaysAllowed(const mojo::String& plugin, ...@@ -171,7 +171,7 @@ void PluginsPageHandler::SetPluginAlwaysAllowed(const mojo::String& plugin,
// whitelisted by the user from automatically whitelisted ones. // whitelisted by the user from automatically whitelisted ones.
DictionaryPrefUpdate update(profile->GetPrefs(), DictionaryPrefUpdate update(profile->GetPrefs(),
prefs::kContentSettingsPluginWhitelist); prefs::kContentSettingsPluginWhitelist);
update->SetBoolean(plugin, allowed); update->SetBoolean(plugin.get(), allowed);
} }
void PluginsPageHandler::GetPluginsData( void PluginsPageHandler::GetPluginsData(
......
...@@ -450,7 +450,8 @@ void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg, ...@@ -450,7 +450,8 @@ void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg,
properties->SetStringWithoutPathExpansion(onc::network_config::kType, properties->SetStringWithoutPathExpansion(onc::network_config::kType,
onc::network_config::kWiFi); onc::network_config::kWiFi);
wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kHexSSID, cfg->hexssid); wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kHexSSID,
cfg->hexssid.get());
wifi_dict->SetBooleanWithoutPathExpansion(onc::wifi::kAutoConnect, wifi_dict->SetBooleanWithoutPathExpansion(onc::wifi::kAutoConnect,
details->autoconnect); details->autoconnect);
if (cfg->security.get().empty()) { if (cfg->security.get().empty()) {
...@@ -458,10 +459,10 @@ void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg, ...@@ -458,10 +459,10 @@ void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg,
onc::wifi::kSecurityNone); onc::wifi::kSecurityNone);
} else { } else {
wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity, wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity,
cfg->security); cfg->security.get());
if (!details->passphrase.is_null()) { if (!details->passphrase.is_null()) {
wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kPassphrase, wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kPassphrase,
details->passphrase); details->passphrase.get());
} }
} }
properties->SetWithoutPathExpansion(onc::network_config::kWiFi, properties->SetWithoutPathExpansion(onc::network_config::kWiFi,
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/strings/string_piece.h"
#include "components/domain_reliability/beacon.h" #include "components/domain_reliability/beacon.h"
#include "components/domain_reliability/dispatcher.h" #include "components/domain_reliability/dispatcher.h"
#include "components/domain_reliability/scheduler.h" #include "components/domain_reliability/scheduler.h"
...@@ -60,8 +61,8 @@ std::unique_ptr<DomainReliabilityBeacon> MakeBeacon(MockableTime* time) { ...@@ -60,8 +61,8 @@ std::unique_ptr<DomainReliabilityBeacon> MakeBeacon(MockableTime* time) {
} }
template <typename ValueType, template <typename ValueType,
bool (DictionaryValue::* GetValueType)(const std::string&, bool (DictionaryValue::*GetValueType)(base::StringPiece, ValueType*)
ValueType*) const> const>
struct HasValue { struct HasValue {
bool operator()(const DictionaryValue& dict, bool operator()(const DictionaryValue& dict,
const std::string& key, const std::string& key,
......
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