Commit ebdc85f0 authored by Ayu Ishii's avatar Ayu Ishii Committed by Commit Bot

[Reland] Convert base::Bind and base::Callback in components/rlz to Once/Repeating

> Original CL: https://crrev.com/c/1935649
> Revert CL: https://crrev.com/c/1949080

Updated with changes to ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h to
new signature.

Change-Id: Ic78393d6bfe1d40f0e2721e828c4b00de36350e8
Bug: 1007725
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949038Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739456}
parent a24f4200
......@@ -172,21 +172,21 @@ bool ChromeRLZTrackerDelegate::ClearReferral() {
}
void ChromeRLZTrackerDelegate::SetOmniboxSearchCallback(
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(!callback.is_null());
omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&ChromeRLZTrackerDelegate::OnURLOpenedFromOmnibox,
base::Unretained(this)));
on_omnibox_search_callback_ = callback;
on_omnibox_search_callback_ = std::move(callback);
}
void ChromeRLZTrackerDelegate::SetHomepageSearchCallback(
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(!callback.is_null());
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
on_homepage_search_callback_ = callback;
on_homepage_search_callback_ = std::move(callback);
}
bool ChromeRLZTrackerDelegate::ShouldUpdateExistingAccessPointRlz() {
......@@ -197,8 +197,7 @@ void ChromeRLZTrackerDelegate::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
using std::swap;
base::Closure callback_to_run;
base::OnceClosure callback_to_run;
switch (type) {
case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
// Firstly check if it is a Google search.
......@@ -235,7 +234,7 @@ void ChromeRLZTrackerDelegate::Observe(
ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
swap(callback_to_run, on_homepage_search_callback_);
callback_to_run = std::move(on_homepage_search_callback_);
}
}
break;
......@@ -247,11 +246,10 @@ void ChromeRLZTrackerDelegate::Observe(
}
if (!callback_to_run.is_null())
callback_to_run.Run();
std::move(callback_to_run).Run();
}
void ChromeRLZTrackerDelegate::OnURLOpenedFromOmnibox(OmniboxLog* log) {
using std::swap;
// In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
// it did previously. The RLZ folks want RLZ's "first search" detection
......@@ -261,7 +259,5 @@ void ChromeRLZTrackerDelegate::OnURLOpenedFromOmnibox(OmniboxLog* log) {
return;
omnibox_url_opened_subscription_.reset();
base::Closure omnibox_callback;
swap(omnibox_callback, on_omnibox_search_callback_);
omnibox_callback.Run();
std::move(on_omnibox_search_callback_).Run();
}
......@@ -44,8 +44,8 @@ class ChromeRLZTrackerDelegate : public rlz::RLZTrackerDelegate,
bool GetLanguage(base::string16* language) override;
bool GetReferral(base::string16* referral) override;
bool ClearReferral() override;
void SetOmniboxSearchCallback(const base::Closure& callback) override;
void SetHomepageSearchCallback(const base::Closure& callback) override;
void SetOmniboxSearchCallback(base::OnceClosure callback) override;
void SetHomepageSearchCallback(base::OnceClosure callback) override;
bool ShouldUpdateExistingAccessPointRlz() override;
// content::NotificationObserver implementation:
......@@ -57,8 +57,8 @@ class ChromeRLZTrackerDelegate : public rlz::RLZTrackerDelegate,
void OnURLOpenedFromOmnibox(OmniboxLog* log);
content::NotificationRegistrar registrar_;
base::Closure on_omnibox_search_callback_;
base::Closure on_homepage_search_callback_;
base::OnceClosure on_omnibox_search_callback_;
base::OnceClosure on_homepage_search_callback_;
// Subscription for receiving callbacks that a URL was opened from the
// omnibox.
......
......@@ -289,15 +289,15 @@ bool RLZTracker::Init(bool first_run,
// Register for notifications from the omnibox so that we can record when
// the user performs a first search.
delegate_->SetOmniboxSearchCallback(
base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this),
ChromeOmnibox()));
base::BindOnce(&RLZTracker::RecordFirstSearch, base::Unretained(this),
ChromeOmnibox()));
#if !defined(OS_IOS)
// Register for notifications from navigations, to see if the user has used
// the home page.
delegate_->SetHomepageSearchCallback(
base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this),
ChromeHomePage()));
base::BindOnce(&RLZTracker::RecordFirstSearch, base::Unretained(this),
ChromeHomePage()));
#endif
}
delegate_->GetReactivationBrand(&reactivation_brand_);
......
......@@ -62,12 +62,12 @@ class RLZTrackerDelegate {
// Registers |callback| to be invoked the next time the user perform a search
// using Google search engine via the omnibox. Callback will invoked at most
// once.
virtual void SetOmniboxSearchCallback(const base::Closure& callback) = 0;
virtual void SetOmniboxSearchCallback(base::OnceClosure callback) = 0;
// Registers |callback| to be invoked the next time the user perform a search
// using Google search engine via the homepage. Callback will invoked at most
// once.
virtual void SetHomepageSearchCallback(const base::Closure& callback) = 0;
virtual void SetHomepageSearchCallback(base::OnceClosure callback) = 0;
// Returns true if the existing access point RLZ strings in the data file
// should be updated.
......
......@@ -49,19 +49,13 @@ class TestRLZTrackerDelegate : public RLZTrackerDelegate {
}
void SimulateOmniboxUsage() {
using std::swap;
base::Closure callback;
swap(callback, on_omnibox_search_callback_);
if (!callback.is_null())
callback.Run();
if (!on_omnibox_search_callback_.is_null())
std::move(on_omnibox_search_callback_).Run();
}
void SimulateHomepageUsage() {
using std::swap;
base::Closure callback;
swap(callback, on_homepage_search_callback_);
if (!callback.is_null())
callback.Run();
if (!on_homepage_search_callback_.is_null())
std::move(on_homepage_search_callback_).Run();
}
// RLZTrackerDelegate implementation.
......@@ -100,14 +94,14 @@ class TestRLZTrackerDelegate : public RLZTrackerDelegate {
bool ClearReferral() override { return true; }
void SetOmniboxSearchCallback(const base::Closure& callback) override {
void SetOmniboxSearchCallback(base::OnceClosure callback) override {
DCHECK(!callback.is_null());
on_omnibox_search_callback_ = callback;
on_omnibox_search_callback_ = std::move(callback);
}
void SetHomepageSearchCallback(const base::Closure& callback) override {
void SetHomepageSearchCallback(base::OnceClosure callback) override {
DCHECK(!callback.is_null());
on_homepage_search_callback_ = callback;
on_homepage_search_callback_ = std::move(callback);
}
// A speculative fix for https://crbug.com/907379.
......@@ -118,8 +112,8 @@ class TestRLZTrackerDelegate : public RLZTrackerDelegate {
std::string brand_override_;
std::string reactivation_brand_override_;
base::Closure on_omnibox_search_callback_;
base::Closure on_homepage_search_callback_;
base::OnceClosure on_omnibox_search_callback_;
base::OnceClosure on_homepage_search_callback_;
DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate);
};
......
......@@ -101,9 +101,9 @@ bool RLZTrackerDelegateImpl::ClearReferral() {
}
void RLZTrackerDelegateImpl::SetOmniboxSearchCallback(
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(!callback.is_null());
on_omnibox_search_callback_ = callback;
on_omnibox_search_callback_ = std::move(callback);
on_omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox,
......@@ -111,7 +111,7 @@ void RLZTrackerDelegateImpl::SetOmniboxSearchCallback(
}
void RLZTrackerDelegateImpl::SetHomepageSearchCallback(
const base::Closure& callback) {
base::OnceClosure callback) {
NOTREACHED();
}
......@@ -130,9 +130,6 @@ void RLZTrackerDelegateImpl::OnURLOpenedFromOmnibox(OmniboxLog* log) {
on_omnibox_url_opened_subscription_.reset();
using std::swap;
base::Closure callback_to_run;
swap(callback_to_run, on_omnibox_search_callback_);
if (!callback_to_run.is_null())
callback_to_run.Run();
if (!on_omnibox_search_callback_.is_null())
std::move(on_omnibox_search_callback_).Run();
}
......@@ -38,14 +38,14 @@ class RLZTrackerDelegateImpl : public rlz::RLZTrackerDelegate {
bool GetLanguage(base::string16* language) override;
bool GetReferral(base::string16* referral) override;
bool ClearReferral() override;
void SetOmniboxSearchCallback(const base::Closure& callback) override;
void SetHomepageSearchCallback(const base::Closure& callback) override;
void SetOmniboxSearchCallback(base::OnceClosure callback) override;
void SetHomepageSearchCallback(base::OnceClosure callback) override;
bool ShouldUpdateExistingAccessPointRlz() override;
// Called when user open an URL from the Omnibox.
void OnURLOpenedFromOmnibox(OmniboxLog* log);
base::Closure on_omnibox_search_callback_;
base::OnceClosure on_omnibox_search_callback_;
std::unique_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription>
on_omnibox_url_opened_subscription_;
......
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