Commit ad3d16db authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

Convert base::Bind in //chrome/browser/profile_resetter/

This CL converts base::Bind to base::BindOnce in
//chrome/browser/profile_resetter/. With this CL, there should be no
base::Callback, base::Closure and base::Bind any more.

Bug: 1007635
Change-Id: I57bb5ec4d0dbf9518015c8c9cf1ef6d739a327cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2284387Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#786231}
parent a5bad859
......@@ -51,10 +51,10 @@ std::string GetUploadData(const std::string& brand) {
BrandcodeConfigFetcher::BrandcodeConfigFetcher(
network::mojom::URLLoaderFactory* url_loader_factory,
const FetchCallback& callback,
FetchCallback callback,
const GURL& url,
const std::string& brandcode)
: fetch_callback_(callback), weak_ptr_factory_(this) {
: fetch_callback_(std::move(callback)), weak_ptr_factory_(this) {
DCHECK(!brandcode.empty());
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("brandcode_config", R"(
......@@ -101,8 +101,8 @@ BrandcodeConfigFetcher::BrandcodeConfigFetcher(
BrandcodeConfigFetcher::~BrandcodeConfigFetcher() {}
void BrandcodeConfigFetcher::SetCallback(const FetchCallback& callback) {
fetch_callback_ = callback;
void BrandcodeConfigFetcher::SetCallback(FetchCallback callback) {
fetch_callback_ = std::move(callback);
}
void BrandcodeConfigFetcher::OnSimpleLoaderComplete(
......
......@@ -29,10 +29,10 @@ class URLLoaderFactory;
// default settings. Caller should provide a FetchCallback.
class BrandcodeConfigFetcher {
public:
typedef base::Callback<void ()> FetchCallback;
typedef base::OnceCallback<void()> FetchCallback;
BrandcodeConfigFetcher(network::mojom::URLLoaderFactory* url_loader_factory,
const FetchCallback& callback,
FetchCallback callback,
const GURL& url,
const std::string& brandcode);
~BrandcodeConfigFetcher();
......@@ -44,7 +44,7 @@ class BrandcodeConfigFetcher {
}
// Sets the new callback. The previous one won't be called.
void SetCallback(const FetchCallback& callback);
void SetCallback(FetchCallback callback);
private:
void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body);
......
......@@ -94,7 +94,7 @@ ProfileResetter::~ProfileResetter() {
void ProfileResetter::Reset(
ProfileResetter::ResettableFlags resettable_flags,
std::unique_ptr<BrandcodedDefaultSettings> master_settings,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(master_settings);
......@@ -105,12 +105,13 @@ void ProfileResetter::Reset(
CHECK_EQ(static_cast<ResettableFlags>(0), pending_reset_flags_);
if (!resettable_flags) {
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, callback);
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
std::move(callback));
return;
}
master_settings_.swap(master_settings);
callback_ = callback;
callback_ = std::move(callback);
// These flags are set to false by the individual reset functions.
pending_reset_flags_ = resettable_flags;
......@@ -156,8 +157,8 @@ void ProfileResetter::MarkAsDone(Resettable resettable) {
pending_reset_flags_ &= ~resettable;
if (!pending_reset_flags_) {
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, callback_);
callback_.Reset();
content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
std::move(callback_));
master_settings_.reset();
template_url_service_sub_.reset();
}
......@@ -186,10 +187,9 @@ void ProfileResetter::ResetDefaultSearchEngine() {
MarkAsDone(DEFAULT_SEARCH_ENGINE);
} else {
template_url_service_sub_ =
template_url_service_->RegisterOnLoadedCallback(
base::Bind(&ProfileResetter::OnTemplateURLServiceLoaded,
weak_ptr_factory_.GetWeakPtr()));
template_url_service_sub_ = template_url_service_->RegisterOnLoadedCallback(
base::BindRepeating(&ProfileResetter::OnTemplateURLServiceLoaded,
weak_ptr_factory_.GetWeakPtr()));
template_url_service_->Load();
}
}
......
......@@ -71,7 +71,7 @@ class ProfileResetter : public content::BrowsingDataRemover::Observer {
// settings. |default_settings| shouldn't be NULL.
virtual void Reset(ResettableFlags resettable_flags,
std::unique_ptr<BrandcodedDefaultSettings> master_settings,
const base::Closure& callback);
base::OnceClosure callback);
virtual bool IsActive() const;
......@@ -108,7 +108,7 @@ class ProfileResetter : public content::BrowsingDataRemover::Observer {
ResettableFlags pending_reset_flags_;
// Called on UI thread when reset has been completed.
base::Closure callback_;
base::OnceClosure callback_;
// If non-null it means removal is in progress. BrowsingDataRemover takes care
// of deleting itself when done.
......
......@@ -44,8 +44,8 @@ void ProfileResetterTestBase::ResetAndWait(
std::unique_ptr<BrandcodedDefaultSettings> master_settings(
new BrandcodedDefaultSettings);
resetter_->Reset(resettable_flags, std::move(master_settings),
base::Bind(&ProfileResetterMockObject::StopLoop,
base::Unretained(&mock_object_)));
base::BindOnce(&ProfileResetterMockObject::StopLoop,
base::Unretained(&mock_object_)));
mock_object_.RunLoop();
}
......@@ -55,8 +55,8 @@ void ProfileResetterTestBase::ResetAndWait(
std::unique_ptr<BrandcodedDefaultSettings> master_settings(
new BrandcodedDefaultSettings(prefs));
resetter_->Reset(resettable_flags, std::move(master_settings),
base::Bind(&ProfileResetterMockObject::StopLoop,
base::Unretained(&mock_object_)));
base::BindOnce(&ProfileResetterMockObject::StopLoop,
base::Unretained(&mock_object_)));
mock_object_.RunLoop();
}
......@@ -67,5 +67,5 @@ std::unique_ptr<KeyedService> CreateTemplateURLServiceForTesting(
profile->GetPrefs(), std::make_unique<UIThreadSearchTermsData>(),
WebDataServiceFactory::GetKeywordWebDataForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS),
nullptr /* TemplateURLServiceClient */, base::Closure());
nullptr /* TemplateURLServiceClient */, base::RepeatingClosure());
}
......@@ -24,7 +24,7 @@ class BrowserContext;
// ProfileResetterMockObject mock_object;
// resetter_->Reset(ProfileResetter::ALL,
// pointer,
// base::Bind(&ProfileResetterMockObject::StopLoop,
// base::BindOnce(&ProfileResetterMockObject::StopLoop,
// base::Unretained(&mock_object)));
// mock_object.RunLoop();
class ProfileResetterMockObject {
......
......@@ -217,7 +217,7 @@ std::unique_ptr<BrandcodeConfigFetcher> ConfigParserTest::WaitForRequest(
}));
std::unique_ptr<BrandcodeConfigFetcher> fetcher(new BrandcodeConfigFetcher(
&test_url_loader_factory_,
base::Bind(&ConfigParserTest::Callback, base::Unretained(this)), url,
base::BindOnce(&ConfigParserTest::Callback, base::Unretained(this)), url,
"ABCD"));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(fetcher->IsActive());
......@@ -833,7 +833,7 @@ TEST_F(ProfileResetterTest, CheckSnapshots) {
base::ASCIIToUTF16("--profile-directory=Default1"));
ResettableSettingsSnapshot nonorganic_snap(profile());
nonorganic_snap.RequestShortcuts(base::Closure());
nonorganic_snap.RequestShortcuts(base::OnceClosure());
// Let it enumerate shortcuts on a blockable task runner.
content::RunAllTasksUntilIdle();
int diff_fields = ResettableSettingsSnapshot::ALL_FIELDS;
......@@ -861,7 +861,7 @@ TEST_F(ProfileResetterTest, CheckSnapshots) {
ProfileResetter::SHORTCUTS);
ResettableSettingsSnapshot organic_snap(profile());
organic_snap.RequestShortcuts(base::Closure());
organic_snap.RequestShortcuts(base::OnceClosure());
// Let it enumerate shortcuts on a blockable task runner.
content::RunAllTasksUntilIdle();
EXPECT_EQ(diff_fields, nonorganic_snap.FindDifferentFields(organic_snap));
......@@ -905,7 +905,7 @@ TEST_F(ProfileResetterTest, FeedbackSerializationAsProtoTest) {
base::ASCIIToUTF16("--profile-directory=Default foo.com"));
ResettableSettingsSnapshot nonorganic_snap(profile());
nonorganic_snap.RequestShortcuts(base::Closure());
nonorganic_snap.RequestShortcuts(base::OnceClosure());
// Let it enumerate shortcuts on a blockable task runner.
content::RunAllTasksUntilIdle();
......@@ -981,9 +981,9 @@ TEST_F(ProfileResetterTest, GetReadableFeedback) {
FeedbackCapture capture;
EXPECT_CALL(capture, OnUpdatedList());
ResettableSettingsSnapshot snapshot(profile());
snapshot.RequestShortcuts(base::Bind(&FeedbackCapture::SetFeedback,
base::Unretained(&capture), profile(),
std::cref(snapshot)));
snapshot.RequestShortcuts(base::BindOnce(&FeedbackCapture::SetFeedback,
base::Unretained(&capture),
profile(), std::cref(snapshot)));
// Let it enumerate shortcuts on a blockable task runner.
content::RunAllTasksUntilIdle();
EXPECT_TRUE(snapshot.shortcuts_determined());
......@@ -1020,8 +1020,8 @@ TEST_F(ProfileResetterTest, DestroySnapshotFast) {
FeedbackCapture capture;
std::unique_ptr<ResettableSettingsSnapshot> deleted_snapshot(
new ResettableSettingsSnapshot(profile()));
deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail,
base::Unretained(&capture)));
deleted_snapshot->RequestShortcuts(
base::BindOnce(&FeedbackCapture::Fail, base::Unretained(&capture)));
deleted_snapshot.reset();
// Running remaining tasks shouldn't trigger the callback to be called as
// |deleted_snapshot| was deleted before it could run.
......
......@@ -130,8 +130,7 @@ int ResettableSettingsSnapshot::FindDifferentFields(
return bit_mask;
}
void ResettableSettingsSnapshot::RequestShortcuts(
const base::Closure& callback) {
void ResettableSettingsSnapshot::RequestShortcuts(base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!cancellation_flag_.get() && !shortcuts_determined());
......@@ -143,20 +142,20 @@ void ResettableSettingsSnapshot::RequestShortcuts(
.get(),
FROM_HERE, base::BindOnce(&GetChromeLaunchShortcuts, cancellation_flag_),
base::BindOnce(&ResettableSettingsSnapshot::SetShortcutsAndReport,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
#else // defined(OS_WIN)
// Shortcuts are only supported on Windows.
std::vector<ShortcutCommand> no_shortcuts;
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&ResettableSettingsSnapshot::SetShortcutsAndReport,
weak_ptr_factory_.GetWeakPtr(), callback,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(no_shortcuts)));
#endif // defined(OS_WIN)
}
void ResettableSettingsSnapshot::SetShortcutsAndReport(
const base::Closure& callback,
base::OnceClosure callback,
const std::vector<ShortcutCommand>& shortcuts) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
shortcuts_ = shortcuts;
......@@ -164,7 +163,7 @@ void ResettableSettingsSnapshot::SetShortcutsAndReport(
cancellation_flag_.reset();
if (!callback.is_null())
callback.Run();
std::move(callback).Run();
}
std::unique_ptr<reset_report::ChromeResetReport> SerializeSettingsReportToProto(
......
......@@ -84,13 +84,12 @@ class ResettableSettingsSnapshot {
// Collects the shortcuts asynchronously and calls |callback|. If the request
// has been made already, noop.
void RequestShortcuts(const base::Closure& callback);
void RequestShortcuts(base::OnceClosure callback);
private:
// Fills the |shortcuts_| member and calls |callback|.
void SetShortcutsAndReport(
const base::Closure& callback,
const std::vector<ShortcutCommand>& shortcuts);
void SetShortcutsAndReport(base::OnceClosure callback,
const std::vector<ShortcutCommand>& shortcuts);
// Every ResettableSettingsSnapshot instance gets a randomly created GUID.
std::string guid_;
......
......@@ -33,9 +33,9 @@ MockProfileResetter::~MockProfileResetter() {}
void MockProfileResetter::Reset(
ProfileResetter::ResettableFlags resettable_flags,
std::unique_ptr<BrandcodedDefaultSettings> master_settings,
const base::Closure& callback) {
MockReset(resettable_flags, master_settings.get(), callback);
callback.Run();
base::OnceClosure callback) {
MockReset(resettable_flags, master_settings.get(), base::OnceClosure());
std::move(callback).Run();
}
std::unique_ptr<SettingsResetPromptModel> CreateModelForTesting(
......
......@@ -41,12 +41,12 @@ class MockProfileResetter : public ProfileResetter {
// real |ProfileResetter|'s behaviour.
void Reset(ProfileResetter::ResettableFlags resettable_flags,
std::unique_ptr<BrandcodedDefaultSettings> master_settings,
const base::Closure& callback) override;
base::OnceClosure callback) override;
MOCK_METHOD3(MockReset,
void(ProfileResetter::ResettableFlags resettable_flags,
BrandcodedDefaultSettings* master_settings,
const base::Closure& callback));
base::OnceClosure callback));
MOCK_CONST_METHOD0(IsActive, bool());
};
......
......@@ -32,9 +32,9 @@ class MockProfileResetter : public ProfileResetter {
void Reset(ResettableFlags resettable_flags,
std::unique_ptr<BrandcodedDefaultSettings> initial_settings,
const base::Closure& callback) override {
base::OnceClosure callback) override {
resets_++;
callback.Run();
std::move(callback).Run();
}
size_t resets() const {
......
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