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