refactor: remove deprecated GetAs methods (#13425)

* refactor: remove deprecated GetAs methods

* restructure URLRequestAsyncAsarJob on win

* fix: add string conversion header
This commit is contained in:
Shelley Vohr 2018-06-27 14:52:48 -07:00 committed by GitHub
parent fa0704665f
commit 003a92e099
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 20 deletions

View file

@ -336,10 +336,9 @@ void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
for (base::DictionaryValue::Iterator iter(options); !iter.IsAtEnd(); for (base::DictionaryValue::Iterator iter(options); !iter.IsAtEnd();
iter.Advance()) { iter.Advance()) {
std::string key = iter.key(); std::string key = iter.key();
std::string value; if (!key.empty() && iter.value().is_string()) {
if (!key.empty() && iter.value().GetAsString(&value)) {
key[0] = base::ToUpperASCII(key[0]); key[0] = base::ToUpperASCII(key[0]);
about_panel_options_.SetString(key, value); about_panel_options_.SetString(key, iter.value().GetString());
} }
} }
} }

View file

@ -183,9 +183,10 @@ void ReadFromResponseObject(const base::DictionaryValue& response,
headers->Clear(); headers->Clear();
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
it.Advance()) { it.Advance()) {
std::string value; if (it.value().is_string()) {
if (it.value().GetAsString(&value)) std::string value = it.value().GetString();
headers->SetHeader(it.key(), value); headers->SetHeader(it.key(), value);
}
} }
} }
} }

View file

@ -62,8 +62,8 @@ bool IsErrorOptions(base::Value* value, int* error) {
if (dict->GetInteger("error", error)) if (dict->GetInteger("error", error))
return true; return true;
} else if (value->is_int()) { } else if (value->is_int()) {
if (value->GetAsInteger(error)) *error = value->GetInt();
return true; return true;
} }
return false; return false;
} }

View file

@ -7,6 +7,7 @@
#include <string> #include <string>
#include "atom/common/atom_constants.h" #include "atom/common/atom_constants.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
namespace atom { namespace atom {
@ -17,12 +18,13 @@ URLRequestAsyncAsarJob::URLRequestAsyncAsarJob(
: JsAsker<asar::URLRequestAsarJob>(request, network_delegate) {} : JsAsker<asar::URLRequestAsarJob>(request, network_delegate) {}
void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr<base::Value> options) { void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr<base::Value> options) {
base::FilePath::StringType file_path; std::string file_path;
if (options->is_dict()) { if (options->is_dict()) {
static_cast<base::DictionaryValue*>(options.get()) auto path_value = options->FindKeyOfType("path", base::Value::Type::STRING);
->GetString("path", &file_path); if (path_value)
file_path = path_value->GetString();
} else if (options->is_string()) { } else if (options->is_string()) {
options->GetAsString(&file_path); file_path = options->GetString();
} }
if (file_path.empty()) { if (file_path.empty()) {
@ -33,7 +35,11 @@ void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr<base::Value> options) {
base::CreateSequencedTaskRunnerWithTraits( base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}),
#if defined(OS_WIN)
base::FilePath(base::UTF8ToWide(file_path)));
#else
base::FilePath(file_path)); base::FilePath(file_path));
#endif
asar::URLRequestAsarJob::Start(); asar::URLRequestAsarJob::Start();
} }
} }

View file

@ -25,7 +25,7 @@ void URLRequestStringJob::StartAsync(std::unique_ptr<base::Value> options) {
dict->GetString("charset", &charset_); dict->GetString("charset", &charset_);
dict->GetString("data", &data_); dict->GetString("data", &data_);
} else if (options->is_string()) { } else if (options->is_string()) {
options->GetAsString(&data_); data_ = options->GetString();
} }
net::URLRequestSimpleJob::Start(); net::URLRequestSimpleJob::Start();
} }

View file

@ -163,26 +163,22 @@ v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
return v8::Null(isolate); return v8::Null(isolate);
case base::Value::Type::BOOLEAN: { case base::Value::Type::BOOLEAN: {
bool val = false; bool val = value->GetBool();
value->GetAsBoolean(&val);
return v8::Boolean::New(isolate, val); return v8::Boolean::New(isolate, val);
} }
case base::Value::Type::INTEGER: { case base::Value::Type::INTEGER: {
int val = 0; int val = value->GetInt();
value->GetAsInteger(&val);
return v8::Integer::New(isolate, val); return v8::Integer::New(isolate, val);
} }
case base::Value::Type::DOUBLE: { case base::Value::Type::DOUBLE: {
double val = 0.0; double val = value->GetDouble();
value->GetAsDouble(&val);
return v8::Number::New(isolate, val); return v8::Number::New(isolate, val);
} }
case base::Value::Type::STRING: { case base::Value::Type::STRING: {
std::string val; std::string val = value->GetString();
value->GetAsString(&val);
return v8::String::NewFromUtf8(isolate, val.c_str(), return v8::String::NewFromUtf8(isolate, val.c_str(),
v8::String::kNormalString, val.length()); v8::String::kNormalString, val.length());
} }