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
|
||||
void CertificateManagerModel::Create(content::BrowserContext* browser_context,
|
||||
const CreationCallback& callback) {
|
||||
CreationCallback callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
|
||||
browser_context->GetResourceContext(), callback));
|
||||
base::PostTask(FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
|
||||
browser_context->GetResourceContext(),
|
||||
std::move(callback)));
|
||||
}
|
||||
|
||||
CertificateManagerModel::CertificateManagerModel(
|
||||
|
@ -129,17 +129,17 @@ bool CertificateManagerModel::Delete(CERTCertificate* cert) {
|
|||
void CertificateManagerModel::DidGetCertDBOnUIThread(
|
||||
net::NSSCertDatabase* cert_db,
|
||||
bool is_user_db_available,
|
||||
const CreationCallback& callback) {
|
||||
CreationCallback callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
std::unique_ptr<CertificateManagerModel> model(
|
||||
new CertificateManagerModel(cert_db, is_user_db_available));
|
||||
callback.Run(std::move(model));
|
||||
std::move(callback).Run(std::move(model));
|
||||
}
|
||||
|
||||
// static
|
||||
void CertificateManagerModel::DidGetCertDBOnIOThread(
|
||||
const CreationCallback& callback,
|
||||
CreationCallback callback,
|
||||
net::NSSCertDatabase* cert_db) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
|
@ -147,17 +147,24 @@ void CertificateManagerModel::DidGetCertDBOnIOThread(
|
|||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::UI},
|
||||
base::BindOnce(&CertificateManagerModel::DidGetCertDBOnUIThread, cert_db,
|
||||
is_user_db_available, callback));
|
||||
is_user_db_available, std::move(callback)));
|
||||
}
|
||||
|
||||
// static
|
||||
void CertificateManagerModel::GetCertDBOnIOThread(
|
||||
content::ResourceContext* context,
|
||||
const CreationCallback& callback) {
|
||||
CreationCallback callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
|
||||
context, base::BindOnce(&CertificateManagerModel::DidGetCertDBOnIOThread,
|
||||
callback));
|
||||
|
||||
auto did_get_cert_db_callback = base::AdaptCallbackForRepeating(
|
||||
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)
|
||||
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.
|
||||
class CertificateManagerModel {
|
||||
public:
|
||||
typedef base::Callback<void(std::unique_ptr<CertificateManagerModel>)>
|
||||
CreationCallback;
|
||||
using CreationCallback =
|
||||
base::OnceCallback<void(std::unique_ptr<CertificateManagerModel>)>;
|
||||
|
||||
// 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
|
||||
// |browser_context|.
|
||||
static void Create(content::BrowserContext* browser_context,
|
||||
const CreationCallback& callback);
|
||||
CreationCallback callback);
|
||||
|
||||
~CertificateManagerModel();
|
||||
|
||||
|
@ -100,11 +100,11 @@ class CertificateManagerModel {
|
|||
// file for details.
|
||||
static void DidGetCertDBOnUIThread(net::NSSCertDatabase* cert_db,
|
||||
bool is_user_db_available,
|
||||
const CreationCallback& callback);
|
||||
static void DidGetCertDBOnIOThread(const CreationCallback& callback,
|
||||
CreationCallback callback);
|
||||
static void DidGetCertDBOnIOThread(CreationCallback callback,
|
||||
net::NSSCertDatabase* cert_db);
|
||||
static void GetCertDBOnIOThread(content::ResourceContext* context,
|
||||
const CreationCallback& callback);
|
||||
CreationCallback callback);
|
||||
|
||||
net::NSSCertDatabase* cert_db_;
|
||||
// Whether the certificate database has a public slot associated with the
|
||||
|
|
|
@ -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(©),
|
||||
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
|
||||
|
|
|
@ -62,7 +62,7 @@ class App : public ElectronBrowserClient::Delegate,
|
|||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
void OnCertificateManagerModelCreated(
|
||||
std::unique_ptr<base::DictionaryValue> options,
|
||||
base::Value options,
|
||||
net::CompletionOnceCallback callback,
|
||||
std::unique_ptr<CertificateManagerModel> model);
|
||||
#endif
|
||||
|
@ -184,8 +184,9 @@ class App : public ElectronBrowserClient::Delegate,
|
|||
bool enabled);
|
||||
Browser::LoginItemSettings GetLoginItemSettings(gin_helper::Arguments* args);
|
||||
#if defined(USE_NSS_CERTS)
|
||||
void ImportCertificate(const base::DictionaryValue& options,
|
||||
net::CompletionRepeatingCallback callback);
|
||||
void ImportCertificate(gin_helper::ErrorThrower thrower,
|
||||
base::Value options,
|
||||
net::CompletionOnceCallback callback);
|
||||
#endif
|
||||
v8::Local<v8::Promise> GetFileIcon(const base::FilePath& path,
|
||||
gin_helper::Arguments* args);
|
||||
|
|
|
@ -107,8 +107,7 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog(
|
|||
electron::ShowMessageBox(
|
||||
settings,
|
||||
base::BindOnce(&ElectronJavaScriptDialogManager::OnMessageBoxCallback,
|
||||
base::Unretained(this), base::Passed(std::move(callback)),
|
||||
origin));
|
||||
base::Unretained(this), std::move(callback), origin));
|
||||
}
|
||||
|
||||
void ElectronJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||
|
|
Loading…
Reference in a new issue