Skip to content

Commit 714d6c5

Browse files
authored
chore: remove discouraged base::Passed (electron#22871)
Closes electron#12640. Remove discouraged base::Passed from Bind calls.
1 parent 658f8d0 commit 714d6c5

File tree

5 files changed

+56
-39
lines changed

5 files changed

+56
-39
lines changed

chromium_src/chrome/browser/certificate_manager_model.cc

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
6969

7070
// static
7171
void CertificateManagerModel::Create(content::BrowserContext* browser_context,
72-
const CreationCallback& callback) {
72+
CreationCallback callback) {
7373
DCHECK_CURRENTLY_ON(BrowserThread::UI);
74-
base::PostTask(
75-
FROM_HERE, {BrowserThread::IO},
76-
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
77-
browser_context->GetResourceContext(), callback));
74+
base::PostTask(FROM_HERE, {BrowserThread::IO},
75+
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
76+
browser_context->GetResourceContext(),
77+
std::move(callback)));
7878
}
7979

8080
CertificateManagerModel::CertificateManagerModel(
@@ -129,35 +129,42 @@ bool CertificateManagerModel::Delete(CERTCertificate* cert) {
129129
void CertificateManagerModel::DidGetCertDBOnUIThread(
130130
net::NSSCertDatabase* cert_db,
131131
bool is_user_db_available,
132-
const CreationCallback& callback) {
132+
CreationCallback callback) {
133133
DCHECK_CURRENTLY_ON(BrowserThread::UI);
134134

135135
std::unique_ptr<CertificateManagerModel> model(
136136
new CertificateManagerModel(cert_db, is_user_db_available));
137-
callback.Run(std::move(model));
137+
std::move(callback).Run(std::move(model));
138138
}
139139

140140
// static
141141
void CertificateManagerModel::DidGetCertDBOnIOThread(
142-
const CreationCallback& callback,
142+
CreationCallback callback,
143143
net::NSSCertDatabase* cert_db) {
144144
DCHECK_CURRENTLY_ON(BrowserThread::IO);
145145

146146
bool is_user_db_available = !!cert_db->GetPublicSlot();
147147
base::PostTask(
148148
FROM_HERE, {BrowserThread::UI},
149149
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnUIThread, cert_db,
150-
is_user_db_available, callback));
150+
is_user_db_available, std::move(callback)));
151151
}
152152

153153
// static
154154
void CertificateManagerModel::GetCertDBOnIOThread(
155155
content::ResourceContext* context,
156-
const CreationCallback& callback) {
156+
CreationCallback callback) {
157157
DCHECK_CURRENTLY_ON(BrowserThread::IO);
158-
net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
159-
context, base::BindOnce(&CertificateManagerModel::DidGetCertDBOnIOThread,
160-
callback));
158+
159+
auto did_get_cert_db_callback = base::AdaptCallbackForRepeating(
160+
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnIOThread,
161+
std::move(callback)));
162+
163+
net::NSSCertDatabase* cert_db =
164+
GetNSSCertDatabaseForResourceContext(context, did_get_cert_db_callback);
165+
166+
// If the NSS database was already available, |cert_db| is non-null and
167+
// |did_get_cert_db_callback| has not been called. Call it explicitly.
161168
if (cert_db)
162-
DidGetCertDBOnIOThread(callback, cert_db);
169+
did_get_cert_db_callback.Run(cert_db);
163170
}

chromium_src/chrome/browser/certificate_manager_model.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class ResourceContext;
2424
// manager dialog, and processes changes from the view.
2525
class CertificateManagerModel {
2626
public:
27-
typedef base::Callback<void(std::unique_ptr<CertificateManagerModel>)>
28-
CreationCallback;
27+
using CreationCallback =
28+
base::OnceCallback<void(std::unique_ptr<CertificateManagerModel>)>;
2929

3030
// Creates a CertificateManagerModel. The model will be passed to the callback
3131
// when it is ready. The caller must ensure the model does not outlive the
3232
// |browser_context|.
3333
static void Create(content::BrowserContext* browser_context,
34-
const CreationCallback& callback);
34+
CreationCallback callback);
3535

3636
~CertificateManagerModel();
3737

@@ -100,11 +100,11 @@ class CertificateManagerModel {
100100
// file for details.
101101
static void DidGetCertDBOnUIThread(net::NSSCertDatabase* cert_db,
102102
bool is_user_db_available,
103-
const CreationCallback& callback);
104-
static void DidGetCertDBOnIOThread(const CreationCallback& callback,
103+
CreationCallback callback);
104+
static void DidGetCertDBOnIOThread(CreationCallback callback,
105105
net::NSSCertDatabase* cert_db);
106106
static void GetCertDBOnIOThread(content::ResourceContext* context,
107-
const CreationCallback& callback);
107+
CreationCallback callback);
108108

109109
net::NSSCertDatabase* cert_db_;
110110
// Whether the certificate database has a public slot associated with the

shell/browser/api/electron_api_app.cc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,19 @@ void OnClientCertificateSelected(
497497
}
498498

499499
#if defined(USE_NSS_CERTS)
500-
int ImportIntoCertStore(CertificateManagerModel* model,
501-
const base::DictionaryValue& options) {
500+
int ImportIntoCertStore(CertificateManagerModel* model, base::Value options) {
502501
std::string file_data, cert_path;
503502
base::string16 password;
504503
net::ScopedCERTCertificateList imported_certs;
505504
int rv = -1;
506-
options.GetString("certificate", &cert_path);
507-
options.GetString("password", &password);
505+
506+
std::string* cert_path_ptr = options.FindStringKey("certificate");
507+
if (cert_path_ptr)
508+
cert_path = *cert_path_ptr;
509+
510+
std::string* pwd = options.FindStringKey("password");
511+
if (pwd)
512+
password = base::UTF8ToUTF16(*pwd);
508513

509514
if (!cert_path.empty()) {
510515
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
@@ -1071,31 +1076,36 @@ Browser::LoginItemSettings App::GetLoginItemSettings(
10711076
}
10721077

10731078
#if defined(USE_NSS_CERTS)
1074-
void App::ImportCertificate(const base::DictionaryValue& options,
1075-
net::CompletionRepeatingCallback callback) {
1079+
void App::ImportCertificate(gin_helper::ErrorThrower thrower,
1080+
base::Value options,
1081+
net::CompletionOnceCallback callback) {
1082+
if (!options.is_dict()) {
1083+
thrower.ThrowTypeError("Expected options to be an object");
1084+
return;
1085+
}
1086+
10761087
auto browser_context = ElectronBrowserContext::From("", false);
10771088
if (!certificate_manager_model_) {
1078-
auto copy = base::DictionaryValue::From(
1079-
base::Value::ToUniquePtrValue(options.Clone()));
10801089
CertificateManagerModel::Create(
10811090
browser_context.get(),
1082-
base::BindRepeating(&App::OnCertificateManagerModelCreated,
1083-
base::Unretained(this), base::Passed(&copy),
1084-
callback));
1091+
base::BindOnce(&App::OnCertificateManagerModelCreated,
1092+
base::Unretained(this), std::move(options),
1093+
std::move(callback)));
10851094
return;
10861095
}
10871096

1088-
int rv = ImportIntoCertStore(certificate_manager_model_.get(), options);
1097+
int rv =
1098+
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
10891099
std::move(callback).Run(rv);
10901100
}
10911101

10921102
void App::OnCertificateManagerModelCreated(
1093-
std::unique_ptr<base::DictionaryValue> options,
1103+
base::Value options,
10941104
net::CompletionOnceCallback callback,
10951105
std::unique_ptr<CertificateManagerModel> model) {
10961106
certificate_manager_model_ = std::move(model);
10971107
int rv =
1098-
ImportIntoCertStore(certificate_manager_model_.get(), *(options.get()));
1108+
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
10991109
std::move(callback).Run(rv);
11001110
}
11011111
#endif

shell/browser/api/electron_api_app.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class App : public ElectronBrowserClient::Delegate,
6262

6363
#if defined(USE_NSS_CERTS)
6464
void OnCertificateManagerModelCreated(
65-
std::unique_ptr<base::DictionaryValue> options,
65+
base::Value options,
6666
net::CompletionOnceCallback callback,
6767
std::unique_ptr<CertificateManagerModel> model);
6868
#endif
@@ -184,8 +184,9 @@ class App : public ElectronBrowserClient::Delegate,
184184
bool enabled);
185185
Browser::LoginItemSettings GetLoginItemSettings(gin_helper::Arguments* args);
186186
#if defined(USE_NSS_CERTS)
187-
void ImportCertificate(const base::DictionaryValue& options,
188-
net::CompletionRepeatingCallback callback);
187+
void ImportCertificate(gin_helper::ErrorThrower thrower,
188+
base::Value options,
189+
net::CompletionOnceCallback callback);
189190
#endif
190191
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
191192
gin_helper::Arguments* args);

shell/browser/electron_javascript_dialog_manager.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog(
107107
electron::ShowMessageBox(
108108
settings,
109109
base::BindOnce(&ElectronJavaScriptDialogManager::OnMessageBoxCallback,
110-
base::Unretained(this), base::Passed(std::move(callback)),
111-
origin));
110+
base::Unretained(this), std::move(callback), origin));
112111
}
113112

114113
void ElectronJavaScriptDialogManager::RunBeforeUnloadDialog(

0 commit comments

Comments
 (0)