Commit 13740083 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Remove usage of deprecated unique_ptr<base::Value>

Value::Set() is deprecated and Value::SetKey/Path() should be used
instead. base::ValueConversions returns unique_ptr<base::Value> which is
hard to use with the new SetKey/Path methods because they expect a
Value.
This CL converts CreateFilePathValue, CreateTimeDeltaValue and
CreateUnguessableTokenValue to return a Value instead of a unique_ptr.

Tbr: benwells@chromium.org, bauerb@chromium.org, pfeldman@chromium.org, qinmin@chromium.org, xhwang@chromium.org
Change-Id: Ia464bce2cdd74e0e1b51b57050cac3c0176893f8
Reviewed-on: https://chromium-review.googlesource.com/1150036
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578277}
parent 7c6d591b
...@@ -67,7 +67,7 @@ void AddSavedFileEntry(ExtensionPrefs* prefs, ...@@ -67,7 +67,7 @@ void AddSavedFileEntry(ExtensionPrefs* prefs,
std::unique_ptr<base::DictionaryValue> file_entry_dict = std::unique_ptr<base::DictionaryValue> file_entry_dict =
std::make_unique<base::DictionaryValue>(); std::make_unique<base::DictionaryValue>();
file_entry_dict->Set(kFileEntryPath, CreateFilePathValue(file_entry.path)); file_entry_dict->SetKey(kFileEntryPath, CreateFilePathValue(file_entry.path));
file_entry_dict->SetBoolean(kFileEntryIsDirectory, file_entry.is_directory); file_entry_dict->SetBoolean(kFileEntryIsDirectory, file_entry.is_directory);
file_entry_dict->SetInteger(kFileEntrySequenceNumber, file_entry_dict->SetInteger(kFileEntrySequenceNumber,
file_entry.sequence_number); file_entry.sequence_number);
......
...@@ -71,10 +71,10 @@ TEST(UnguessableTokenTest, VerifySerialization) { ...@@ -71,10 +71,10 @@ TEST(UnguessableTokenTest, VerifySerialization) {
TEST(UnguessableTokenTest, VerifyValueSerialization) { TEST(UnguessableTokenTest, VerifyValueSerialization) {
UnguessableToken token = UnguessableToken::Create(); UnguessableToken token = UnguessableToken::Create();
std::unique_ptr<Value> value = CreateUnguessableTokenValue(token); Value value = CreateUnguessableTokenValue(token);
UnguessableToken deserialized; UnguessableToken deserialized;
EXPECT_TRUE(GetValueAsUnguessableToken(*value, &deserialized)); EXPECT_TRUE(GetValueAsUnguessableToken(value, &deserialized));
EXPECT_EQ(token, deserialized); EXPECT_EQ(token, deserialized);
} }
......
...@@ -32,8 +32,8 @@ union UnguessableTokenRepresentation { ...@@ -32,8 +32,8 @@ union UnguessableTokenRepresentation {
// |Value| internally stores strings in UTF-8, so we have to convert from the // |Value| internally stores strings in UTF-8, so we have to convert from the
// system native code to UTF-8 and back. // system native code to UTF-8 and back.
std::unique_ptr<Value> CreateFilePathValue(const FilePath& in_value) { Value CreateFilePathValue(const FilePath& in_value) {
return std::make_unique<Value>(in_value.AsUTF8Unsafe()); return Value(in_value.AsUTF8Unsafe());
} }
bool GetValueAsFilePath(const Value& value, FilePath* file_path) { bool GetValueAsFilePath(const Value& value, FilePath* file_path) {
...@@ -47,9 +47,9 @@ bool GetValueAsFilePath(const Value& value, FilePath* file_path) { ...@@ -47,9 +47,9 @@ bool GetValueAsFilePath(const Value& value, FilePath* file_path) {
// |Value| does not support 64-bit integers, and doubles do not have enough // |Value| does not support 64-bit integers, and doubles do not have enough
// precision, so we store the 64-bit time value as a string instead. // precision, so we store the 64-bit time value as a string instead.
std::unique_ptr<Value> CreateTimeDeltaValue(const TimeDelta& time) { Value CreateTimeDeltaValue(const TimeDelta& time) {
std::string string_value = base::Int64ToString(time.ToInternalValue()); std::string string_value = base::Int64ToString(time.ToInternalValue());
return std::make_unique<Value>(string_value); return Value(string_value);
} }
bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) { bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) {
...@@ -62,14 +62,12 @@ bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) { ...@@ -62,14 +62,12 @@ bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) {
return true; return true;
} }
std::unique_ptr<Value> CreateUnguessableTokenValue( Value CreateUnguessableTokenValue(const UnguessableToken& token) {
const UnguessableToken& token) {
UnguessableTokenRepresentation representation; UnguessableTokenRepresentation representation;
representation.field.high = token.GetHighForSerialization(); representation.field.high = token.GetHighForSerialization();
representation.field.low = token.GetLowForSerialization(); representation.field.low = token.GetLowForSerialization();
return std::make_unique<Value>( return Value(HexEncode(representation.buffer, sizeof(representation.buffer)));
HexEncode(representation.buffer, sizeof(representation.buffer)));
} }
bool GetValueAsUnguessableToken(const Value& value, UnguessableToken* token) { bool GetValueAsUnguessableToken(const Value& value, UnguessableToken* token) {
......
...@@ -18,15 +18,13 @@ class UnguessableToken; ...@@ -18,15 +18,13 @@ class UnguessableToken;
class Value; class Value;
// The caller takes ownership of the returned value. // The caller takes ownership of the returned value.
BASE_EXPORT std::unique_ptr<Value> CreateFilePathValue( BASE_EXPORT Value CreateFilePathValue(const FilePath& in_value);
const FilePath& in_value);
BASE_EXPORT bool GetValueAsFilePath(const Value& value, FilePath* file_path); BASE_EXPORT bool GetValueAsFilePath(const Value& value, FilePath* file_path);
BASE_EXPORT std::unique_ptr<Value> CreateTimeDeltaValue(const TimeDelta& time); BASE_EXPORT Value CreateTimeDeltaValue(const TimeDelta& time);
BASE_EXPORT bool GetValueAsTimeDelta(const Value& value, TimeDelta* time); BASE_EXPORT bool GetValueAsTimeDelta(const Value& value, TimeDelta* time);
BASE_EXPORT std::unique_ptr<Value> CreateUnguessableTokenValue( BASE_EXPORT Value CreateUnguessableTokenValue(const UnguessableToken& token);
const UnguessableToken& token);
BASE_EXPORT bool GetValueAsUnguessableToken(const Value& value, BASE_EXPORT bool GetValueAsUnguessableToken(const Value& value,
UnguessableToken* token); UnguessableToken* token);
......
...@@ -296,8 +296,7 @@ void DevToolsFileHelper::SaveAsFileSelected(const std::string& url, ...@@ -296,8 +296,7 @@ void DevToolsFileHelper::SaveAsFileSelected(const std::string& url,
DictionaryPrefUpdate update(profile_->GetPrefs(), DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kDevToolsEditedFiles); prefs::kDevToolsEditedFiles);
base::DictionaryValue* files_map = update.Get(); base::DictionaryValue* files_map = update.Get();
files_map->SetWithoutPathExpansion(base::MD5String(url), files_map->SetKey(base::MD5String(url), base::CreateFilePathValue(path));
base::CreateFilePathValue(path));
std::string file_system_path = path.AsUTF8Unsafe(); std::string file_system_path = path.AsUTF8Unsafe();
callback.Run(file_system_path); callback.Run(file_system_path);
file_task_runner_->PostTask(FROM_HERE, BindOnce(&WriteToFile, path, content)); file_task_runner_->PostTask(FROM_HERE, BindOnce(&WriteToFile, path, content));
......
...@@ -407,7 +407,8 @@ void DownloadTargetDeterminerTest::EnableAutoOpenBasedOnExtension( ...@@ -407,7 +407,8 @@ void DownloadTargetDeterminerTest::EnableAutoOpenBasedOnExtension(
void DownloadTargetDeterminerTest::SetManagedDownloadPath( void DownloadTargetDeterminerTest::SetManagedDownloadPath(
const base::FilePath& path) { const base::FilePath& path) {
profile()->GetTestingPrefService()->SetManagedPref( profile()->GetTestingPrefService()->SetManagedPref(
prefs::kDownloadDefaultDirectory, base::CreateFilePathValue(path)); prefs::kDownloadDefaultDirectory,
base::Value::ToUniquePtrValue(base::CreateFilePathValue(path)));
} }
void DownloadTargetDeterminerTest::SetPromptForDownload(bool prompt) { void DownloadTargetDeterminerTest::SetPromptForDownload(bool prompt) {
......
...@@ -240,8 +240,7 @@ void MarkProfileDirectoryForDeletion(const base::FilePath& path) { ...@@ -240,8 +240,7 @@ void MarkProfileDirectoryForDeletion(const base::FilePath& path) {
// on shutdown. In case of a crash remaining files are removed on next start. // on shutdown. In case of a crash remaining files are removed on next start.
ListPrefUpdate deleted_profiles(g_browser_process->local_state(), ListPrefUpdate deleted_profiles(g_browser_process->local_state(),
prefs::kProfilesDeleted); prefs::kProfilesDeleted);
std::unique_ptr<base::Value> value(CreateFilePathValue(path)); deleted_profiles->GetList().push_back(CreateFilePathValue(path));
deleted_profiles->Append(std::move(value));
} }
// Cancel a scheduling deletion, so ScheduleProfileDirectoryForDeletion can be // Cancel a scheduling deletion, so ScheduleProfileDirectoryForDeletion can be
......
...@@ -210,7 +210,7 @@ DownloadsListTracker::CreateDownloadItemValue( ...@@ -210,7 +210,7 @@ DownloadsListTracker::CreateDownloadItemValue(
file_value->SetString("id", base::NumberToString(download_item->GetId())); file_value->SetString("id", base::NumberToString(download_item->GetId()));
base::FilePath download_path(download_item->GetTargetFilePath()); base::FilePath download_path(download_item->GetTargetFilePath());
file_value->Set("file_path", base::CreateFilePathValue(download_path)); file_value->SetKey("file_path", base::CreateFilePathValue(download_path));
file_value->SetString("file_url", file_value->SetString("file_url",
net::FilePathToFileURL(download_path).spec()); net::FilePathToFileURL(download_path).spec());
......
...@@ -796,8 +796,8 @@ void UserManagerScreenHandler::SendUserList() { ...@@ -796,8 +796,8 @@ void UserManagerScreenHandler::SendUserList() {
profile_value->SetString(kKeyEmailAddress, entry->GetUserName()); profile_value->SetString(kKeyEmailAddress, entry->GetUserName());
profile_value->SetString(kKeyDisplayName, profile_value->SetString(kKeyDisplayName,
profiles::GetAvatarNameForProfile(profile_path)); profiles::GetAvatarNameForProfile(profile_path));
profile_value->Set(kKeyProfilePath, profile_value->SetKey(kKeyProfilePath,
base::CreateFilePathValue(profile_path)); base::CreateFilePathValue(profile_path));
profile_value->SetBoolean(kKeyPublicAccount, false); profile_value->SetBoolean(kKeyPublicAccount, false);
profile_value->SetBoolean(kKeyLegacySupervisedUser, profile_value->SetBoolean(kKeyLegacySupervisedUser,
entry->IsLegacySupervised()); entry->IsLegacySupervised());
......
...@@ -74,8 +74,8 @@ std::unique_ptr<base::DictionaryValue> ProtocolHandler::Encode() const { ...@@ -74,8 +74,8 @@ std::unique_ptr<base::DictionaryValue> ProtocolHandler::Encode() const {
auto d = std::make_unique<base::DictionaryValue>(); auto d = std::make_unique<base::DictionaryValue>();
d->SetString("protocol", protocol_); d->SetString("protocol", protocol_);
d->SetString("url", url_.spec()); d->SetString("url", url_.spec());
d->Set("last_modified", d->SetKey("last_modified", base::CreateTimeDeltaValue(
base::CreateTimeDeltaValue(last_modified_.ToDeltaSinceWindowsEpoch())); last_modified_.ToDeltaSinceWindowsEpoch()));
return d; return d;
} }
......
...@@ -98,8 +98,7 @@ class OriginData { ...@@ -98,8 +98,7 @@ class OriginData {
base::Value ToDictValue() const { base::Value ToDictValue() const {
base::Value dict(base::Value::Type::DICTIONARY); base::Value dict(base::Value::Type::DICTIONARY);
dict.SetKey(kOriginId, base::Value::FromUniquePtrValue( dict.SetKey(kOriginId, base::CreateUnguessableTokenValue(origin_id_));
base::CreateUnguessableTokenValue(origin_id_)));
dict.SetKey(kCreationTime, base::Value(provision_time_.ToDoubleT())); dict.SetKey(kCreationTime, base::Value(provision_time_.ToDoubleT()));
return dict; return dict;
......
...@@ -424,7 +424,8 @@ void PrefService::SetString(const std::string& path, const std::string& value) { ...@@ -424,7 +424,8 @@ void PrefService::SetString(const std::string& path, const std::string& value) {
void PrefService::SetFilePath(const std::string& path, void PrefService::SetFilePath(const std::string& path,
const base::FilePath& value) { const base::FilePath& value) {
SetUserPrefValue(path, base::CreateFilePathValue(value)); SetUserPrefValue(
path, base::Value::ToUniquePtrValue(base::CreateFilePathValue(value)));
} }
void PrefService::SetInt64(const std::string& path, int64_t value) { void PrefService::SetInt64(const std::string& path, int64_t value) {
......
...@@ -96,8 +96,8 @@ std::unique_ptr<base::ListValue> AlarmsToValue( ...@@ -96,8 +96,8 @@ std::unique_ptr<base::ListValue> AlarmsToValue(
for (size_t i = 0; i < alarms.size(); ++i) { for (size_t i = 0; i < alarms.size(); ++i) {
std::unique_ptr<base::DictionaryValue> alarm = std::unique_ptr<base::DictionaryValue> alarm =
alarms[i]->js_alarm->ToValue(); alarms[i]->js_alarm->ToValue();
alarm->Set(kAlarmGranularity, alarm->SetKey(kAlarmGranularity,
base::CreateTimeDeltaValue(alarms[i]->granularity)); base::CreateTimeDeltaValue(alarms[i]->granularity));
list->Append(std::move(alarm)); list->Append(std::move(alarm));
} }
return list; return list;
......
...@@ -226,8 +226,9 @@ base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, ...@@ -226,8 +226,9 @@ base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
void SetLastChooseEntryDirectory(ExtensionPrefs* prefs, void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
const std::string& extension_id, const std::string& extension_id,
const base::FilePath& path) { const base::FilePath& path) {
prefs->UpdateExtensionPref(extension_id, kLastChooseEntryDirectory, prefs->UpdateExtensionPref(
base::CreateFilePathValue(path)); extension_id, kLastChooseEntryDirectory,
base::Value::ToUniquePtrValue(base::CreateFilePathValue(path)));
} }
} // namespace file_system_api } // namespace file_system_api
......
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