Commit 815969c2 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NotificationService usage from arc_app_utils.cc

Bug: 268984
Change-Id: I49aa469198d7fe48d7d3cf10cc742499489decfb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876912Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708806}
parent 9f5c2806
......@@ -14,6 +14,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
......@@ -22,13 +23,13 @@
#include "base/synchronization/waitable_event.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/arc/arc_migration_guide_notification.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/boot_phase_monitor/arc_boot_phase_monitor_bridge.h"
#include "chrome/browser/chromeos/arc/notification/arc_supervision_transition_notification.h"
#include "chrome/browser/chromeos/arc/session/arc_session_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h"
#include "chrome/browser/ui/ash/launcher/arc_shelf_spinner_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
......@@ -43,10 +44,6 @@
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.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/browser/notification_source.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
......@@ -112,36 +109,10 @@ bool IsMouseOrTouchEventFromFlags(int event_flags) {
using AppLaunchObserverMap =
std::map<content::BrowserContext*, base::ObserverList<AppLaunchObserver>>;
AppLaunchObserverMap* GetAppLaunchObserverMap();
content::NotificationObserver* GetNotificationObserver() {
class ProfileDestroyedObserver : public content::NotificationObserver {
public:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override {
if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) {
GetAppLaunchObserverMap()->erase(
content::Source<Profile>(source).ptr());
}
}
};
static base::NoDestructor<ProfileDestroyedObserver> observer;
return observer.get();
}
AppLaunchObserverMap* GetAppLaunchObserverMap() {
static base::NoDestructor<
std::map<content::BrowserContext*, base::ObserverList<AppLaunchObserver>>>
instance;
static base::NoDestructor<content::NotificationRegistrar> registrar;
if (!registrar->IsRegistered(
GetNotificationObserver(), chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources())) {
registrar->Add(
GetNotificationObserver(), chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources());
}
return instance.get();
}
......@@ -712,10 +683,34 @@ bool IsArcAppSticky(const std::string& app_id, Profile* profile) {
void AddAppLaunchObserver(content::BrowserContext* context,
AppLaunchObserver* observer) {
class ProfileDestroyedObserver : public ProfileObserver {
public:
ProfileDestroyedObserver() = default;
~ProfileDestroyedObserver() override = default;
void Observe(Profile* profile) {
if (!observed_profiles_.IsObserving(profile))
observed_profiles_.Add(profile);
}
void OnProfileWillBeDestroyed(Profile* profile) override {
observed_profiles_.Remove(profile);
GetAppLaunchObserverMap()->erase(profile);
}
private:
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
DISALLOW_COPY_AND_ASSIGN(ProfileDestroyedObserver);
};
static base::NoDestructor<ProfileDestroyedObserver>
profile_destroyed_observer;
AppLaunchObserverMap* const map = GetAppLaunchObserverMap();
auto result =
map->emplace(std::piecewise_construct, std::forward_as_tuple(context),
std::forward_as_tuple());
profile_destroyed_observer->Observe(Profile::FromBrowserContext(context));
result.first->second.AddObserver(observer);
}
......
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