Skip to content

Commit

Permalink
Move NotificationObserver code out of ChromeShellDelegate
Browse files Browse the repository at this point in the history
There is no particular reason for this code to be part of the delegate.
This allows the code to run in Mash and Mus modes.

Bug: 665064
Change-Id: I0c9a7b1872f82b3487aa51412294b5baeea33b9b
Reviewed-on: https://chromium-review.googlesource.com/1071873
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561903}
  • Loading branch information
stevenjb authored and Commit Bot committed May 25, 2018
1 parent 0dbdf56 commit 7c3a331
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 64 deletions.
54 changes: 53 additions & 1 deletion chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
#include "ash/shell.h"
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/chromeos/night_light/night_light_client.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
#include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/ash/accessibility/accessibility_controller_client.h"
#include "chrome/browser/ui/ash/ash_shell_init.h"
Expand Down Expand Up @@ -50,6 +55,9 @@
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
Expand Down Expand Up @@ -128,7 +136,8 @@ class ChromeLauncherControllerInitializer

} // namespace internal

ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {}
ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh()
: notification_observer_(std::make_unique<NotificationObserver>()) {}

ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {}

Expand Down Expand Up @@ -308,3 +317,46 @@ void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
// ash::Shell is so destroy |tablet_mode_client_| after ash::Shell.
tablet_mode_client_.reset();
}

class ChromeBrowserMainExtraPartsAsh::NotificationObserver
: public content::NotificationObserver {
public:
NotificationObserver() {
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
}
~NotificationObserver() override = default;

// content::NotificationObserver
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
Profile* profile = content::Details<Profile>(details).ptr();
if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
!chromeos::ProfileHelper::IsLockScreenAppProfile(profile) &&
!profile->IsGuestSession() && !profile->IsSupervised()) {
// Start the error notifier services to show auth/sync notifications.
SigninErrorNotifierFactory::GetForProfile(profile);
SyncErrorNotifierFactory::GetForProfile(profile);
}
// Do not use chrome::NOTIFICATION_PROFILE_ADDED because the
// profile is not fully initialized by user_manager. Use
// chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED instead.
if (ChromeLauncherController::instance()) {
ChromeLauncherController::instance()->OnUserProfileReadyToSwitch(
profile);
}
break;
}
default:
NOTREACHED() << "Unexpected notification " << type;
}
}

private:
content::NotificationRegistrar registrar_;

DISALLOW_COPY_AND_ASSIGN(NotificationObserver);
};
4 changes: 4 additions & 0 deletions chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
void PostMainMessageLoopRun() override;

private:
class NotificationObserver;

std::unique_ptr<NotificationObserver> notification_observer_;

// Initialized in PreProfileInit in all configs before Shell init:
std::unique_ptr<NetworkConnectDelegateChromeOS> network_connect_delegate_;

Expand Down
50 changes: 0 additions & 50 deletions chrome/browser/ui/ash/chrome_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,19 @@
#include "ash/accessibility/accessibility_delegate.h"
#include "ash/public/cpp/accessibility_types.h"
#include "ash/screenshot_delegate.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/chromeos/arc/arc_web_contents_data.h"
#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/chromeos/policy/display_rotation_default_handler.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
#include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
#include "chrome/browser/ui/ash/chrome_keyboard_ui.h"
#include "chrome/browser/ui/ash/chrome_screenshot_grabber.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/network/networking_config_delegate_chromeos.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
Expand All @@ -45,16 +37,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/chromeos_switches.h"
#include "components/arc/intent_helper/page_transition_util.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/url_constants.h"
#include "services/ui/public/cpp/input_devices/input_device_controller_client.h"
Expand Down Expand Up @@ -110,7 +93,6 @@ class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
ChromeShellDelegate::ChromeShellDelegate()
: networking_config_delegate_(
std::make_unique<chromeos::NetworkingConfigDelegateChromeos>()) {
PlatformInit();
}

ChromeShellDelegate::~ChromeShellDelegate() {}
Expand Down Expand Up @@ -213,35 +195,3 @@ ui::InputDeviceControllerClient*
ChromeShellDelegate::GetInputDeviceControllerClient() {
return g_browser_process->platform_part()->GetInputDeviceControllerClient();
}

void ChromeShellDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
Profile* profile = content::Details<Profile>(details).ptr();
if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
!chromeos::ProfileHelper::IsLockScreenAppProfile(profile) &&
!profile->IsGuestSession() && !profile->IsSupervised()) {
// Start the error notifier services to show auth/sync notifications.
SigninErrorNotifierFactory::GetForProfile(profile);
SyncErrorNotifierFactory::GetForProfile(profile);
}
// Do not use chrome::NOTIFICATION_PROFILE_ADDED because the
// profile is not fully initialized by user_manager. Use
// chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED instead.
if (ChromeLauncherController::instance()) {
ChromeLauncherController::instance()->OnUserProfileReadyToSwitch(
profile);
}
break;
}
default:
NOTREACHED() << "Unexpected notification " << type;
}
}

void ChromeShellDelegate::PlatformInit() {
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
}
14 changes: 1 addition & 13 deletions chrome/browser/ui/ash/chrome_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
#include "ash/shell_delegate.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

namespace keyboard {
class KeyboardUI;
}

class ChromeShellDelegate : public ash::ShellDelegate,
public content::NotificationObserver {
class ChromeShellDelegate : public ash::ShellDelegate {
public:
ChromeShellDelegate();
~ChromeShellDelegate() override;
Expand All @@ -36,16 +33,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
void OpenKeyboardShortcutHelpPage() const override;
ui::InputDeviceControllerClient* GetInputDeviceControllerClient() override;

// content::NotificationObserver override:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;

private:
void PlatformInit();

content::NotificationRegistrar registrar_;

std::unique_ptr<ash::NetworkingConfigDelegate> networking_config_delegate_;

DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate);
Expand Down

0 comments on commit 7c3a331

Please sign in to comment.