Skip to content

Commit

Permalink
Code health: replace usages of Value::GetAsString in chrome/browser/d…
Browse files Browse the repository at this point in the history
…ownload

Bug: chromium:1187007
Change-Id: Id99230015b6c814dac78e89f2f0aa82d35850493
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3013777
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#901721}
  • Loading branch information
OrKoN authored and Chromium LUCI CQ committed Jul 15, 2021
1 parent aaf00d7 commit 7761717
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void DefaultDownloadDirPolicyHandler::ApplyPolicySettingsWithParameters(
const policy::PolicyHandlerParameters& parameters,
PrefValueMap* prefs) {
const base::Value* value = policies.GetValue(policy_name());
std::string str_value;
if (!value || !value->GetAsString(&str_value))
if (!value || !value->is_string())
return;
std::string str_value = value->GetString();
base::FilePath::StringType string_value =
#if defined(OS_WIN)
base::UTF8ToWide(str_value);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/download/download_dir_policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void DownloadDirPolicyHandler::ApplyPolicySettingsWithParameters(
const policy::PolicyHandlerParameters& parameters,
PrefValueMap* prefs) {
const base::Value* value = policies.GetValue(policy_name());
std::string str_value;
if (!value || !value->GetAsString(&str_value))
if (!value || !value->is_string())
return;
std::string str_value = value->GetString();
base::FilePath::StringType string_value =
#if defined(OS_WIN)
base::UTF8ToWide(str_value);
Expand Down
10 changes: 8 additions & 2 deletions chrome/browser/download/download_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ bool GetAs(const base::Value& in, double* out) {
return false;
}
template<> bool GetAs(const base::Value& in, std::string* out) {
return in.GetAsString(out);
auto is_string = in.is_string();
if (is_string)
*out = in.GetString();
return is_string;
}
template <>
bool GetAs(const base::Value& in, std::u16string* out) {
return in.GetAsString(out);
auto is_string = in.is_string();
if (is_string)
*out = base::UTF8ToUTF16(in.GetString());
return is_string;
}
template <>
bool GetAs(const base::Value& in, std::vector<std::u16string>* out) {
Expand Down

0 comments on commit 7761717

Please sign in to comment.