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