Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove deprecated BrowserContext::ResourceContext #41246

Merged
9 changes: 3 additions & 6 deletions shell/browser/api/electron_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,10 @@ void App::ImportCertificate(gin_helper::ErrorThrower thrower,
return;
}

auto* browser_context = ElectronBrowserContext::From("", false);
if (!certificate_manager_model_) {
CertificateManagerModel::Create(
browser_context,
base::BindOnce(&App::OnCertificateManagerModelCreated,
base::Unretained(this), std::move(options),
std::move(callback)));
CertificateManagerModel::Create(base::BindOnce(
&App::OnCertificateManagerModelCreated, base::Unretained(this),
std::move(options), std::move(callback)));
return;
}

Expand Down
21 changes: 7 additions & 14 deletions shell/browser/certificate_manager_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include <utility>

#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_context.h"
#include "base/memory/ptr_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
Expand All @@ -25,8 +23,7 @@ namespace {

net::NSSCertDatabase* g_nss_cert_database = nullptr;

net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
content::ResourceContext* context,
net::NSSCertDatabase* GetNSSCertDatabase(
base::OnceCallback<void(net::NSSCertDatabase*)> callback) {
// This initialization is not thread safe. This CHECK ensures that this code
// is only run on a single thread.
Expand Down Expand Up @@ -57,7 +54,7 @@ net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
// \--------------------------------------v
// CertificateManagerModel::GetCertDBOnIOThread
// |
// GetNSSCertDatabaseForResourceContext
// GetNSSCertDatabase
// |
// CertificateManagerModel::DidGetCertDBOnIOThread
// v--------------------------------------/
Expand All @@ -68,12 +65,10 @@ net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
// callback

// static
void CertificateManagerModel::Create(content::BrowserContext* browser_context,
CreationCallback callback) {
void CertificateManagerModel::Create(CreationCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&CertificateManagerModel::GetCertDBOnIOThread,
browser_context->GetResourceContext(),
std::move(callback)));
}

Expand Down Expand Up @@ -151,16 +146,14 @@ void CertificateManagerModel::DidGetCertDBOnIOThread(
}

// static
void CertificateManagerModel::GetCertDBOnIOThread(
content::ResourceContext* context,
CreationCallback callback) {
void CertificateManagerModel::GetCertDBOnIOThread(CreationCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

auto split_callback = base::SplitOnceCallback(base::BindOnce(
&CertificateManagerModel::DidGetCertDBOnIOThread, std::move(callback)));

net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
context, std::move(split_callback.first));
net::NSSCertDatabase* cert_db =
GetNSSCertDatabase(std::move(split_callback.first));

// 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.
Expand Down
14 changes: 3 additions & 11 deletions shell/browser/certificate_manager_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
#include "base/memory/ref_counted.h"
#include "net/cert/nss_cert_database.h"

namespace content {
class BrowserContext;
class ResourceContext;
} // namespace content

// CertificateManagerModel provides the data to be displayed in the certificate
// manager dialog, and processes changes from the view.
class CertificateManagerModel {
Expand All @@ -26,10 +21,8 @@ class CertificateManagerModel {
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,
CreationCallback callback);
// when it is ready.
static void Create(CreationCallback callback);

// disable copy
CertificateManagerModel(const CertificateManagerModel&) = delete;
Expand Down Expand Up @@ -105,8 +98,7 @@ class CertificateManagerModel {
CreationCallback callback);
static void DidGetCertDBOnIOThread(CreationCallback callback,
net::NSSCertDatabase* cert_db);
static void GetCertDBOnIOThread(content::ResourceContext* context,
CreationCallback callback);
static void GetCertDBOnIOThread(CreationCallback callback);

raw_ptr<net::NSSCertDatabase> cert_db_;
// Whether the certificate database has a public slot associated with the
Expand Down