Commit 93eb72ec authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

Convert base::Callback and base::Closure to Once/Repeating in //chrome/browser/net/

This CL converts base::Callback and base::Closure to Once/Repeating
in //chrome/browser/net/. After this CL, there should be no
base::Callback, base::Closure and base::Bind in this directory.

Bug: 1007635
Change-Id: If66dbd7d611c448456e6b40dcd033f9c68ed45c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2306292Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#790676}
parent 85cf63e0
......@@ -51,8 +51,7 @@
using base::Bind;
using base::BindOnce;
using base::Callback;
using base::Closure;
using base::BindRepeating;
using base::FilePath;
using base::Unretained;
using content::BrowserThread;
......@@ -253,7 +252,8 @@ void DnsProbeBrowserTest::SetActiveBrowser(Browser* browser) {
monitored_tab_helper_ = NetErrorTabHelper::FromWebContents(
active_browser_->tab_strip_model()->GetActiveWebContents());
monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing(
Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this)));
BindRepeating(&DnsProbeBrowserTest::OnDnsProbeStatusSent,
Unretained(this)));
}
void DnsProbeBrowserTest::SetFakeHostResolverResults(
......
......@@ -40,7 +40,7 @@ class NetErrorDiagnosticsDialog : public ui::BaseShellDialogImpl {
// NetErrorDiagnosticsDialog implementation.
void Show(content::WebContents* web_contents,
const std::string& failed_url,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(!callback.is_null());
HWND parent =
......@@ -57,7 +57,8 @@ class NetErrorDiagnosticsDialog : public ui::BaseShellDialogImpl {
base::BindOnce(&NetErrorDiagnosticsDialog::ShowDialogOnPrivateThread,
base::Unretained(this), parent, failed_url),
base::BindOnce(&NetErrorDiagnosticsDialog::DiagnosticsDone,
base::Unretained(this), std::move(run_state), callback));
base::Unretained(this), std::move(run_state),
std::move(callback)));
}
private:
......@@ -73,9 +74,9 @@ class NetErrorDiagnosticsDialog : public ui::BaseShellDialogImpl {
}
void DiagnosticsDone(std::unique_ptr<RunState> run_state,
const base::Closure& callback) {
base::OnceClosure callback) {
EndRun(std::move(run_state));
callback.Run();
std::move(callback).Run();
}
DISALLOW_COPY_AND_ASSIGN(NetErrorDiagnosticsDialog);
......@@ -98,5 +99,5 @@ void ShowNetworkDiagnosticsDialog(content::WebContents* web_contents,
NetErrorDiagnosticsDialog* dialog = new NetErrorDiagnosticsDialog();
dialog->Show(
web_contents, failed_url,
base::Bind(&base::DeletePointer<NetErrorDiagnosticsDialog>, dialog));
base::BindOnce(&base::DeletePointer<NetErrorDiagnosticsDialog>, dialog));
}
......@@ -45,7 +45,7 @@ class NetErrorTabHelper
TESTING_FORCE_ENABLED
};
typedef base::Callback<void(error_page::DnsProbeStatus)>
typedef base::RepeatingCallback<void(error_page::DnsProbeStatus)>
DnsProbeStatusSnoopCallback;
~NetErrorTabHelper() override;
......
......@@ -1771,7 +1771,7 @@ class NetworkContextConfigurationHttpPacBrowserTest
~NetworkContextConfigurationHttpPacBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
pac_test_server_.RegisterRequestHandler(base::Bind(
pac_test_server_.RegisterRequestHandler(base::BindRepeating(
&NetworkContextConfigurationHttpPacBrowserTest::HandlePacRequest,
GetPacScript()));
EXPECT_TRUE(pac_test_server_.Start());
......
......@@ -20,25 +20,26 @@ namespace {
// Relays callback to the right message loop.
void DidGetCertDBOnIOThread(
const scoped_refptr<base::SequencedTaskRunner>& response_task_runner,
const base::Callback<void(net::NSSCertDatabase*)>& callback,
base::OnceCallback<void(net::NSSCertDatabase*)> callback,
net::NSSCertDatabase* cert_db) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
response_task_runner->PostTask(FROM_HERE, base::BindOnce(callback, cert_db));
response_task_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), cert_db));
}
// Gets NSSCertDatabase for the resource context.
void GetCertDBOnIOThread(
content::ResourceContext* context,
const scoped_refptr<base::SequencedTaskRunner>& response_task_runner,
const base::Callback<void(net::NSSCertDatabase*)>& callback) {
scoped_refptr<base::SequencedTaskRunner> response_task_runner,
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Note that the callback will be used only if the cert database hasn't yet
// been initialized.
net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
context,
base::Bind(&DidGetCertDBOnIOThread, response_task_runner, callback));
base::BindOnce(&DidGetCertDBOnIOThread, response_task_runner, callback));
if (cert_db)
DidGetCertDBOnIOThread(response_task_runner, callback, cert_db);
......@@ -48,7 +49,7 @@ void GetCertDBOnIOThread(
void GetNSSCertDatabaseForProfile(
Profile* profile,
const base::Callback<void(net::NSSCertDatabase*)>& callback) {
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
content::GetIOThreadTaskRunner({})->PostTask(
......@@ -56,4 +57,3 @@ void GetNSSCertDatabaseForProfile(
base::BindOnce(&GetCertDBOnIOThread, profile->GetResourceContext(),
base::ThreadTaskRunnerHandle::Get(), callback));
}
......@@ -30,7 +30,7 @@ class ResourceContext;
// Must be called only on the IO thread.
net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
content::ResourceContext* context,
const base::Callback<void(net::NSSCertDatabase*)>& callback)
base::OnceCallback<void(net::NSSCertDatabase*)> callback)
WARN_UNUSED_RESULT;
#if defined(OS_CHROMEOS)
......@@ -48,6 +48,6 @@ void EnableNSSSystemKeySlotForResourceContext(
// It's accessing profile, so it should be called on the UI thread.
void GetNSSCertDatabaseForProfile(
Profile* profile,
const base::Callback<void(net::NSSCertDatabase*)>& callback);
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback);
#endif // CHROME_BROWSER_NET_NSS_CONTEXT_H_
......@@ -22,7 +22,7 @@ void* kDatabaseManagerKey = &kDatabaseManagerKey;
class NSSCertDatabaseChromeOSManager : public base::SupportsUserData::Data {
public:
typedef base::Callback<void(net::NSSCertDatabaseChromeOS*)>
typedef base::OnceCallback<void(net::NSSCertDatabaseChromeOS*)>
GetNSSCertDatabaseCallback;
explicit NSSCertDatabaseChromeOSManager(const std::string& username_hash)
: username_hash_(username_hash) {
......@@ -40,13 +40,13 @@ class NSSCertDatabaseChromeOSManager : public base::SupportsUserData::Data {
}
net::NSSCertDatabaseChromeOS* GetNSSCertDatabase(
const GetNSSCertDatabaseCallback& callback) {
GetNSSCertDatabaseCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (nss_cert_database_)
return nss_cert_database_.get();
ready_callback_list_.push_back(callback);
ready_callback_list_.push_back(std::move(callback));
return NULL;
}
......@@ -61,11 +61,8 @@ class NSSCertDatabaseChromeOSManager : public base::SupportsUserData::Data {
ReadyCallbackList callback_list;
callback_list.swap(ready_callback_list_);
for (ReadyCallbackList::iterator i = callback_list.begin();
i != callback_list.end();
++i) {
(*i).Run(nss_cert_database_.get());
}
for (auto& callback : callback_list)
std::move(callback).Run(nss_cert_database_.get());
}
std::string username_hash_;
......@@ -82,8 +79,7 @@ std::string GetUsername(content::ResourceContext* context) {
net::NSSCertDatabaseChromeOS* GetNSSCertDatabaseChromeOS(
content::ResourceContext* context,
const NSSCertDatabaseChromeOSManager::GetNSSCertDatabaseCallback&
callback) {
NSSCertDatabaseChromeOSManager::GetNSSCertDatabaseCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
NSSCertDatabaseChromeOSManager* manager =
static_cast<NSSCertDatabaseChromeOSManager*>(
......@@ -92,13 +88,13 @@ net::NSSCertDatabaseChromeOS* GetNSSCertDatabaseChromeOS(
manager = new NSSCertDatabaseChromeOSManager(GetUsername(context));
context->SetUserData(kDatabaseManagerKey, base::WrapUnique(manager));
}
return manager->GetNSSCertDatabase(callback);
return manager->GetNSSCertDatabase(std::move(callback));
}
void CallWithNSSCertDatabase(
const base::Callback<void(net::NSSCertDatabase*)>& callback,
base::OnceCallback<void(net::NSSCertDatabase*)> callback,
net::NSSCertDatabaseChromeOS* db) {
callback.Run(db);
std::move(callback).Run(db);
}
void SetSystemSlot(crypto::ScopedPK11Slot system_slot,
......@@ -108,8 +104,8 @@ void SetSystemSlot(crypto::ScopedPK11Slot system_slot,
void SetSystemSlotOfDBForResourceContext(content::ResourceContext* context,
crypto::ScopedPK11Slot system_slot) {
base::Callback<void(net::NSSCertDatabaseChromeOS*)> callback =
base::Bind(&SetSystemSlot, base::Passed(&system_slot));
base::RepeatingCallback<void(net::NSSCertDatabaseChromeOS*)> callback =
base::BindRepeating(&SetSystemSlot, base::Passed(&system_slot));
net::NSSCertDatabaseChromeOS* db =
GetNSSCertDatabaseChromeOS(context, callback);
......@@ -121,16 +117,16 @@ void SetSystemSlotOfDBForResourceContext(content::ResourceContext* context,
net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
content::ResourceContext* context,
const base::Callback<void(net::NSSCertDatabase*)>& callback) {
base::OnceCallback<void(net::NSSCertDatabase*)> callback) {
return GetNSSCertDatabaseChromeOS(
context, base::Bind(&CallWithNSSCertDatabase, callback));
context, base::BindOnce(&CallWithNSSCertDatabase, std::move(callback)));
}
void EnableNSSSystemKeySlotForResourceContext(
content::ResourceContext* context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
base::Callback<void(crypto::ScopedPK11Slot)> callback =
base::Bind(&SetSystemSlotOfDBForResourceContext, context);
base::RepeatingCallback<void(crypto::ScopedPK11Slot)> callback =
base::BindRepeating(&SetSystemSlotOfDBForResourceContext, context);
crypto::ScopedPK11Slot system_slot = crypto::GetSystemNSSKeySlot(callback);
if (system_slot)
callback.Run(std::move(system_slot));
......
......@@ -67,12 +67,10 @@ class DBTester {
private:
void GetDBAndDoTestsOnIOThread(content::ResourceContext* context,
const base::Closure& done_callback) {
const base::RepeatingClosure& done_callback) {
net::NSSCertDatabase* db = GetNSSCertDatabaseForResourceContext(
context,
base::Bind(&DBTester::DoTestsOnIOThread,
base::Unretained(this),
done_callback));
context, base::BindOnce(&DBTester::DoTestsOnIOThread,
base::Unretained(this), done_callback));
if (db) {
DVLOG(1) << "got db synchronously";
DoTestsOnIOThread(done_callback, db);
......@@ -81,7 +79,7 @@ class DBTester {
}
}
void DoTestsOnIOThread(const base::Closure& done_callback,
void DoTestsOnIOThread(base::OnceClosure done_callback,
net::NSSCertDatabase* db) {
db_ = db;
EXPECT_TRUE(db);
......@@ -91,19 +89,21 @@ class DBTester {
EXPECT_EQ(db->GetPublicSlot().get(), db->GetPrivateSlot().get());
}
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, done_callback);
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
std::move(done_callback));
}
void DoGetDBAgainTestsOnIOThread(content::ResourceContext* context,
const base::Closure& done_callback) {
base::OnceClosure done_callback) {
net::NSSCertDatabase* db = GetNSSCertDatabaseForResourceContext(
context, base::Bind(&NotCalledDbCallback));
context, base::BindOnce(&NotCalledDbCallback));
// Should always be synchronous now.
EXPECT_TRUE(db);
// Should return the same db as before.
EXPECT_EQ(db_, db);
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, done_callback);
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
std::move(done_callback));
}
Profile* profile_;
......
......@@ -14,7 +14,7 @@ net::NSSCertDatabase* g_nss_cert_database = NULL;
net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext(
content::ResourceContext* context,
const base::Callback<void(net::NSSCertDatabase*)>& callback) {
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.
CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
......
......@@ -256,10 +256,10 @@ void UpdateStorageAccessSettings(Profile* profile) {
ProfileNetworkContextService::ProfileNetworkContextService(Profile* profile)
: profile_(profile), proxy_config_monitor_(profile) {
PrefService* profile_prefs = profile->GetPrefs();
quic_allowed_.Init(
prefs::kQuicAllowed, profile_prefs,
base::Bind(&ProfileNetworkContextService::DisableQuicIfNotAllowed,
base::Unretained(this)));
quic_allowed_.Init(prefs::kQuicAllowed, profile_prefs,
base::BindRepeating(
&ProfileNetworkContextService::DisableQuicIfNotAllowed,
base::Unretained(this)));
pref_accept_language_.Init(
language::prefs::kAcceptLanguages, profile_prefs,
base::BindRepeating(&ProfileNetworkContextService::UpdateAcceptLanguage,
......@@ -631,12 +631,12 @@ ProfileNetworkContextService::CreateClientCertStore() {
return std::make_unique<chromeos::ClientCertStoreChromeOS>(
std::move(certificate_provider), use_system_key_slot, username_hash,
base::Bind(&CreateCryptoModuleBlockingPasswordDelegate,
kCryptoModulePasswordClientAuth));
base::BindRepeating(&CreateCryptoModuleBlockingPasswordDelegate,
kCryptoModulePasswordClientAuth));
#elif defined(USE_NSS_CERTS)
return std::make_unique<net::ClientCertStoreNSS>(
base::Bind(&CreateCryptoModuleBlockingPasswordDelegate,
kCryptoModulePasswordClientAuth));
base::BindRepeating(&CreateCryptoModuleBlockingPasswordDelegate,
kCryptoModulePasswordClientAuth));
#elif defined(OS_WIN)
return std::make_unique<net::ClientCertStoreWin>();
#elif defined(OS_MACOSX)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment