chore: remove discouraged base::Passed (#22871)
Closes #12640. Remove discouraged base::Passed from Bind calls.
This commit is contained in:
parent
658f8d0abb
commit
714d6c536f
5 changed files with 60 additions and 43 deletions
|
@ -69,12 +69,12 @@ net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void CertificateManagerModel::Create(content::BrowserContext* browser_context,
|
void CertificateManagerModel::Create(content::BrowserContext* browser_context,
|
||||||
const CreationCallback& callback) {
|
CreationCallback callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
base::PostTask(
|
base::PostTask(FROM_HERE, {BrowserThread::IO},
|
||||||
FROM_HERE, {BrowserThread::IO},
|
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
|
||||||
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
|
browser_context->GetResourceContext(),
|
||||||
browser_context->GetResourceContext(), callback));
|
std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificateManagerModel::CertificateManagerModel(
|
CertificateManagerModel::CertificateManagerModel(
|
||||||
|
@ -129,17 +129,17 @@ bool CertificateManagerModel::Delete(CERTCertificate* cert) {
|
||||||
void CertificateManagerModel::DidGetCertDBOnUIThread(
|
void CertificateManagerModel::DidGetCertDBOnUIThread(
|
||||||
net::NSSCertDatabase* cert_db,
|
net::NSSCertDatabase* cert_db,
|
||||||
bool is_user_db_available,
|
bool is_user_db_available,
|
||||||
const CreationCallback& callback) {
|
CreationCallback callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
std::unique_ptr<CertificateManagerModel> model(
|
std::unique_ptr<CertificateManagerModel> model(
|
||||||
new CertificateManagerModel(cert_db, is_user_db_available));
|
new CertificateManagerModel(cert_db, is_user_db_available));
|
||||||
callback.Run(std::move(model));
|
std::move(callback).Run(std::move(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void CertificateManagerModel::DidGetCertDBOnIOThread(
|
void CertificateManagerModel::DidGetCertDBOnIOThread(
|
||||||
const CreationCallback& callback,
|
CreationCallback callback,
|
||||||
net::NSSCertDatabase* cert_db) {
|
net::NSSCertDatabase* cert_db) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
|
|
||||||
|
@ -147,17 +147,24 @@ void CertificateManagerModel::DidGetCertDBOnIOThread(
|
||||||
base::PostTask(
|
base::PostTask(
|
||||||
FROM_HERE, {BrowserThread::UI},
|
FROM_HERE, {BrowserThread::UI},
|
||||||
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnUIThread, cert_db,
|
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnUIThread, cert_db,
|
||||||
is_user_db_available, callback));
|
is_user_db_available, std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void CertificateManagerModel::GetCertDBOnIOThread(
|
void CertificateManagerModel::GetCertDBOnIOThread(
|
||||||
content::ResourceContext* context,
|
content::ResourceContext* context,
|
||||||
const CreationCallback& callback) {
|
CreationCallback callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
|
|
||||||
context, base::BindOnce(&CertificateManagerModel::DidGetCertDBOnIOThread,
|
auto did_get_cert_db_callback = base::AdaptCallbackForRepeating(
|
||||||
callback));
|
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnIOThread,
|
||||||
|
std::move(callback)));
|
||||||
|
|
||||||
|
net::NSSCertDatabase* cert_db =
|
||||||
|
GetNSSCertDatabaseForResourceContext(context, did_get_cert_db_callback);
|
||||||
|
|
||||||
|
// If the NSS database was already available, |cert_db| is non-null and
|
||||||
|
// |did_get_cert_db_callback| has not been called. Call it explicitly.
|
||||||
if (cert_db)
|
if (cert_db)
|
||||||
DidGetCertDBOnIOThread(callback, cert_db);
|
did_get_cert_db_callback.Run(cert_db);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,14 @@ class ResourceContext;
|
||||||
// manager dialog, and processes changes from the view.
|
// manager dialog, and processes changes from the view.
|
||||||
class CertificateManagerModel {
|
class CertificateManagerModel {
|
||||||
public:
|
public:
|
||||||
typedef base::Callback<void(std::unique_ptr<CertificateManagerModel>)>
|
using CreationCallback =
|
||||||
CreationCallback;
|
base::OnceCallback<void(std::unique_ptr<CertificateManagerModel>)>;
|
||||||
|
|
||||||
// Creates a CertificateManagerModel. The model will be passed to the callback
|
// Creates a CertificateManagerModel. The model will be passed to the callback
|
||||||
// when it is ready. The caller must ensure the model does not outlive the
|
// when it is ready. The caller must ensure the model does not outlive the
|
||||||
// |browser_context|.
|
// |browser_context|.
|
||||||
static void Create(content::BrowserContext* browser_context,
|
static void Create(content::BrowserContext* browser_context,
|
||||||
const CreationCallback& callback);
|
CreationCallback callback);
|
||||||
|
|
||||||
~CertificateManagerModel();
|
~CertificateManagerModel();
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ class CertificateManagerModel {
|
||||||
// file for details.
|
// file for details.
|
||||||
static void DidGetCertDBOnUIThread(net::NSSCertDatabase* cert_db,
|
static void DidGetCertDBOnUIThread(net::NSSCertDatabase* cert_db,
|
||||||
bool is_user_db_available,
|
bool is_user_db_available,
|
||||||
const CreationCallback& callback);
|
CreationCallback callback);
|
||||||
static void DidGetCertDBOnIOThread(const CreationCallback& callback,
|
static void DidGetCertDBOnIOThread(CreationCallback callback,
|
||||||
net::NSSCertDatabase* cert_db);
|
net::NSSCertDatabase* cert_db);
|
||||||
static void GetCertDBOnIOThread(content::ResourceContext* context,
|
static void GetCertDBOnIOThread(content::ResourceContext* context,
|
||||||
const CreationCallback& callback);
|
CreationCallback callback);
|
||||||
|
|
||||||
net::NSSCertDatabase* cert_db_;
|
net::NSSCertDatabase* cert_db_;
|
||||||
// Whether the certificate database has a public slot associated with the
|
// Whether the certificate database has a public slot associated with the
|
||||||
|
|
|
@ -497,14 +497,19 @@ void OnClientCertificateSelected(
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
int ImportIntoCertStore(CertificateManagerModel* model,
|
int ImportIntoCertStore(CertificateManagerModel* model, base::Value options) {
|
||||||
const base::DictionaryValue& options) {
|
|
||||||
std::string file_data, cert_path;
|
std::string file_data, cert_path;
|
||||||
base::string16 password;
|
base::string16 password;
|
||||||
net::ScopedCERTCertificateList imported_certs;
|
net::ScopedCERTCertificateList imported_certs;
|
||||||
int rv = -1;
|
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 (!cert_path.empty()) {
|
||||||
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
|
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
|
||||||
|
@ -1071,31 +1076,36 @@ Browser::LoginItemSettings App::GetLoginItemSettings(
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void App::ImportCertificate(const base::DictionaryValue& options,
|
void App::ImportCertificate(gin_helper::ErrorThrower thrower,
|
||||||
net::CompletionRepeatingCallback callback) {
|
base::Value options,
|
||||||
auto browser_context = ElectronBrowserContext::From("", false);
|
net::CompletionOnceCallback callback) {
|
||||||
if (!certificate_manager_model_) {
|
if (!options.is_dict()) {
|
||||||
auto copy = base::DictionaryValue::From(
|
thrower.ThrowTypeError("Expected options to be an object");
|
||||||
base::Value::ToUniquePtrValue(options.Clone()));
|
|
||||||
CertificateManagerModel::Create(
|
|
||||||
browser_context.get(),
|
|
||||||
base::BindRepeating(&App::OnCertificateManagerModelCreated,
|
|
||||||
base::Unretained(this), base::Passed(©),
|
|
||||||
callback));
|
|
||||||
return;
|
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);
|
std::move(callback).Run(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::OnCertificateManagerModelCreated(
|
void App::OnCertificateManagerModelCreated(
|
||||||
std::unique_ptr<base::DictionaryValue> options,
|
base::Value options,
|
||||||
net::CompletionOnceCallback callback,
|
net::CompletionOnceCallback callback,
|
||||||
std::unique_ptr<CertificateManagerModel> model) {
|
std::unique_ptr<CertificateManagerModel> model) {
|
||||||
certificate_manager_model_ = std::move(model);
|
certificate_manager_model_ = std::move(model);
|
||||||
int rv =
|
int rv =
|
||||||
ImportIntoCertStore(certificate_manager_model_.get(), *(options.get()));
|
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
|
||||||
std::move(callback).Run(rv);
|
std::move(callback).Run(rv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,7 +62,7 @@ class App : public ElectronBrowserClient::Delegate,
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void OnCertificateManagerModelCreated(
|
void OnCertificateManagerModelCreated(
|
||||||
std::unique_ptr<base::DictionaryValue> options,
|
base::Value options,
|
||||||
net::CompletionOnceCallback callback,
|
net::CompletionOnceCallback callback,
|
||||||
std::unique_ptr<CertificateManagerModel> model);
|
std::unique_ptr<CertificateManagerModel> model);
|
||||||
#endif
|
#endif
|
||||||
|
@ -184,8 +184,9 @@ class App : public ElectronBrowserClient::Delegate,
|
||||||
bool enabled);
|
bool enabled);
|
||||||
Browser::LoginItemSettings GetLoginItemSettings(gin_helper::Arguments* args);
|
Browser::LoginItemSettings GetLoginItemSettings(gin_helper::Arguments* args);
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
void ImportCertificate(const base::DictionaryValue& options,
|
void ImportCertificate(gin_helper::ErrorThrower thrower,
|
||||||
net::CompletionRepeatingCallback callback);
|
base::Value options,
|
||||||
|
net::CompletionOnceCallback callback);
|
||||||
#endif
|
#endif
|
||||||
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
||||||
gin_helper::Arguments* args);
|
gin_helper::Arguments* args);
|
||||||
|
|
|
@ -107,8 +107,7 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog(
|
||||||
electron::ShowMessageBox(
|
electron::ShowMessageBox(
|
||||||
settings,
|
settings,
|
||||||
base::BindOnce(&ElectronJavaScriptDialogManager::OnMessageBoxCallback,
|
base::BindOnce(&ElectronJavaScriptDialogManager::OnMessageBoxCallback,
|
||||||
base::Unretained(this), base::Passed(std::move(callback)),
|
base::Unretained(this), std::move(callback), origin));
|
||||||
origin));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronJavaScriptDialogManager::RunBeforeUnloadDialog(
|
void ElectronJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||||
|
|
Loading…
Reference in a new issue