Commit 593dd520 authored by bauerb's avatar bauerb Committed by Commit bot

Use ScopedObserver to observe the SupervisedUserSyncService in SupervisedUserImportHandler.

In addition to simplifying the code, ScopedObserver ensures that the object is unregistered as an observer if and only if it has been registered.

BUG=488642

Review URL: https://codereview.chromium.org/1123283011

Cr-Commit-Position: refs/heads/master@{#330536}
parent ac82d80a
...@@ -56,19 +56,12 @@ namespace options { ...@@ -56,19 +56,12 @@ namespace options {
SupervisedUserImportHandler::SupervisedUserImportHandler() SupervisedUserImportHandler::SupervisedUserImportHandler()
: profile_observer_(this), : profile_observer_(this),
signin_error_observer_(this), signin_error_observer_(this),
supervised_user_sync_service_observer_(this),
removed_profile_is_supervised_(false), removed_profile_is_supervised_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
} }
SupervisedUserImportHandler::~SupervisedUserImportHandler() { SupervisedUserImportHandler::~SupervisedUserImportHandler() {
Profile* profile = Profile::FromWebUI(web_ui());
if (!profile->IsSupervised()) {
SupervisedUserSyncService* service =
SupervisedUserSyncServiceFactory::GetForProfile(profile);
if (service)
service->RemoveObserver(this);
subscription_.reset();
}
} }
void SupervisedUserImportHandler::GetLocalizedValues( void SupervisedUserImportHandler::GetLocalizedValues(
...@@ -105,7 +98,7 @@ void SupervisedUserImportHandler::InitializeHandler() { ...@@ -105,7 +98,7 @@ void SupervisedUserImportHandler::InitializeHandler() {
SupervisedUserSyncService* sync_service = SupervisedUserSyncService* sync_service =
SupervisedUserSyncServiceFactory::GetForProfile(profile); SupervisedUserSyncServiceFactory::GetForProfile(profile);
if (sync_service) { if (sync_service) {
sync_service->AddObserver(this); supervised_user_sync_service_observer_.Add(sync_service);
signin_error_observer_.Add( signin_error_observer_.Add(
SigninErrorControllerFactory::GetForProfile(profile)); SigninErrorControllerFactory::GetForProfile(profile));
SupervisedUserSharedSettingsService* settings_service = SupervisedUserSharedSettingsService* settings_service =
......
...@@ -22,6 +22,7 @@ class ListValue; ...@@ -22,6 +22,7 @@ class ListValue;
} }
class ProfileInfoCache; class ProfileInfoCache;
class SupervisedUserSyncService;
namespace options { namespace options {
...@@ -100,6 +101,8 @@ class SupervisedUserImportHandler : public OptionsPageUIHandler, ...@@ -100,6 +101,8 @@ class SupervisedUserImportHandler : public OptionsPageUIHandler,
profile_observer_; profile_observer_;
ScopedObserver<SigninErrorController, SupervisedUserImportHandler> ScopedObserver<SigninErrorController, SupervisedUserImportHandler>
signin_error_observer_; signin_error_observer_;
ScopedObserver<SupervisedUserSyncService, SupervisedUserImportHandler>
supervised_user_sync_service_observer_;
bool removed_profile_is_supervised_; bool removed_profile_is_supervised_;
......
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