Commit 75fea71b authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Retire ScopedObserver in /chrome/browser/ui/views/profiles.

ScopedObserver is being deprecated in favor of two new classes:
- base::ScopedObservation for observers that only ever observe
  a single source.
- base::ScopedMultiSourceObservation for observers that do or may
  observe more than a single source.

This CL was uploaded by git cl split.

R=jkrcal@chromium.org

Bug: 1145565
Change-Id: Ieed947565ee31fddba6e0ef2e73981ba34ba6ae6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547775
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829678}
parent 8ea1ec0e
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observation.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h" #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_icon_container_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_icon_container_view.h"
#include "ui/events/event.h" #include "ui/events/event.h"
......
...@@ -109,7 +109,7 @@ void AvatarToolbarButtonDelegate::Init(AvatarToolbarButton* button, ...@@ -109,7 +109,7 @@ void AvatarToolbarButtonDelegate::Init(AvatarToolbarButton* button,
profile_ = profile; profile_ = profile;
error_controller_ = error_controller_ =
std::make_unique<AvatarButtonErrorController>(this, profile_); std::make_unique<AvatarButtonErrorController>(this, profile_);
profile_observer_.Add(&GetProfileAttributesStorage()); profile_observation_.Observe(&GetProfileAttributesStorage());
AvatarToolbarButton::State state = GetState(); AvatarToolbarButton::State state = GetState();
if (state == AvatarToolbarButton::State::kIncognitoProfile || if (state == AvatarToolbarButton::State::kIncognitoProfile ||
state == AvatarToolbarButton::State::kGuestSession) { state == AvatarToolbarButton::State::kGuestSession) {
...@@ -117,7 +117,7 @@ void AvatarToolbarButtonDelegate::Init(AvatarToolbarButton* button, ...@@ -117,7 +117,7 @@ void AvatarToolbarButtonDelegate::Init(AvatarToolbarButton* button,
} else if (state != AvatarToolbarButton::State::kGuestSession) { } else if (state != AvatarToolbarButton::State::kGuestSession) {
signin::IdentityManager* identity_manager = signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
identity_manager_observer_.Add(identity_manager); identity_manager_observation_.Observe(identity_manager);
if (identity_manager->AreRefreshTokensLoaded()) if (identity_manager->AreRefreshTokensLoaded())
OnRefreshTokensLoaded(); OnRefreshTokensLoaded();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observation.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
...@@ -100,10 +100,12 @@ class AvatarToolbarButtonDelegate : public BrowserListObserver, ...@@ -100,10 +100,12 @@ class AvatarToolbarButtonDelegate : public BrowserListObserver,
void MaybeHideIdentityAnimation(); void MaybeHideIdentityAnimation();
void HideHighlightAnimation(); void HideHighlightAnimation();
ScopedObserver<ProfileAttributesStorage, ProfileAttributesStorage::Observer> base::ScopedObservation<ProfileAttributesStorage,
profile_observer_{this}; ProfileAttributesStorage::Observer>
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer> profile_observation_{this};
identity_manager_observer_{this}; base::ScopedObservation<signin::IdentityManager,
signin::IdentityManager::Observer>
identity_manager_observation_{this};
AvatarToolbarButton* avatar_toolbar_button_ = nullptr; AvatarToolbarButton* avatar_toolbar_button_ = nullptr;
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
IdentityAnimationState identity_animation_state_ = IdentityAnimationState identity_animation_state_ =
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/scoped_observation.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -1048,7 +1049,7 @@ class ProfileMenuViewBase::AXMenuWidgetObserver : public views::WidgetObserver { ...@@ -1048,7 +1049,7 @@ class ProfileMenuViewBase::AXMenuWidgetObserver : public views::WidgetObserver {
public: public:
AXMenuWidgetObserver(ProfileMenuViewBase* owner, views::Widget* widget) AXMenuWidgetObserver(ProfileMenuViewBase* owner, views::Widget* widget)
: owner_(owner) { : owner_(owner) {
observer_.Add(widget); observation_.Observe(widget);
} }
~AXMenuWidgetObserver() override = default; ~AXMenuWidgetObserver() override = default;
...@@ -1064,5 +1065,6 @@ class ProfileMenuViewBase::AXMenuWidgetObserver : public views::WidgetObserver { ...@@ -1064,5 +1065,6 @@ class ProfileMenuViewBase::AXMenuWidgetObserver : public views::WidgetObserver {
private: private:
ProfileMenuViewBase* owner_; ProfileMenuViewBase* owner_;
ScopedObserver<views::Widget, views::WidgetObserver> observer_{this}; base::ScopedObservation<views::Widget, views::WidgetObserver> observation_{
this};
}; };
...@@ -300,7 +300,7 @@ void ProfilePickerView::OnProfileForSigninCreated( ...@@ -300,7 +300,7 @@ void ProfilePickerView::OnProfileForSigninCreated(
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO); signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
// Listen for sign-in getting completed. // Listen for sign-in getting completed.
identity_manager_observer_.Add( identity_manager_observation_.Observe(
IdentityManagerFactory::GetForProfile(profile)); IdentityManagerFactory::GetForProfile(profile));
// TODO(crbug.com/1126913): When there is back button from the signed-in page, // TODO(crbug.com/1126913): When there is back button from the signed-in page,
// make sure the flow does not create multiple profiles simultaneously. // make sure the flow does not create multiple profiles simultaneously.
...@@ -443,8 +443,9 @@ void ProfilePickerView::OnExtendedAccountInfoTimeout(const std::string& email) { ...@@ -443,8 +443,9 @@ void ProfilePickerView::OnExtendedAccountInfoTimeout(const std::string& email) {
void ProfilePickerView::OnProfileNameAvailable() { void ProfilePickerView::OnProfileNameAvailable() {
// Stop listening to further changes. // Stop listening to further changes.
identity_manager_observer_.Remove( DCHECK(identity_manager_observation_.IsObservingSource(
IdentityManagerFactory::GetForProfile(signed_in_profile_being_created_)); IdentityManagerFactory::GetForProfile(signed_in_profile_being_created_)));
identity_manager_observation_.RemoveObservation();
if (on_profile_name_available_) if (on_profile_name_available_)
std::move(on_profile_name_available_).Run(); std::move(on_profile_name_available_).Run();
......
...@@ -120,8 +120,9 @@ class ProfilePickerView : public views::DialogDelegateView, ...@@ -120,8 +120,9 @@ class ProfilePickerView : public views::DialogDelegateView,
// Not null iff switching to sign-in is in progress. // Not null iff switching to sign-in is in progress.
base::OnceClosure switch_failure_callback_; base::OnceClosure switch_failure_callback_;
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer> base::ScopedObservation<signin::IdentityManager,
identity_manager_observer_{this}; signin::IdentityManager::Observer>
identity_manager_observation_{this};
// Creation time of the picker, to measure performance on startup. Only set // Creation time of the picker, to measure performance on startup. Only set
// when the picker is shown on startup. // when the picker is shown on startup.
......
...@@ -106,7 +106,7 @@ class WebViewAddedWaiter : public views::ViewObserver { ...@@ -106,7 +106,7 @@ class WebViewAddedWaiter : public views::ViewObserver {
views::View* top_view, views::View* top_view,
base::RepeatingCallback<views::WebView*()> current_web_view_getter) base::RepeatingCallback<views::WebView*()> current_web_view_getter)
: current_web_view_getter_(current_web_view_getter) { : current_web_view_getter_(current_web_view_getter) {
observed_.Add(top_view); observation_.Observe(top_view);
} }
~WebViewAddedWaiter() override = default; ~WebViewAddedWaiter() override = default;
...@@ -124,7 +124,7 @@ class WebViewAddedWaiter : public views::ViewObserver { ...@@ -124,7 +124,7 @@ class WebViewAddedWaiter : public views::ViewObserver {
base::RunLoop run_loop_; base::RunLoop run_loop_;
base::RepeatingCallback<views::WebView*()> current_web_view_getter_; base::RepeatingCallback<views::WebView*()> current_web_view_getter_;
ScopedObserver<views::View, views::ViewObserver> observed_{this}; base::ScopedObservation<views::View, views::ViewObserver> observation_{this};
}; };
class BrowserAddedWaiter : public BrowserListObserver { class BrowserAddedWaiter : public BrowserListObserver {
......
...@@ -77,7 +77,8 @@ void ProfilePickerViewSyncDelegate::ShowSyncConfirmation( ...@@ -77,7 +77,8 @@ void ProfilePickerViewSyncDelegate::ShowSyncConfirmation(
callback) { callback) {
DCHECK(callback); DCHECK(callback);
sync_confirmation_callback_ = std::move(callback); sync_confirmation_callback_ = std::move(callback);
scoped_login_ui_service_observer_.Add( DCHECK(!scoped_login_ui_service_observation_.IsObserving());
scoped_login_ui_service_observation_.Observe(
LoginUIServiceFactory::GetForProfile(profile_)); LoginUIServiceFactory::GetForProfile(profile_));
if (enterprise_confirmation_shown_) { if (enterprise_confirmation_shown_) {
...@@ -94,7 +95,8 @@ void ProfilePickerViewSyncDelegate::ShowSyncDisabledConfirmation( ...@@ -94,7 +95,8 @@ void ProfilePickerViewSyncDelegate::ShowSyncDisabledConfirmation(
callback) { callback) {
DCHECK(callback); DCHECK(callback);
sync_confirmation_callback_ = std::move(callback); sync_confirmation_callback_ = std::move(callback);
scoped_login_ui_service_observer_.Add( DCHECK(!scoped_login_ui_service_observation_.IsObserving());
scoped_login_ui_service_observation_.Observe(
LoginUIServiceFactory::GetForProfile(profile_)); LoginUIServiceFactory::GetForProfile(profile_));
// Open the browser and when it's done, show the confirmation dialog. // Open the browser and when it's done, show the confirmation dialog.
...@@ -124,8 +126,9 @@ void ProfilePickerViewSyncDelegate::SwitchToProfile(Profile* new_profile) { ...@@ -124,8 +126,9 @@ void ProfilePickerViewSyncDelegate::SwitchToProfile(Profile* new_profile) {
void ProfilePickerViewSyncDelegate::OnSyncConfirmationUIClosed( void ProfilePickerViewSyncDelegate::OnSyncConfirmationUIClosed(
LoginUIService::SyncConfirmationUIClosedResult result) { LoginUIService::SyncConfirmationUIClosedResult result) {
// No need to listen to further confirmations any more. // No need to listen to further confirmations any more.
scoped_login_ui_service_observer_.Remove( DCHECK(scoped_login_ui_service_observation_.IsObservingSource(
LoginUIServiceFactory::GetForProfile(profile_)); LoginUIServiceFactory::GetForProfile(profile_)));
scoped_login_ui_service_observation_.RemoveObservation();
DCHECK(sync_confirmation_callback_); DCHECK(sync_confirmation_callback_);
std::move(sync_confirmation_callback_).Run(result); std::move(sync_confirmation_callback_).Run(result);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_ #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_ #define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_VIEW_SYNC_DELEGATE_H_
#include "base/scoped_observer.h" #include "base/scoped_observation.h"
#include "chrome/browser/ui/views/profiles/profile_picker_view.h" #include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include "chrome/browser/ui/webui/signin/dice_turn_sync_on_helper.h" #include "chrome/browser/ui/webui/signin/dice_turn_sync_on_helper.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h" #include "chrome/browser/ui/webui/signin/login_ui_service.h"
...@@ -53,8 +53,8 @@ class ProfilePickerViewSyncDelegate : public DiceTurnSyncOnHelper::Delegate, ...@@ -53,8 +53,8 @@ class ProfilePickerViewSyncDelegate : public DiceTurnSyncOnHelper::Delegate,
OpenBrowserCallback open_browser_callback_; OpenBrowserCallback open_browser_callback_;
base::OnceCallback<void(LoginUIService::SyncConfirmationUIClosedResult)> base::OnceCallback<void(LoginUIService::SyncConfirmationUIClosedResult)>
sync_confirmation_callback_; sync_confirmation_callback_;
ScopedObserver<LoginUIService, LoginUIService::Observer> base::ScopedObservation<LoginUIService, LoginUIService::Observer>
scoped_login_ui_service_observer_{this}; scoped_login_ui_service_observation_{this};
DISALLOW_COPY_AND_ASSIGN(ProfilePickerViewSyncDelegate); DISALLOW_COPY_AND_ASSIGN(ProfilePickerViewSyncDelegate);
}; };
......
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