-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
+#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
+#include "base/scoped_observation.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/extension_host_registry.h"
namespace content {
class BrowserContext;
// Observes startup of apps and their windows and notifies observers of these
// events.
class AppLifetimeMonitor : public KeyedService,
- public content::NotificationObserver,
- public extensions::AppWindowRegistry::Observer {
+ public extensions::AppWindowRegistry::Observer,
+ public extensions::ExtensionHostRegistry::Observer {
public:
class Observer {
public:
const std::string& app_id) {}
protected:
- virtual ~Observer() {}
+ virtual ~Observer() = default;
};
explicit AppLifetimeMonitor(content::BrowserContext* context);
+ AppLifetimeMonitor(const AppLifetimeMonitor&) = delete;
+ AppLifetimeMonitor& operator=(const AppLifetimeMonitor&) = delete;
~AppLifetimeMonitor() override;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
- // content::NotificationObserver overrides:
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
// extensions::AppWindowRegistry::Observer overrides:
void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
void OnAppWindowHidden(extensions::AppWindow* app_window) override;
void OnAppWindowShown(extensions::AppWindow* app_window,
bool was_hidden) override;
+ // extensions::ExtensionHostRegistry::Observer:
+ void OnExtensionHostCompletedFirstLoad(
+ content::BrowserContext* browser_context,
+ extensions::ExtensionHost* host) override;
+ void OnExtensionHostDestroyed(content::BrowserContext* browser_context,
+ extensions::ExtensionHost* host) override;
+
// KeyedService overrides:
void Shutdown() override;
void NotifyAppDeactivated(const std::string& app_id);
void NotifyAppStop(const std::string& app_id);
- content::NotificationRegistrar registrar_;
- content::BrowserContext* context_;
+ raw_ptr<content::BrowserContext> context_;
base::ObserverList<Observer>::Unchecked observers_;
-
- DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
+ base::ScopedObservation<extensions::ExtensionHostRegistry,
+ extensions::ExtensionHostRegistry::Observer>
+ extension_host_registry_observation_{this};
};
} // namespace apps