diff options
26 files changed, 398 insertions, 201 deletions
diff --git a/base/json/json_writer.cc b/base/json/json_writer.cc index fa43953..dbf43ec 100644 --- a/base/json/json_writer.cc +++ b/base/json/json_writer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -188,8 +188,10 @@ void JSONWriter::BuildJSONString(const Value* const node, } } -void JSONWriter::AppendQuotedString(const std::wstring& str) { - JsonDoubleQuote(WideToUTF16Hack(str), true, json_string_); +void JSONWriter::AppendQuotedString(const std::string& str) { + // TODO(viettrungluu): |str| is UTF-8, not ASCII, so to properly escape it we + // have to convert it to UTF-16. This round-trip is suboptimal. + JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); } void JSONWriter::IndentLine(int depth) { diff --git a/base/json/json_writer.h b/base/json/json_writer.h index db24718..eb17145 100644 --- a/base/json/json_writer.h +++ b/base/json/json_writer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,8 +45,8 @@ class JSONWriter { // json_string_ will contain the JSON. void BuildJSONString(const Value* const node, int depth, bool escape); - // Appends a quoted, escaped, version of str to json_string_. - void AppendQuotedString(const std::wstring& str); + // Appends a quoted, escaped, version of (UTF-8) str to json_string_. + void AppendQuotedString(const std::string& str); // Adds space to json_string_ for the indent level. void IndentLine(int depth); diff --git a/base/values.cc b/base/values.cc index eebd7eb..3688c35 100644 --- a/base/values.cc +++ b/base/values.cc @@ -323,7 +323,7 @@ bool BinaryValue::Equals(const Value* other) const { ///////////////////// DictionaryValue //////////////////// DictionaryValue::DictionaryValue() - : Value(TYPE_DICTIONARY) { + : Value(TYPE_DICTIONARY) { } DictionaryValue::~DictionaryValue() { @@ -367,14 +367,20 @@ bool DictionaryValue::Equals(const Value* other) const { return true; } -bool DictionaryValue::HasKey(const std::wstring& key) const { +bool DictionaryValue::HasKey(const std::string& key) const { ValueMap::const_iterator current_entry = dictionary_.find(key); DCHECK((current_entry == dictionary_.end()) || current_entry->second); return current_entry != dictionary_.end(); } +// TODO(viettrungluu): Deprecated and to be removed: bool DictionaryValue::HasKeyASCII(const std::string& key) const { - return HasKey(ASCIIToWide(key)); + return HasKey(key); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::HasKey(const std::wstring& key) const { + return HasKey(WideToUTF8(key)); } void DictionaryValue::Clear() { @@ -387,16 +393,16 @@ void DictionaryValue::Clear() { dictionary_.clear(); } -void DictionaryValue::Set(const std::wstring& path, Value* in_value) { +void DictionaryValue::Set(const std::string& path, Value* in_value) { DCHECK(in_value); - std::wstring current_path(path); + std::string current_path(path); DictionaryValue* current_dictionary = this; for (size_t delimiter_position = current_path.find('.'); - delimiter_position != std::wstring::npos; + delimiter_position != std::string::npos; delimiter_position = current_path.find('.')) { // Assume that we're indexing into a dictionary. - std::wstring key(current_path, 0, delimiter_position); + std::string key(current_path, 0, delimiter_position); DictionaryValue* child_dictionary = NULL; if (!current_dictionary->GetDictionary(key, &child_dictionary)) { child_dictionary = new DictionaryValue; @@ -410,34 +416,67 @@ void DictionaryValue::Set(const std::wstring& path, Value* in_value) { current_dictionary->SetWithoutPathExpansion(current_path, in_value); } +// TODO(viettrungluu): Deprecated and to be removed: +void DictionaryValue::Set(const std::wstring& path, Value* in_value) { + Set(WideToUTF8(path), in_value); +} + +void DictionaryValue::SetBoolean(const std::string& path, bool in_value) { + Set(path, CreateBooleanValue(in_value)); +} + +void DictionaryValue::SetInteger(const std::string& path, int in_value) { + Set(path, CreateIntegerValue(in_value)); +} + +void DictionaryValue::SetReal(const std::string& path, double in_value) { + Set(path, CreateRealValue(in_value)); +} + +void DictionaryValue::SetString(const std::string& path, + const std::string& in_value) { + Set(path, CreateStringValue(in_value)); +} + +void DictionaryValue::SetStringFromUTF16(const std::string& path, + const string16& in_value) { + Set(path, CreateStringValueFromUTF16(in_value)); +} + +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetBoolean(const std::wstring& path, bool in_value) { Set(path, CreateBooleanValue(in_value)); } +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetInteger(const std::wstring& path, int in_value) { Set(path, CreateIntegerValue(in_value)); } +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetReal(const std::wstring& path, double in_value) { Set(path, CreateRealValue(in_value)); } +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetString(const std::wstring& path, const std::string& in_value) { Set(path, CreateStringValue(in_value)); } +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetString(const std::wstring& path, const std::wstring& in_value) { Set(path, CreateStringValue(in_value)); } +// TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetStringFromUTF16(const std::wstring& path, const string16& in_value) { Set(path, CreateStringValueFromUTF16(in_value)); } -void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, +void DictionaryValue::SetWithoutPathExpansion(const std::string& key, Value* in_value) { // If there's an existing value here, we need to delete it, because // we own all our children. @@ -449,11 +488,17 @@ void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, dictionary_[key] = in_value; } -bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const { - std::wstring current_path(path); +// TODO(viettrungluu): Deprecated and to be removed: +void DictionaryValue::SetWithoutPathExpansion(const std::wstring& key, + Value* in_value) { + SetWithoutPathExpansion(WideToUTF8(key), in_value); +} + +bool DictionaryValue::Get(const std::string& path, Value** out_value) const { + std::string current_path(path); const DictionaryValue* current_dictionary = this; for (size_t delimiter_position = current_path.find('.'); - delimiter_position != std::wstring::npos; + delimiter_position != std::string::npos; delimiter_position = current_path.find('.')) { DictionaryValue* child_dictionary = NULL; if (!current_dictionary->GetDictionary( @@ -467,7 +512,12 @@ bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const { return current_dictionary->GetWithoutPathExpansion(current_path, out_value); } -bool DictionaryValue::GetBoolean(const std::wstring& path, +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const { + return Get(WideToUTF8(path), out_value); +} + +bool DictionaryValue::GetBoolean(const std::string& path, bool* bool_value) const { Value* value; if (!Get(path, &value)) @@ -476,7 +526,7 @@ bool DictionaryValue::GetBoolean(const std::wstring& path, return value->GetAsBoolean(bool_value); } -bool DictionaryValue::GetInteger(const std::wstring& path, +bool DictionaryValue::GetInteger(const std::string& path, int* out_value) const { Value* value; if (!Get(path, &value)) @@ -485,7 +535,7 @@ bool DictionaryValue::GetInteger(const std::wstring& path, return value->GetAsInteger(out_value); } -bool DictionaryValue::GetReal(const std::wstring& path, +bool DictionaryValue::GetReal(const std::string& path, double* out_value) const { Value* value; if (!Get(path, &value)) @@ -495,26 +545,6 @@ bool DictionaryValue::GetReal(const std::wstring& path, } bool DictionaryValue::GetString(const std::string& path, - string16* out_value) const { - return GetStringAsUTF16(ASCIIToWide(path), out_value); -} - -bool DictionaryValue::GetStringASCII(const std::string& path, - std::string* out_value) const { - std::string out; - if (!GetString(ASCIIToWide(path), &out)) - return false; - - if (!IsStringASCII(out)) { - NOTREACHED(); - return false; - } - - out_value->assign(out); - return true; -} - -bool DictionaryValue::GetString(const std::wstring& path, std::string* out_value) const { Value* value; if (!Get(path, &value)) @@ -523,25 +553,31 @@ bool DictionaryValue::GetString(const std::wstring& path, return value->GetAsString(out_value); } -bool DictionaryValue::GetString(const std::wstring& path, - std::wstring* out_value) const { +bool DictionaryValue::GetStringAsUTF16(const std::string& path, + string16* out_value) const { Value* value; if (!Get(path, &value)) return false; - return value->GetAsString(out_value); + return value->GetAsUTF16(out_value); } -bool DictionaryValue::GetStringAsUTF16(const std::wstring& path, - string16* out_value) const { - Value* value; - if (!Get(path, &value)) +bool DictionaryValue::GetStringASCII(const std::string& path, + std::string* out_value) const { + std::string out; + if (!GetString(path, &out)) return false; - return value->GetAsUTF16(out_value); + if (!IsStringASCII(out)) { + NOTREACHED(); + return false; + } + + out_value->assign(out); + return true; } -bool DictionaryValue::GetBinary(const std::wstring& path, +bool DictionaryValue::GetBinary(const std::string& path, BinaryValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -554,7 +590,7 @@ bool DictionaryValue::GetBinary(const std::wstring& path, return true; } -bool DictionaryValue::GetDictionary(const std::wstring& path, +bool DictionaryValue::GetDictionary(const std::string& path, DictionaryValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -567,7 +603,7 @@ bool DictionaryValue::GetDictionary(const std::wstring& path, return true; } -bool DictionaryValue::GetList(const std::wstring& path, +bool DictionaryValue::GetList(const std::string& path, ListValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -580,7 +616,71 @@ bool DictionaryValue::GetList(const std::wstring& path, return true; } -bool DictionaryValue::GetWithoutPathExpansion(const std::wstring& key, +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetBoolean(const std::wstring& path, + bool* out_value) const { + return GetBoolean(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetInteger(const std::wstring& path, + int* out_value) const { + return GetInteger(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetReal(const std::wstring& path, + double* out_value) const { + return GetReal(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): or maybe we should get rid of the "AsUTF16" version? +bool DictionaryValue::GetString(const std::string& path, + string16* out_value) const { + return GetStringAsUTF16(path, out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetString(const std::wstring& path, + std::string* out_value) const { + return GetString(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetString(const std::wstring& path, + std::wstring* out_value) const { + Value* value; + if (!Get(WideToUTF8(path), &value)) + return false; + + return value->GetAsString(out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetStringAsUTF16(const std::wstring& path, + string16* out_value) const { + return GetStringAsUTF16(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetBinary(const std::wstring& path, + BinaryValue** out_value) const { + return GetBinary(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetDictionary(const std::wstring& path, + DictionaryValue** out_value) const { + return GetDictionary(WideToUTF8(path), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetList(const std::wstring& path, + ListValue** out_value) const { + return GetList(WideToUTF8(path), out_value); +} + +bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, Value** out_value) const { ValueMap::const_iterator entry_iterator = dictionary_.find(key); if (entry_iterator == dictionary_.end()) @@ -592,50 +692,40 @@ bool DictionaryValue::GetWithoutPathExpansion(const std::wstring& key, return true; } -bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::wstring& path, +bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::string& key, int* out_value) const { Value* value; - if (!GetWithoutPathExpansion(path, &value)) + if (!GetWithoutPathExpansion(key, &value)) return false; return value->GetAsInteger(out_value); } bool DictionaryValue::GetStringWithoutPathExpansion( - const std::wstring& path, + const std::string& key, std::string* out_value) const { Value* value; - if (!GetWithoutPathExpansion(path, &value)) - return false; - - return value->GetAsString(out_value); -} - -bool DictionaryValue::GetStringWithoutPathExpansion( - const std::wstring& path, - std::wstring* out_value) const { - Value* value; - if (!GetWithoutPathExpansion(path, &value)) + if (!GetWithoutPathExpansion(key, &value)) return false; return value->GetAsString(out_value); } bool DictionaryValue::GetStringAsUTF16WithoutPathExpansion( - const std::wstring& path, + const std::string& key, string16* out_value) const { Value* value; - if (!GetWithoutPathExpansion(path, &value)) + if (!GetWithoutPathExpansion(key, &value)) return false; return value->GetAsUTF16(out_value); } bool DictionaryValue::GetDictionaryWithoutPathExpansion( - const std::wstring& path, + const std::string& key, DictionaryValue** out_value) const { Value* value; - bool result = GetWithoutPathExpansion(path, &value); + bool result = GetWithoutPathExpansion(key, &value); if (!result || !value->IsType(TYPE_DICTIONARY)) return false; @@ -645,10 +735,10 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion( return true; } -bool DictionaryValue::GetListWithoutPathExpansion(const std::wstring& path, +bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, ListValue** out_value) const { Value* value; - bool result = GetWithoutPathExpansion(path, &value); + bool result = GetWithoutPathExpansion(key, &value); if (!result || !value->IsType(TYPE_LIST)) return false; @@ -658,11 +748,61 @@ bool DictionaryValue::GetListWithoutPathExpansion(const std::wstring& path, return true; } -bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { - std::wstring current_path(path); +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetWithoutPathExpansion(const std::wstring& key, + Value** out_value) const { + return GetWithoutPathExpansion(WideToUTF8(key), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetIntegerWithoutPathExpansion(const std::wstring& key, + int* out_value) const { + return GetIntegerWithoutPathExpansion(WideToUTF8(key), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetStringWithoutPathExpansion( + const std::wstring& key, + std::string* out_value) const { + return GetStringWithoutPathExpansion(WideToUTF8(key), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetStringWithoutPathExpansion( + const std::wstring& key, + std::wstring* out_value) const { + Value* value; + if (!GetWithoutPathExpansion(WideToUTF8(key), &value)) + return false; + + return value->GetAsString(out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetStringAsUTF16WithoutPathExpansion( + const std::wstring& key, + string16* out_value) const { + return GetStringAsUTF16WithoutPathExpansion(WideToUTF8(key), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetDictionaryWithoutPathExpansion( + const std::wstring& key, + DictionaryValue** out_value) const { + return GetDictionaryWithoutPathExpansion(WideToUTF8(key), out_value); +} + +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::GetListWithoutPathExpansion(const std::wstring& key, + ListValue** out_value) const { + return GetListWithoutPathExpansion(WideToUTF8(key), out_value); +} + +bool DictionaryValue::Remove(const std::string& path, Value** out_value) { + std::string current_path(path); DictionaryValue* current_dictionary = this; size_t delimiter_position = current_path.rfind('.'); - if (delimiter_position != std::wstring::npos) { + if (delimiter_position != std::string::npos) { if (!GetDictionary(current_path.substr(0, delimiter_position), ¤t_dictionary)) return false; @@ -673,7 +813,12 @@ bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { out_value); } -bool DictionaryValue::RemoveWithoutPathExpansion(const std::wstring& key, +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { + return Remove(WideToUTF8(path), out_value); +} + +bool DictionaryValue::RemoveWithoutPathExpansion(const std::string& key, Value** out_value) { ValueMap::iterator entry_iterator = dictionary_.find(key); if (entry_iterator == dictionary_.end()) @@ -688,6 +833,12 @@ bool DictionaryValue::RemoveWithoutPathExpansion(const std::wstring& key, return true; } +// TODO(viettrungluu): Deprecated and to be removed: +bool DictionaryValue::RemoveWithoutPathExpansion(const std::wstring& key, + Value** out_value) { + return RemoveWithoutPathExpansion(WideToUTF8(key), out_value); +} + DictionaryValue* DictionaryValue::DeepCopyWithoutEmptyChildren() { Value* copy = CopyWithoutEmptyChildren(this); return copy ? static_cast<DictionaryValue*>(copy) : new DictionaryValue; diff --git a/base/values.h b/base/values.h index 32d8a18..cc9d0fc 100644 --- a/base/values.h +++ b/base/values.h @@ -39,7 +39,7 @@ class DictionaryValue; class ListValue; typedef std::vector<Value*> ValueVector; -typedef std::map<std::wstring, Value*> ValueMap; +typedef std::map<std::string, Value*> ValueMap; // The Value class is the base class for Values. A Value can be // instantiated via the Create*Value() factory methods, or by directly @@ -202,6 +202,7 @@ class BinaryValue: public Value { DISALLOW_COPY_AND_ASSIGN(BinaryValue); }; +// TODO(viettrungluu): Things marked DEPRECATED will be removed. crbug.com/23581 class DictionaryValue : public Value { public: DictionaryValue(); @@ -212,10 +213,9 @@ class DictionaryValue : public Value { virtual bool Equals(const Value* other) const; // Returns true if the current dictionary has a value for the given key. - bool HasKeyASCII(const std::string& key) const; - // Deprecated version of the above. TODO: add a string16 version for Unicode. - // http://code.google.com/p/chromium/issues/detail?id=23581 - bool HasKey(const std::wstring& key) const; + bool HasKey(const std::string& key) const; + /*DEPRECATED*/bool HasKeyASCII(const std::string& key) const; + /*DEPRECATED*/bool HasKey(const std::wstring& key) const; // Returns the number of Values in this dictionary. size_t size() const { return dictionary_.size(); } @@ -235,20 +235,31 @@ class DictionaryValue : public Value { // to the path in that location. // Note that the dictionary takes ownership of the value referenced by // |in_value|, and therefore |in_value| must be non-NULL. - void Set(const std::wstring& path, Value* in_value); + void Set(const std::string& path, Value* in_value); + /*DEPRECATED*/void Set(const std::wstring& path, Value* in_value); // Convenience forms of Set(). These methods will replace any existing // value at that path, even if it has a different type. - void SetBoolean(const std::wstring& path, bool in_value); - void SetInteger(const std::wstring& path, int in_value); - void SetReal(const std::wstring& path, double in_value); - void SetString(const std::wstring& path, const std::string& in_value); - void SetString(const std::wstring& path, const std::wstring& in_value); - void SetStringFromUTF16(const std::wstring& path, const string16& in_value); + void SetBoolean(const std::string& path, bool in_value); + void SetInteger(const std::string& path, int in_value); + void SetReal(const std::string& path, double in_value); + void SetString(const std::string& path, const std::string& in_value); + void SetStringFromUTF16(const std::string& path, const string16& in_value); + /*DEPRECATED*/void SetBoolean(const std::wstring& path, bool in_value); + /*DEPRECATED*/void SetInteger(const std::wstring& path, int in_value); + /*DEPRECATED*/void SetReal(const std::wstring& path, double in_value); + /*DEPRECATED*/void SetString(const std::wstring& path, + const std::string& in_value); + /*DEPRECATED*/void SetString(const std::wstring& path, + const std::wstring& in_value); + /*DEPRECATED*/void SetStringFromUTF16(const std::wstring& path, + const string16& in_value); // Like Set(), but without special treatment of '.'. This allows e.g. URLs to // be used as paths. - void SetWithoutPathExpansion(const std::wstring& key, Value* in_value); + void SetWithoutPathExpansion(const std::string& key, Value* in_value); + /*DEPRECATED*/void SetWithoutPathExpansion(const std::wstring& key, + Value* in_value); // Gets the Value associated with the given path starting from this object. // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes @@ -257,42 +268,70 @@ class DictionaryValue : public Value { // through the |out_value| parameter, and the function will return true. // Otherwise, it will return false and |out_value| will be untouched. // Note that the dictionary always owns the value that's returned. - bool Get(const std::wstring& path, Value** out_value) const; + bool Get(const std::string& path, Value** out_value) const; + /*DEPRECATED*/bool Get(const std::wstring& path, Value** out_value) const; // These are convenience forms of Get(). The value will be retrieved // 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. - bool GetBoolean(const std::wstring& path, bool* out_value) const; - bool GetInteger(const std::wstring& path, int* out_value) const; - bool GetReal(const std::wstring& path, double* out_value) const; - bool GetString(const std::string& path, string16* out_value) const; + bool GetBoolean(const std::string& path, bool* out_value) const; + bool GetInteger(const std::string& path, int* out_value) const; + bool GetReal(const std::string& path, double* out_value) const; + bool GetString(const std::string& path, std::string* out_value) const; + bool GetStringAsUTF16(const std::string& path, string16* out_value) const; bool GetStringASCII(const std::string& path, std::string* out_value) const; - // TODO: deprecate wstring accessors. - // http://code.google.com/p/chromium/issues/detail?id=23581 - bool GetString(const std::wstring& path, std::string* out_value) const; - bool GetString(const std::wstring& path, std::wstring* out_value) const; - bool GetStringAsUTF16(const std::wstring& path, string16* out_value) const; - bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; - bool GetDictionary(const std::wstring& path, + bool GetBinary(const std::string& path, BinaryValue** out_value) const; + bool GetDictionary(const std::string& path, DictionaryValue** out_value) const; - bool GetList(const std::wstring& path, ListValue** out_value) const; + bool GetList(const std::string& path, ListValue** out_value) const; + /*DEPRECATED*/bool GetBoolean(const std::wstring& path, + bool* out_value) const; + /*DEPRECATED*/bool GetInteger(const std::wstring& path, int* out_value) const; + /*DEPRECATED*/bool GetReal(const std::wstring& path, double* out_value) const; + // Use |GetStringAsUTF16()| instead: + /*DEPRECATED*/bool GetString(const std::string& path, + string16* out_value) const; + /*DEPRECATED*/bool GetString(const std::wstring& path, + std::string* out_value) const; + /*DEPRECATED*/bool GetString(const std::wstring& path, + std::wstring* out_value) const; + /*DEPRECATED*/bool GetStringAsUTF16(const std::wstring& path, + string16* out_value) const; + /*DEPRECATED*/bool GetBinary(const std::wstring& path, + BinaryValue** out_value) const; + /*DEPRECATED*/bool GetDictionary(const std::wstring& path, + DictionaryValue** out_value) const; + /*DEPRECATED*/bool GetList(const std::wstring& path, + ListValue** out_value) const; // Like Get(), but without special treatment of '.'. This allows e.g. URLs to // be used as paths. - bool GetWithoutPathExpansion(const std::wstring& key, + bool GetWithoutPathExpansion(const std::string& key, Value** out_value) const; - bool GetIntegerWithoutPathExpansion(const std::wstring& path, + bool GetIntegerWithoutPathExpansion(const std::string& key, int* out_value) const; - bool GetStringWithoutPathExpansion(const std::wstring& path, + bool GetStringWithoutPathExpansion(const std::string& key, std::string* out_value) const; - bool GetStringWithoutPathExpansion(const std::wstring& path, - std::wstring* out_value) const; - bool GetStringAsUTF16WithoutPathExpansion(const std::wstring& path, + bool GetStringAsUTF16WithoutPathExpansion(const std::string& key, string16* out_value) const; - bool GetDictionaryWithoutPathExpansion(const std::wstring& path, + bool GetDictionaryWithoutPathExpansion(const std::string& key, DictionaryValue** out_value) const; - bool GetListWithoutPathExpansion(const std::wstring& path, + bool GetListWithoutPathExpansion(const std::string& key, ListValue** out_value) const; + /*DEPRECATED*/bool GetWithoutPathExpansion(const std::wstring& key, + Value** out_value) const; + /*DEPRECATED*/bool GetIntegerWithoutPathExpansion(const std::wstring& key, + int* out_value) const; + /*DEPRECATED*/bool GetStringWithoutPathExpansion( + const std::wstring& key, std::string* out_value) const; + /*DEPRECATED*/bool GetStringWithoutPathExpansion( + const std::wstring& key, std::wstring* out_value) const; + /*DEPRECATED*/bool GetStringAsUTF16WithoutPathExpansion( + const std::wstring& key, string16* out_value) const; + /*DEPRECATED*/bool GetDictionaryWithoutPathExpansion( + const std::wstring& key, DictionaryValue** out_value) const; + /*DEPRECATED*/bool GetListWithoutPathExpansion(const std::wstring& key, + ListValue** out_value) const; // 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). @@ -300,11 +339,14 @@ class DictionaryValue : public Value { // passed out via 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 return false and the DictionaryValue object will be unchanged. - bool Remove(const std::wstring& path, Value** out_value); + bool Remove(const std::string& path, Value** out_value); + /*DEPRECATED*/bool Remove(const std::wstring& path, Value** out_value); // Like Remove(), but without special treatment of '.'. This allows e.g. URLs // to be used as paths. - bool RemoveWithoutPathExpansion(const std::wstring& key, Value** out_value); + bool RemoveWithoutPathExpansion(const std::string& key, Value** out_value); + /*DEPRECATED*/bool RemoveWithoutPathExpansion(const std::wstring& key, + Value** out_value); // 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. @@ -323,14 +365,14 @@ class DictionaryValue : public Value { // THE NORMAL XXX() APIs. This makes sure things will work correctly if any // keys have '.'s in them. class key_iterator - : private std::iterator<std::input_iterator_tag, const std::wstring> { + : private std::iterator<std::input_iterator_tag, const std::string> { public: explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } key_iterator operator++() { ++itr_; return *this; } - const std::wstring& operator*() { return itr_->first; } + const std::string& operator*() { return itr_->first; } bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } bool operator==(const key_iterator& other) { return itr_ == other.itr_; } diff --git a/chrome/browser/background_contents_service.cc b/chrome/browser/background_contents_service.cc index c10d9d2..654a0a1 100644 --- a/chrome/browser/background_contents_service.cc +++ b/chrome/browser/background_contents_service.cc @@ -151,7 +151,7 @@ void BackgroundContentsService::LoadBackgroundContentsFromPrefs( CreateBackgroundContents(profile, GURL(url), frame_name, - WideToUTF16(*it)); + UTF8ToUTF16(*it)); } } diff --git a/chrome/browser/browser_theme_pack.cc b/chrome/browser/browser_theme_pack.cc index 943b1e8..8d2fe89 100644 --- a/chrome/browser/browser_theme_pack.cc +++ b/chrome/browser/browser_theme_pack.cc @@ -618,7 +618,7 @@ void BrowserThemePack::BuildTintsFromJSON(DictionaryValue* tints_value) { if (ValidRealValue(tint_list, 0, &hsl.h) && ValidRealValue(tint_list, 1, &hsl.s) && ValidRealValue(tint_list, 2, &hsl.l)) { - int id = GetIntForString(WideToUTF8(*iter), kTintTable); + int id = GetIntForString(*iter, kTintTable); if (id != -1) { temp_tints[id] = hsl; } @@ -689,7 +689,7 @@ void BrowserThemePack::ReadColorsFromJSON( color = SkColorSetRGB(r, g, b); } - int id = GetIntForString(WideToUTF8(*iter), kColorTable); + int id = GetIntForString(*iter, kColorTable); if (id != -1) { (*temp_colors)[id] = color; } @@ -769,7 +769,7 @@ void BrowserThemePack::BuildDisplayPropertiesFromJSON( for (DictionaryValue::key_iterator iter( display_properties_value->begin_keys()); iter != display_properties_value->end_keys(); ++iter) { - int property_id = GetIntForString(WideToUTF8(*iter), kDisplayProperties); + int property_id = GetIntForString(*iter, kDisplayProperties); switch (property_id) { case BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT: { std::string val; @@ -817,7 +817,7 @@ void BrowserThemePack::ParseImageNamesFromJSON( iter != images_value->end_keys(); ++iter) { std::string val; if (images_value->GetString(*iter, &val)) { - int id = GetPersistentIDByName(WideToUTF8(*iter)); + int id = GetPersistentIDByName(*iter); if (id != -1) (*file_paths)[id] = images_path.AppendASCII(val); } diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 4006120..8380543 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -82,16 +82,16 @@ namespace { // and http://crbug.com/39745 for more details). static void CleanupBadExtensionKeys(PrefService* prefs) { DictionaryValue* dictionary = prefs->GetMutableDictionary(kExtensionsPref); - std::set<std::wstring> bad_keys; + std::set<std::string> bad_keys; for (DictionaryValue::key_iterator i = dictionary->begin_keys(); i != dictionary->end_keys(); ++i) { - const std::wstring key_name = *i; - if (!Extension::IdIsValid(WideToASCII(key_name))) { + const std::string& key_name(*i); + if (!Extension::IdIsValid(key_name)) { bad_keys.insert(key_name); } } bool dirty = false; - for (std::set<std::wstring>::iterator i = bad_keys.begin(); + for (std::set<std::string>::iterator i = bad_keys.begin(); i != bad_keys.end(); ++i) { dirty = true; dictionary->Remove(*i, NULL); @@ -259,7 +259,7 @@ void ExtensionPrefs::UpdateBlacklist( NOTREACHED() << "Invalid pref for extension " << *extension_id; continue; } - std::string id = WideToASCII(*extension_id); + const std::string& id(*extension_id); if (blacklist_set.find(id) == blacklist_set.end()) { if (!IsBlacklistBitSet(ext)) { // This extension is not in blacklist. And it was not blacklisted @@ -373,10 +373,9 @@ void ExtensionPrefs::GetKilledExtensionIds(std::set<std::string>* killed_ids) { for (DictionaryValue::key_iterator i = dict->begin_keys(); i != dict->end_keys(); ++i) { - std::wstring key_name = *i; - if (!Extension::IdIsValid(WideToASCII(key_name))) { - LOG(WARNING) << "Invalid external extension ID encountered: " - << WideToASCII(key_name); + const std::string& key_name(*i); + if (!Extension::IdIsValid(key_name)) { + LOG(WARNING) << "Invalid external extension ID encountered: " << key_name; continue; } @@ -390,8 +389,7 @@ void ExtensionPrefs::GetKilledExtensionIds(std::set<std::string>* killed_ids) { int state; if (extension->GetInteger(kPrefState, &state) && state == static_cast<int>(Extension::KILLBIT)) { - StringToLowerASCII(&key_name); - killed_ids->insert(WideToASCII(key_name)); + killed_ids->insert(StringToLowerASCII(key_name)); } } } @@ -643,8 +641,7 @@ static ExtensionInfo* GetInstalledExtensionInfoImpl( // Just a warning for now. } - return new ExtensionInfo(manifest, WideToASCII(*extension_id), - FilePath(path), location); + return new ExtensionInfo(manifest, *extension_id, FilePath(path), location); } ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::GetInstalledExtensionsInfo() { @@ -655,7 +652,7 @@ ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::GetInstalledExtensionsInfo() { for (DictionaryValue::key_iterator extension_id( extension_data->begin_keys()); extension_id != extension_data->end_keys(); ++extension_id) { - if (!Extension::IdIsValid(WideToASCII(*extension_id))) + if (!Extension::IdIsValid(*extension_id)) continue; ExtensionInfo* info = GetInstalledExtensionInfoImpl(extension_data.get(), @@ -674,7 +671,7 @@ ExtensionInfo* ExtensionPrefs::GetInstalledExtensionInfo( for (DictionaryValue::key_iterator extension_iter( extension_data->begin_keys()); extension_iter != extension_data->end_keys(); ++extension_iter) { - if (WideToASCII(*extension_iter) == extension_id) { + if (*extension_iter == extension_id) { return GetInstalledExtensionInfoImpl(extension_data.get(), extension_iter); } @@ -762,7 +759,7 @@ std::set<std::string> ExtensionPrefs::GetIdleInstallInfoIds() { for (DictionaryValue::key_iterator iter = extensions->begin_keys(); iter != extensions->end_keys(); ++iter) { - std::string id = WideToASCII(*iter); + const std::string& id(*iter); if (!Extension::IdIsValid(id)) { NOTREACHED(); continue; diff --git a/chrome/browser/extensions/external_pref_extension_provider.cc b/chrome/browser/extensions/external_pref_extension_provider.cc index 5fe39b4..a7c99ff 100644 --- a/chrome/browser/extensions/external_pref_extension_provider.cc +++ b/chrome/browser/extensions/external_pref_extension_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,8 +44,8 @@ void ExternalPrefExtensionProvider::VisitRegisteredExtension( Visitor* visitor, const std::set<std::string>& ids_to_ignore) const { for (DictionaryValue::key_iterator i = prefs_->begin_keys(); i != prefs_->end_keys(); ++i) { - const std::wstring& extension_id = *i; - if (ids_to_ignore.find(WideToASCII(extension_id)) != ids_to_ignore.end()) + const std::string& extension_id = *i; + if (ids_to_ignore.find(extension_id) != ids_to_ignore.end()) continue; DictionaryValue* extension; @@ -79,8 +79,8 @@ void ExternalPrefExtensionProvider::VisitRegisteredExtension( scoped_ptr<Version> version; version.reset(Version::GetVersionFromString(external_version)); - visitor->OnExternalExtensionFound(WideToASCII(extension_id), version.get(), - path, Extension::EXTERNAL_PREF); + visitor->OnExternalExtensionFound(extension_id, version.get(), path, + Extension::EXTERNAL_PREF); } } diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc index a564d11..de3a8a6 100644 --- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/scoped_handle.h" #include "base/task.h" +#include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. #include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" @@ -381,7 +382,9 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { return false; } - FilePath relative_path = FilePath::FromWStringHack(*key_it); + // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())| + // hack and remove the corresponding #include. + FilePath relative_path = FilePath::FromWStringHack(UTF8ToWide(*key_it)); relative_path = relative_path.Append(Extension::kMessagesFilename); if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { ReportFailure("Invalid path for catalog."); diff --git a/chrome/browser/geolocation/access_token_store.cc b/chrome/browser/geolocation/access_token_store.cc index b0d2d5e..f790c51 100644 --- a/chrome/browser/geolocation/access_token_store.cc +++ b/chrome/browser/geolocation/access_token_store.cc @@ -47,7 +47,7 @@ void ChromePrefsAccessTokenStore::LoadDictionaryStoreInUIThread( if (token_dictionary != NULL) { for (DictionaryValue::key_iterator it = token_dictionary->begin_keys(); it != token_dictionary->end_keys(); ++it) { - GURL url(WideToUTF8(*it)); + GURL url(*it); if (!url.is_valid()) continue; token_dictionary->GetStringAsUTF16WithoutPathExpansion( diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc index 2723870..77fb103 100644 --- a/chrome/browser/geolocation/geolocation_content_settings_map.cc +++ b/chrome/browser/geolocation/geolocation_content_settings_map.cc @@ -92,13 +92,13 @@ GeolocationContentSettingsMap::AllOriginsSettings if (all_settings_dictionary != NULL) { for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); i != all_settings_dictionary->end_keys(); ++i) { - const std::wstring& wide_origin(*i); - GURL origin_as_url(WideToUTF8(wide_origin)); + const std::string& origin(*i); + GURL origin_as_url(origin); if (!origin_as_url.is_valid()) continue; DictionaryValue* requesting_origin_settings_dictionary = NULL; bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( - wide_origin, &requesting_origin_settings_dictionary); + origin, &requesting_origin_settings_dictionary); DCHECK(found); if (!requesting_origin_settings_dictionary) continue; @@ -177,11 +177,11 @@ void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary( OneOriginSettings* one_origin_settings) { for (DictionaryValue::key_iterator i(dictionary->begin_keys()); i != dictionary->end_keys(); ++i) { - const std::wstring& target(*i); + const std::string& target(*i); int setting = kDefaultSetting; bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting); DCHECK(found); - GURL target_url(WideToUTF8(target)); + GURL target_url(target); // An empty URL has a special meaning (wildcard), so only accept invalid // URLs if the original version was empty (avoids treating corrupted prefs // as the wildcard entry; see http://crbug.com/39685) diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index 324f207..2e4fbb0 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -730,7 +730,7 @@ bool TopSites::GetPinnedURLAtIndex(size_t index, GURL* url) { int current_index; if (pinned_urls_->GetIntegerWithoutPathExpansion(*it, ¤t_index)) { if (static_cast<size_t>(current_index) == index) { - *url = GURL(WideToASCII(*it)); + *url = GURL(*it); return true; } } diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc index f09ac13..ce53c2d 100644 --- a/chrome/browser/host_content_settings_map.cc +++ b/chrome/browser/host_content_settings_map.cc @@ -152,11 +152,11 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile) prefs->GetDictionary(prefs::kPerHostContentSettings); for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); i != all_settings_dictionary->end_keys(); ++i) { - std::wstring wide_host(*i); - Pattern pattern(std::string(kDomainWildcard) + WideToUTF8(wide_host)); + const std::string& host(*i); + Pattern pattern(std::string(kDomainWildcard) + host); DictionaryValue* host_settings_dictionary = NULL; bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( - wide_host, &host_settings_dictionary); + host, &host_settings_dictionary); DCHECK(found); ContentSettings settings; GetSettingsFromDictionary(host_settings_dictionary, &settings); @@ -570,14 +570,14 @@ void HostContentSettingsMap::GetSettingsFromDictionary( ContentSettings* settings) { for (DictionaryValue::key_iterator i(dictionary->begin_keys()); i != dictionary->end_keys(); ++i) { - std::wstring content_type(*i); + const std::string& content_type(*i); int setting = CONTENT_SETTING_DEFAULT; bool found = dictionary->GetIntegerWithoutPathExpansion(content_type, &setting); DCHECK(found); for (size_t type = 0; type < arraysize(kTypeNames); ++type) { if ((kTypeNames[type] != NULL) && - (std::wstring(kTypeNames[type]) == content_type)) { + (WideToUTF8(kTypeNames[type]) == content_type)) { settings->settings[type] = IntToContentSetting(setting); break; } @@ -634,16 +634,16 @@ void HostContentSettingsMap::ReadExceptions(bool overwrite) { if (all_settings_dictionary != NULL) { for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); i != all_settings_dictionary->end_keys(); ++i) { - std::wstring wide_pattern(*i); - if (!Pattern(WideToUTF8(wide_pattern)).IsValid()) + const std::string& pattern(*i); + if (!Pattern(pattern).IsValid()) LOG(WARNING) << "Invalid pattern stored in content settings"; DictionaryValue* pattern_settings_dictionary = NULL; bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( - wide_pattern, &pattern_settings_dictionary); + pattern, &pattern_settings_dictionary); DCHECK(found); ContentSettings settings; GetSettingsFromDictionary(pattern_settings_dictionary, &settings); - host_content_settings_[WideToUTF8(wide_pattern)] = settings; + host_content_settings_[pattern] = settings; } } } diff --git a/chrome/browser/host_zoom_map.cc b/chrome/browser/host_zoom_map.cc index 50e1519..512fdf0 100644 --- a/chrome/browser/host_zoom_map.cc +++ b/chrome/browser/host_zoom_map.cc @@ -42,12 +42,12 @@ void HostZoomMap::Load() { if (host_zoom_dictionary != NULL) { for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); i != host_zoom_dictionary->end_keys(); ++i) { - std::wstring wide_host(*i); + const std::string& host(*i); int zoom_level = 0; bool success = host_zoom_dictionary->GetIntegerWithoutPathExpansion( - wide_host, &zoom_level); + host, &zoom_level); DCHECK(success); - host_zoom_levels_[WideToUTF8(wide_host)] = zoom_level; + host_zoom_levels_[host] = zoom_level; } } } diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 7384a2a..9b51cfa 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -354,10 +354,10 @@ void MetricsLog::RecordEnvironment( void MetricsLog::WriteAllProfilesMetrics( const DictionaryValue& all_profiles_metrics) { - const std::wstring profile_prefix(prefs::kProfilePrefix); + const std::string profile_prefix(WideToUTF8(prefs::kProfilePrefix)); for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); i != all_profiles_metrics.end_keys(); ++i) { - const std::wstring& key_name = *i; + const std::string& key_name = *i; if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { DictionaryValue* profile; if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, @@ -367,21 +367,21 @@ void MetricsLog::WriteAllProfilesMetrics( } } -void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash, +void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, const DictionaryValue& profile_metrics) { OPEN_ELEMENT_FOR_SCOPE("userprofile"); - WriteAttribute("profileidhash", WideToUTF8(profileidhash)); + WriteAttribute("profileidhash", profileidhash); for (DictionaryValue::key_iterator i = profile_metrics.begin_keys(); i != profile_metrics.end_keys(); ++i) { Value* value; if (profile_metrics.GetWithoutPathExpansion(*i, &value)) { - DCHECK(*i != L"id"); + DCHECK(*i != "id"); switch (value->GetType()) { case Value::TYPE_STRING: { std::string string_value; if (value->GetAsString(&string_value)) { OPEN_ELEMENT_FOR_SCOPE("profileparam"); - WriteAttribute("name", WideToUTF8(*i)); + WriteAttribute("name", *i); WriteAttribute("value", string_value); } break; @@ -391,7 +391,7 @@ void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash, bool bool_value; if (value->GetAsBoolean(&bool_value)) { OPEN_ELEMENT_FOR_SCOPE("profileparam"); - WriteAttribute("name", WideToUTF8(*i)); + WriteAttribute("name", *i); WriteIntAttribute("value", bool_value ? 1 : 0); } break; @@ -401,7 +401,7 @@ void MetricsLog::WriteProfileMetrics(const std::wstring& profileidhash, int int_value; if (value->GetAsInteger(&int_value)) { OPEN_ELEMENT_FOR_SCOPE("profileparam"); - WriteAttribute("name", WideToUTF8(*i)); + WriteAttribute("name", *i); WriteIntAttribute("value", int_value); } break; diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index eb8e67f..081d4b1 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -93,7 +93,7 @@ class MetricsLog : public MetricsLogBase { // Writes metrics for the profile identified by key. This writes all // key/value pairs in profile_metrics. - void WriteProfileMetrics(const std::wstring& key, + void WriteProfileMetrics(const std::string& key, const DictionaryValue& profile_metrics); DISALLOW_COPY_AND_ASSIGN(MetricsLog); diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc index 48b766a..779faad 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc @@ -222,7 +222,7 @@ WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs( std::string value; if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value)) web_prefs.inspector_settings.push_back( - std::make_pair(WideToUTF8(*iter), value)); + std::make_pair(*iter, value)); } } web_prefs.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 59a2cfa6..d17d8e8 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -128,7 +128,7 @@ class WebDatabaseTest : public testing::Test { int b_count = GetKeyCount(b); DictionaryValue::key_iterator i(a.begin_keys()); DictionaryValue::key_iterator e(a.end_keys()); - std::wstring av, bv; + std::string av, bv; while (i != e) { if (!(a.GetStringWithoutPathExpansion(*i, &av)) || !(b.GetStringWithoutPathExpansion(*i, &bv)) || diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index d32ef66..6d6c05d 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -514,11 +514,12 @@ ExtensionAction* Extension::LoadExtensionActionHelper( bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) { // Generate a map of allowable keys - static std::map<std::wstring, bool> theme_keys; + static std::map<std::string, bool> theme_keys; static bool theme_key_mapped = false; if (!theme_key_mapped) { for (size_t i = 0; i < arraysize(kValidThemeKeys); ++i) { - theme_keys[kValidThemeKeys[i]] = true; + // TODO(viettrungluu): Make the constants |char*|s and avoid converting. + theme_keys[WideToUTF8(kValidThemeKeys[i])] = true; } theme_key_mapped = true; } @@ -1454,7 +1455,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, // Validate that the overrides are all strings for (DictionaryValue::key_iterator iter = overrides->begin_keys(); iter != overrides->end_keys(); ++iter) { - std::string page = WideToUTF8(*iter); + std::string page = *iter; std::string val; // Restrict override pages to a list of supported URLs. if ((page != chrome::kChromeUINewTabHost && @@ -1529,6 +1530,8 @@ GURL Extension::GalleryUrl() const { std::set<FilePath> Extension::GetBrowserImages() { std::set<FilePath> image_paths; + // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| + // indicate that we're doing something wrong. // Extension icons. for (std::map<int, std::string>::iterator iter = icons_.begin(); @@ -1541,9 +1544,9 @@ std::set<FilePath> Extension::GetBrowserImages() { if (theme_images) { for (DictionaryValue::key_iterator it = theme_images->begin_keys(); it != theme_images->end_keys(); ++it) { - std::wstring val; + std::string val; if (theme_images->GetStringWithoutPathExpansion(*it, &val)) - image_paths.insert(FilePath::FromWStringHack(val)); + image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); } } diff --git a/chrome/common/extensions/extension_message_bundle.cc b/chrome/common/extensions/extension_message_bundle.cc index 6b001b1..04022cd 100644 --- a/chrome/common/extensions/extension_message_bundle.cc +++ b/chrome/common/extensions/extension_message_bundle.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,7 +73,7 @@ bool ExtensionMessageBundle::Init(const CatalogVector& locale_catalogs, DictionaryValue* catalog = (*it).get(); for (DictionaryValue::key_iterator key_it = catalog->begin_keys(); key_it != catalog->end_keys(); ++key_it) { - std::string key(StringToLowerASCII(WideToUTF8(*key_it))); + std::string key(StringToLowerASCII(*key_it)); if (!IsValidName(*key_it)) return BadKeyMessage(key, error); std::string value; @@ -126,14 +126,13 @@ bool ExtensionMessageBundle::AppendReservedMessagesForLocale( return true; } -bool ExtensionMessageBundle::GetMessageValue(const std::wstring& wkey, +bool ExtensionMessageBundle::GetMessageValue(const std::string& key, const DictionaryValue& catalog, std::string* value, std::string* error) const { - std::string key(WideToUTF8(wkey)); // Get the top level tree for given key (name part). DictionaryValue* name_tree; - if (!catalog.GetDictionaryWithoutPathExpansion(wkey, &name_tree)) { + if (!catalog.GetDictionaryWithoutPathExpansion(key, &name_tree)) { *error = StringPrintf("Not a valid tree for key %s.", key.c_str()); return false; } @@ -176,10 +175,10 @@ bool ExtensionMessageBundle::GetPlaceholders(const DictionaryValue& name_tree, for (DictionaryValue::key_iterator key_it = placeholders_tree->begin_keys(); key_it != placeholders_tree->end_keys(); ++key_it) { DictionaryValue* placeholder; - std::string content_key = WideToUTF8(*key_it); - if (!IsValidName(*key_it)) + const std::string& content_key(*key_it); + if (!IsValidName(content_key)) return BadKeyMessage(content_key, error); - if (!placeholders_tree->GetDictionaryWithoutPathExpansion(*key_it, + if (!placeholders_tree->GetDictionaryWithoutPathExpansion(content_key, &placeholder)) { *error = StringPrintf("Invalid placeholder %s for key %s", content_key.c_str(), diff --git a/chrome/common/extensions/extension_message_bundle.h b/chrome/common/extensions/extension_message_bundle.h index 2e62649..3c80356 100644 --- a/chrome/common/extensions/extension_message_bundle.h +++ b/chrome/common/extensions/extension_message_bundle.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -133,7 +133,7 @@ class ExtensionMessageBundle { // Helper methods that navigate JSON tree and return simplified message. // They replace all $PLACEHOLDERS$ with their value, and return just key/value // of the message. - bool GetMessageValue(const std::wstring& wkey, + bool GetMessageValue(const std::string& key, const DictionaryValue& catalog, std::string* value, std::string* error) const; diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index e9dff40..d3ee31a 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -19,6 +19,7 @@ #include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "base/win_util.h" #include "base/wmi_util.h" #include "chrome/common/chrome_switches.h" @@ -235,12 +236,12 @@ bool GoogleChromeDistribution::BuildUninstallMetricsString( iter != uninstall_metrics_dict->end_keys(); ++iter) { has_values = true; metrics->append(L"&"); - metrics->append(*iter); + metrics->append(UTF8ToWide(*iter)); metrics->append(L"="); - std::wstring value; + std::string value; uninstall_metrics_dict->GetStringWithoutPathExpansion(*iter, &value); - metrics->append(value); + metrics->append(UTF8ToWide(value)); } return has_values; diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index dc1314c..265e1d3 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -363,10 +363,10 @@ bool PrintSystemCUPS::ParsePrintTicket(const std::string& print_ticket, static_cast<DictionaryValue*>(ticket_value.get()); DictionaryValue::key_iterator it(ticket_dict->begin_keys()); for (; it != ticket_dict->end_keys(); ++it) { - std::wstring key = *it; + const std::string& key = *it; std::string value; if (ticket_dict->GetString(key, &value)) { - (*options)[WideToUTF8(key.c_str())] = value; + (*options)[key] = value; } } diff --git a/chrome/test/ui/javascript_test_util.cc b/chrome/test/ui/javascript_test_util.cc index 8f07809..f4b0f4a9 100644 --- a/chrome/test/ui/javascript_test_util.cc +++ b/chrome/test/ui/javascript_test_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,7 +40,7 @@ bool JsonDictionaryToMap(const std::string& json, EXPECT_TRUE(value->IsType(Value::TYPE_STRING)); if (value->IsType(Value::TYPE_STRING)) { - std::string key = WideToUTF8(*it); + const std::string& key(*it); std::string result; succeeded = value->GetAsString(&result); diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index 72679aa..41fbde7 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -100,7 +100,7 @@ static bool ReadDictionaryValue(const Message* m, void** iter, return false; for (int i = 0; i < size; ++i) { - std::wstring key; + std::string key; Value* subval; if (!ReadParam(m, iter, &key) || !ReadValue(m, iter, &subval, recursion + 1)) diff --git a/net/base/transport_security_state.cc b/net/base/transport_security_state.cc index 4fcc2b8..ca4dc1a 100644 --- a/net/base/transport_security_state.cc +++ b/net/base/transport_security_state.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -210,10 +210,9 @@ static std::wstring HashedDomainToExternalString(const std::string& hashed) { // This inverts |HashedDomainToExternalString|, above. It turns an external // string (from a JSON file) into an internal (binary) string. -static std::string ExternalStringToHashedDomain(const std::wstring& external) { - std::string external_ascii = WideToASCII(external); +static std::string ExternalStringToHashedDomain(const std::string& external) { std::string out; - if (!base::Base64Decode(external_ascii, &out) || + if (!base::Base64Decode(external, &out) || out.size() != base::SHA256_LENGTH) { return std::string(); } |