Commit dccffbfd authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_* from SiteSettingsHandler

Also remove obsolete NotificationService includes from
//chrome/browser/ui/webui/settings/

Bug: 268984
Change-Id: I2c5cf6e456965f6d98c844bf8c81c423add00c1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891737
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714504}
parent 2755ff97
......@@ -453,9 +453,9 @@ class Profile : public content::BrowserContext {
static PrefStore* CreateExtensionPrefStore(Profile*,
bool incognito_pref_store);
private:
void NotifyOffTheRecordProfileCreated(Profile* off_the_record);
private:
bool restored_last_session_;
// Used to prevent the notification that this Profile is destroyed from
......
......@@ -19,7 +19,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/camera_presence_notifier.h"
#include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
......@@ -39,7 +38,6 @@
#include "components/user_manager/user_image/user_image.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/url_constants.h"
#include "net/base/data_url.h"
......
......@@ -14,12 +14,10 @@
#include "ui/base/webui/web_ui_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/ui/webui/chromeos/user_image_source.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
#else
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_statistics.h"
......
......@@ -14,7 +14,6 @@
#include "base/value_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/gaia_info_update_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
......@@ -31,7 +30,6 @@
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "ui/base/l10n/l10n_util.h"
......
......@@ -17,7 +17,6 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/content_settings/web_site_settings_uma_util.h"
#include "chrome/browser/engagement/site_engagement_service.h"
......@@ -28,7 +27,6 @@
#include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/permissions/permission_uma_util.h"
#include "chrome/browser/permissions/permission_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/serial/serial_chooser_context.h"
#include "chrome/browser/serial/serial_chooser_context_factory.h"
#include "chrome/browser/ui/browser.h"
......@@ -50,7 +48,6 @@
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/origin_util.h"
......@@ -338,9 +335,7 @@ void LogAllSitesAction(AllSitesAction action) {
SiteSettingsHandler::SiteSettingsHandler(Profile* profile,
web_app::AppRegistrar& app_registrar)
: profile_(profile),
app_registrar_(app_registrar),
pref_change_registrar_(nullptr) {}
: profile_(profile), app_registrar_(app_registrar) {}
SiteSettingsHandler::~SiteSettingsHandler() {
if (cookies_tree_model_)
......@@ -452,11 +447,6 @@ void SiteSettingsHandler::OnJavascriptAllowed() {
if (profile_->HasOffTheRecordProfile())
ObserveSourcesForProfile(profile_->GetOffTheRecordProfile());
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
// Here we only subscribe to the HostZoomMap for the default storage partition
// since we don't allow the user to manage the zoom levels for apps.
// We're only interested in zoom-levels that are persisted, since the user
......@@ -487,12 +477,12 @@ void SiteSettingsHandler::OnJavascriptAllowed() {
void SiteSettingsHandler::OnJavascriptDisallowed() {
observer_.RemoveAll();
chooser_observer_.RemoveAll();
notification_registrar_.RemoveAll();
host_zoom_map_subscription_.reset();
pref_change_registrar_->Remove(prefs::kBlockAutoplayEnabled);
#if defined(OS_CHROMEOS)
pref_change_registrar_->Remove(prefs::kEnableDRM);
#endif
observed_profiles_.RemoveAll();
}
void SiteSettingsHandler::OnGetUsageInfo() {
......@@ -558,31 +548,16 @@ void SiteSettingsHandler::OnContentSettingChanged(
}
}
void SiteSettingsHandler::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
Profile* profile = content::Source<Profile>(source).ptr();
if (!profile_->IsSameProfile(profile))
break;
SendIncognitoStatus(profile, /*was_destroyed=*/true);
if (profile->IsOffTheRecord())
StopObservingSourcesForProfile(profile);
break;
}
case chrome::NOTIFICATION_PROFILE_CREATED: {
Profile* profile = content::Source<Profile>(source).ptr();
if (!profile_->IsSameProfile(profile))
break;
SendIncognitoStatus(profile, /*was_destroyed=*/false);
void SiteSettingsHandler::OnOffTheRecordProfileCreated(
Profile* off_the_record) {
FireWebUIListener("onIncognitoStatusChanged", base::Value(true));
ObserveSourcesForProfile(off_the_record);
}
ObserveSourcesForProfile(profile);
break;
}
}
void SiteSettingsHandler::OnProfileWillBeDestroyed(Profile* profile) {
if (profile->IsOffTheRecord())
FireWebUIListener("onIncognitoStatusChanged", base::Value(false));
StopObservingSourcesForProfile(profile);
}
void SiteSettingsHandler::OnChooserObjectPermissionChanged(
......@@ -1207,22 +1182,8 @@ void SiteSettingsHandler::HandleIsPatternValidForType(
void SiteSettingsHandler::HandleUpdateIncognitoStatus(
const base::ListValue* args) {
AllowJavascript();
SendIncognitoStatus(profile_, /*was_destroyed=*/false);
}
void SiteSettingsHandler::SendIncognitoStatus(Profile* profile,
bool was_destroyed) {
if (!IsJavascriptAllowed())
return;
// When an incognito profile is destroyed, it sends out the destruction
// message before destroying, so HasOffTheRecordProfile for profile_ won't
// return false until after the profile actually been destroyed.
bool incognito_enabled =
profile_->HasOffTheRecordProfile() &&
!(was_destroyed && profile == profile_->GetOffTheRecordProfile());
FireWebUIListener("onIncognitoStatusChanged", base::Value(incognito_enabled));
FireWebUIListener("onIncognitoStatusChanged",
base::Value(profile_->HasOffTheRecordProfile()));
}
void SiteSettingsHandler::HandleFetchZoomLevels(const base::ListValue* args) {
......@@ -1390,6 +1351,8 @@ void SiteSettingsHandler::ObserveSourcesForProfile(Profile* profile) {
auto* serial_context = SerialChooserContextFactory::GetForProfile(profile);
if (!chooser_observer_.IsObserving(serial_context))
chooser_observer_.Add(serial_context);
observed_profiles_.Add(profile);
}
void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) {
......@@ -1404,6 +1367,8 @@ void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) {
auto* serial_context = SerialChooserContextFactory::GetForProfile(profile);
if (chooser_observer_.IsObserving(serial_context))
chooser_observer_.Remove(serial_context);
observed_profiles_.Remove(profile);
}
void SiteSettingsHandler::TreeNodesAdded(ui::TreeModel* model,
......
......@@ -14,18 +14,16 @@
#include "base/scoped_observer.h"
#include "chrome/browser/browsing_data/cookies_tree_model.h"
#include "chrome/browser/permissions/chooser_context_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "components/content_settings/core/browser/content_settings_observer.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ppapi/buildflags/buildflags.h"
class Profile;
class PrefChangeRegistrar;
namespace base {
......@@ -37,7 +35,7 @@ namespace settings {
// Chrome "ContentSettings" settings page UI handler.
class SiteSettingsHandler : public SettingsPageUIHandler,
public content_settings::Observer,
public content::NotificationObserver,
public ProfileObserver,
public ChooserContextBase::PermissionObserver,
public CookiesTreeModel::Observer {
public:
......@@ -79,10 +77,9 @@ class SiteSettingsHandler : public SettingsPageUIHandler,
ContentSettingsType content_type,
const std::string& resource_identifier) override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileObserver:
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;
// ChooserContextBase::PermissionObserver implementation:
void OnChooserObjectPermissionChanged(
......@@ -246,7 +243,7 @@ class SiteSettingsHandler : public SettingsPageUIHandler,
Profile* profile_;
web_app::AppRegistrar& app_registrar_;
content::NotificationRegistrar notification_registrar_;
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
// Keeps track of events related to zooming.
std::unique_ptr<content::HostZoomMap::Subscription>
......
......@@ -19,7 +19,6 @@
#include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
#include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h"
#include "chrome/browser/browsing_data/mock_browsing_data_local_storage_helper.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
......@@ -48,7 +47,6 @@
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_ui.h"
......@@ -396,10 +394,6 @@ class SiteSettingsHandlerTest : public testing::Test {
}
virtual void DestroyIncognitoProfile() {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(static_cast<Profile*>(incognito_profile_)),
content::NotificationService::NoDetails());
profile_.SetOffTheRecordProfile(nullptr);
ASSERT_FALSE(profile_.HasOffTheRecordProfile());
incognito_profile_ = nullptr;
......
......@@ -545,6 +545,9 @@ void TestingProfile::FinishInit() {
// must be initialized when the testing profile finishes its initialization.
signin_util::EnsureUserSignoutAllowedIsInitializedForProfile(this);
}
if (original_profile_)
original_profile_->NotifyOffTheRecordProfileCreated(this);
}
TestingProfile::~TestingProfile() {
......
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