Commit 1d721775 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_DESTROYED from //c/b/chromeos

Bug: 268984
Change-Id: Iabb05901e16d6002304ddf1ad427e0ea2836468b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873215
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708425}
parent 80ca9f23
......@@ -48,7 +48,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/api/braille_display_private/stub_braille_controller.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/singleton_tabs.h"
......@@ -241,8 +240,6 @@ AccessibilityManager::AccessibilityManager() {
notification_registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources());
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
notification_registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
......@@ -1052,10 +1049,19 @@ void AccessibilityManager::OnActiveOutputNodeChanged() {
}
}
void AccessibilityManager::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK_EQ(profile_, profile);
SetProfile(nullptr);
}
void AccessibilityManager::SetProfile(Profile* profile) {
if (profile_ == profile)
return;
if (profile_)
profile_observer_.Remove(profile_);
DCHECK(!profile_observer_.IsObservingSources());
pref_change_registrar_.reset();
local_state_pref_change_registrar_.reset();
......@@ -1141,6 +1147,8 @@ void AccessibilityManager::SetProfile(Profile* profile) {
extensions::ExtensionRegistry::Get(profile);
if (!extension_registry_observer_.IsObserving(registry))
extension_registry_observer_.Add(registry);
profile_observer_.Add(profile);
}
bool had_profile = (profile_ != NULL);
......@@ -1278,13 +1286,6 @@ void AccessibilityManager::Observe(
SetProfile(profile);
break;
}
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
// Update |profile_| when exiting a session or shutting down.
Profile* profile = content::Source<Profile>(source).ptr();
if (profile_ == profile)
SetProfile(nullptr);
break;
}
case chrome::NOTIFICATION_APP_TERMINATING: {
app_terminating_ = true;
break;
......
......@@ -20,6 +20,8 @@
#include "chrome/browser/chromeos/accessibility/chromevox_panel.h"
#include "chrome/browser/chromeos/accessibility/switch_access_panel.h"
#include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/user_manager/user_manager.h"
......@@ -35,7 +37,6 @@
#include "ui/base/ime/chromeos/input_method_manager.h"
class Browser;
class Profile;
class SwitchAccessEventHandlerDelegate;
namespace ash {
......@@ -109,7 +110,8 @@ class AccessibilityManager
public extensions::ExtensionRegistryObserver,
public user_manager::UserManager::UserSessionStateObserver,
public input_method::InputMethodManager::Observer,
public CrasAudioHandler::AudioObserver {
public CrasAudioHandler::AudioObserver,
public ProfileObserver {
public:
// Creates an instance of AccessibilityManager, this should be called once,
// because only one instance should exist at the same time.
......@@ -429,8 +431,12 @@ class AccessibilityManager
// CrasAudioHandler::AudioObserver:
void OnActiveOutputNodeChanged() override;
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
// Profile which has the current a11y context.
Profile* profile_ = nullptr;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
content::NotificationRegistrar notification_registrar_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
......@@ -95,6 +94,11 @@ double MagnificationManager::GetSavedScreenMagnifierScale() const {
ash::prefs::kAccessibilityScreenMagnifierScale);
}
void MagnificationManager::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK_EQ(profile_, profile);
SetProfile(nullptr);
}
void MagnificationManager::OnViewEvent(views::View* view,
ax::mojom::Event event_type) {
if (!fullscreen_magnifier_enabled_ && !IsDockedMagnifierEnabled())
......@@ -114,8 +118,6 @@ void MagnificationManager::SetProfileForTest(Profile* profile) {
MagnificationManager::MagnificationManager() {
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
// TODO(warx): observe focus changed in page notification when either
// fullscreen magnifier or docked magnifier is enabled.
registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
......@@ -142,13 +144,6 @@ void MagnificationManager::Observe(
SetProfile(profile);
break;
}
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
// Update |profile_| when exiting a session or shutting down.
Profile* profile = content::Source<Profile>(source).ptr();
if (profile_ == profile)
SetProfile(NULL);
break;
}
case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: {
HandleFocusChangedInPage(details);
break;
......@@ -170,6 +165,10 @@ void MagnificationManager::SetProfileByUser(const user_manager::User* user) {
}
void MagnificationManager::SetProfile(Profile* profile) {
if (profile_)
profile_observer_.Remove(profile_);
DCHECK(!profile_observer_.IsObservingSources());
pref_change_registrar_.reset();
if (profile) {
......@@ -193,6 +192,8 @@ void MagnificationManager::SetProfile(Profile* profile) {
base::BindRepeating(
&MagnificationManager::UpdateDockedMagnifierFromPrefs,
base::Unretained(this)));
profile_observer_.Add(profile);
}
profile_ = profile;
......
......@@ -7,13 +7,15 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/views/accessibility/ax_event_observer.h"
class PrefChangeRegistrar;
class Profile;
namespace chromeos {
......@@ -32,6 +34,7 @@ namespace chromeos {
class MagnificationManager
: public content::NotificationObserver,
public user_manager::UserManager::UserSessionStateObserver,
public ProfileObserver,
public views::AXEventObserver {
public:
// Creates an instance of MagnificationManager. This should be called once.
......@@ -61,6 +64,9 @@ class MagnificationManager
// Loads the Fullscreen magnifier scale from the pref.
double GetSavedScreenMagnifierScale() const;
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
// views::AXEventObserver:
void OnViewEvent(views::View* view, ax::mojom::Event event_type) override;
......@@ -94,6 +100,7 @@ class MagnificationManager
void HandleFocusChanged(const gfx::Rect& bounds_in_screen, bool is_editable);
Profile* profile_ = nullptr;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
bool fullscreen_magnifier_enabled_ = false;
bool keep_focus_centered_ = false;
......
......@@ -4,18 +4,12 @@
#include "chrome/browser/chromeos/note_taking_controller_client.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
namespace chromeos {
NoteTakingControllerClient::NoteTakingControllerClient(NoteTakingHelper* helper)
: helper_(helper) {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
user_manager::UserManager::Get()->AddSessionStateObserver(this);
}
......@@ -41,20 +35,18 @@ void NoteTakingControllerClient::ActiveUserChanged(
weak_ptr_factory_.GetWeakPtr(), active_user));
}
void NoteTakingControllerClient::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED);
void NoteTakingControllerClient::OnProfileWillBeDestroyed(Profile* profile) {
// Update |profile_| when exiting a session or shutting down.
Profile* profile = content::Source<Profile>(source).ptr();
if (profile_ == profile)
profile_ = nullptr;
DCHECK_EQ(profile_, profile);
profile_observer_.Remove(profile_);
profile_ = nullptr;
}
void NoteTakingControllerClient::SetProfileByUser(
const user_manager::User* user) {
profile_ = ProfileHelper::Get()->GetProfileByUser(user);
profile_observer_.RemoveAll();
profile_observer_.Add(profile_);
}
} // namespace chromeos
......@@ -9,18 +9,16 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/note_taking_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
namespace chromeos {
class NoteTakingControllerClient
: public ash::NoteTakingClient,
public user_manager::UserManager::UserSessionStateObserver,
public content::NotificationObserver {
public ProfileObserver {
public:
explicit NoteTakingControllerClient(NoteTakingHelper* helper);
~NoteTakingControllerClient() override;
......@@ -32,10 +30,8 @@ class NoteTakingControllerClient
// user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(user_manager::User* active_user) override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
void SetProfileForTesting(Profile* profile) { profile_ = profile; }
......@@ -47,8 +43,8 @@ class NoteTakingControllerClient
// Unowned pointer to the active profile.
Profile* profile_ = nullptr;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
content::NotificationRegistrar registrar_;
base::WeakPtrFactory<NoteTakingControllerClient> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NoteTakingControllerClient);
......
......@@ -14,8 +14,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/system_clock_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chromeos/login/login_state/login_state.h"
#include "chromeos/settings/cros_settings_names.h"
......@@ -54,8 +52,6 @@ SystemClock::SystemClock() {
if (LoginState::IsInitialized())
LoginState::Get()->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
user_manager::UserManager::Get()->AddSessionStateObserver(this);
}
......@@ -67,7 +63,6 @@ SystemClock::~SystemClock() {
user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
}
// LoginState::Observer overrides.
void SystemClock::LoggedInStateChanged() {
// It apparently sometimes takes a while after login before the current user
// is recognized as the owner. Make sure that the system-wide clock setting
......@@ -76,15 +71,11 @@ void SystemClock::LoggedInStateChanged() {
SetShouldUse24HourClock(ShouldUse24HourClock());
}
// content::NotificationObserver implementation.
void SystemClock::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED);
if (OnProfileDestroyed(content::Source<Profile>(source).ptr())) {
registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
}
void SystemClock::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK_EQ(profile, user_profile_);
profile_observer_.Remove(profile);
user_pref_registrar_.reset();
user_profile_ = nullptr;
}
void SystemClock::ActiveUserChanged(user_manager::User* active_user) {
......@@ -110,6 +101,8 @@ void SystemClock::SetProfileByUser(const user_manager::User* user) {
void SystemClock::SetProfile(Profile* profile) {
user_profile_ = profile;
profile_observer_.RemoveAll();
profile_observer_.Add(profile);
PrefService* prefs = profile->GetPrefs();
user_pref_registrar_.reset(new PrefChangeRegistrar);
user_pref_registrar_->Init(prefs);
......@@ -119,14 +112,6 @@ void SystemClock::SetProfile(Profile* profile) {
UpdateClockType();
}
bool SystemClock::OnProfileDestroyed(Profile* profile) {
if (profile != user_profile_)
return false;
user_pref_registrar_.reset();
user_profile_ = NULL;
return true;
}
void SystemClock::SetLastFocusedPodHourClockType(
base::HourClockType hour_clock_type) {
user_pod_was_focused_ = true;
......
......@@ -11,12 +11,12 @@
#include "base/i18n/time_formatting.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chromeos/login/login_state/login_state.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
class PrefChangeRegistrar;
namespace user_manager {
......@@ -33,7 +33,7 @@ class SystemClockObserver;
// modify on-screen time representation (like ActiveUserChanged) and notifies
// observers.
class SystemClock : public chromeos::LoginState::Observer,
public content::NotificationObserver,
public ProfileObserver,
public user_manager::UserManager::UserSessionStateObserver {
public:
SystemClock();
......@@ -46,12 +46,10 @@ class SystemClock : public chromeos::LoginState::Observer,
bool ShouldUse24HourClock() const;
// content::NotificationObserver implementation.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
// user_manager::UserManager::UserSessionStateObserver overrides
// user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(user_manager::User* active_user) override;
private:
......@@ -61,7 +59,6 @@ class SystemClock : public chromeos::LoginState::Observer,
void SetProfileByUser(const user_manager::User* user);
void SetProfile(Profile* profile);
bool OnProfileDestroyed(Profile* profile);
// LoginState::Observer overrides.
void LoggedInStateChanged() override;
......@@ -74,7 +71,7 @@ class SystemClock : public chromeos::LoginState::Observer,
base::HourClockType last_focused_pod_hour_clock_type_ = base::k12HourClock;
Profile* user_profile_ = nullptr;
content::NotificationRegistrar registrar_;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
std::unique_ptr<PrefChangeRegistrar> user_pref_registrar_;
base::ObserverList<SystemClockObserver>::Unchecked observer_list_;
......
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