chore: remove discouraged base::Passed (#22871)

Closes #12640.

Remove discouraged base::Passed from Bind calls.
This commit is contained in:
Shelley Vohr 2020-04-13 13:52:07 -07:00 committed by GitHub
parent 658f8d0abb
commit 714d6c536f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 43 deletions

View file

@ -497,14 +497,19 @@ void OnClientCertificateSelected(
}
#if defined(USE_NSS_CERTS)
int ImportIntoCertStore(CertificateManagerModel* model,
const base::DictionaryValue& options) {
int ImportIntoCertStore(CertificateManagerModel* model, base::Value options) {
std::string file_data, cert_path;
base::string16 password;
net::ScopedCERTCertificateList imported_certs;
int rv = -1;
options.GetString("certificate", &cert_path);
options.GetString("password", &password);
std::string* cert_path_ptr = options.FindStringKey("certificate");
if (cert_path_ptr)
cert_path = *cert_path_ptr;
std::string* pwd = options.FindStringKey("password");
if (pwd)
password = base::UTF8ToUTF16(*pwd);
if (!cert_path.empty()) {
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
@ -1071,31 +1076,36 @@ Browser::LoginItemSettings App::GetLoginItemSettings(
}
#if defined(USE_NSS_CERTS)
void App::ImportCertificate(const base::DictionaryValue& options,
net::CompletionRepeatingCallback callback) {
auto browser_context = ElectronBrowserContext::From("", false);
if (!certificate_manager_model_) {
auto copy = base::DictionaryValue::From(
base::Value::ToUniquePtrValue(options.Clone()));
CertificateManagerModel::Create(
browser_context.get(),
base::BindRepeating(&App::OnCertificateManagerModelCreated,
base::Unretained(this), base::Passed(&copy),
callback));
void App::ImportCertificate(gin_helper::ErrorThrower thrower,
base::Value options,
net::CompletionOnceCallback callback) {
if (!options.is_dict()) {
thrower.ThrowTypeError("Expected options to be an object");
return;
}
int rv = ImportIntoCertStore(certificate_manager_model_.get(), options);
auto browser_context = ElectronBrowserContext::From("", false);
if (!certificate_manager_model_) {
CertificateManagerModel::Create(
browser_context.get(),
base::BindOnce(&App::OnCertificateManagerModelCreated,
base::Unretained(this), std::move(options),
std::move(callback)));
return;
}
int rv =
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
std::move(callback).Run(rv);
}
void App::OnCertificateManagerModelCreated(
std::unique_ptr<base::DictionaryValue> options,
base::Value options,
net::CompletionOnceCallback callback,
std::unique_ptr<CertificateManagerModel> model) {
certificate_manager_model_ = std::move(model);
int rv =
ImportIntoCertStore(certificate_manager_model_.get(), *(options.get()));
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
std::move(callback).Run(rv);
}
#endif