diff options
author | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 13:38:37 +0000 |
---|---|---|
committer | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 13:38:37 +0000 |
commit | d54b3f490de80c708e335714872e44eba322342b (patch) | |
tree | 08b3bb2e4312da05091229947ca82b1e1655c94f /apps/app_lifetime_monitor.h | |
parent | e34d51130d3026bf2fb6501264b1c761cfa48a18 (diff) | |
download | chromium_src-d54b3f490de80c708e335714872e44eba322342b.zip chromium_src-d54b3f490de80c708e335714872e44eba322342b.tar.gz chromium_src-d54b3f490de80c708e335714872e44eba322342b.tar.bz2 |
Factor out AppLifetimeMonitor.
AppLifetimeMonitor listens to extension host notifications and observes
ShellWindowRegistry. It sends out notifications when:
- an app starts
- the first shell window opens
- the last shell window closes
- the app stops
BUG=
Review URL: https://chromiumcodereview.appspot.com/16412002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204487 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps/app_lifetime_monitor.h')
-rw-r--r-- | apps/app_lifetime_monitor.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/apps/app_lifetime_monitor.h b/apps/app_lifetime_monitor.h new file mode 100644 index 0000000..00c1ccc --- /dev/null +++ b/apps/app_lifetime_monitor.h @@ -0,0 +1,82 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPS_APP_LIFETIME_MONITOR_H_ +#define APPS_APP_LIFETIME_MONITOR_H_ + +#include <string> +#include <vector> + +#include "base/observer_list.h" +#include "chrome/browser/extensions/shell_window_registry.h" +#include "components/browser_context_keyed_service/browser_context_keyed_service.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +namespace extensions { +class Extension; +} + +class Profile; + +namespace apps { + +// Observes startup of apps and their windows and notifies observers of these +// events. +class AppLifetimeMonitor : public BrowserContextKeyedService, + public content::NotificationObserver, + public extensions::ShellWindowRegistry::Observer { + public: + class Observer { + public: + // Called when the app starts running. + virtual void OnAppStart(Profile* profile, const std::string& app_id) = 0; + // Called when the app becomes active to the user, i.e. it opens a window. + virtual void OnAppActivated(Profile* profile, + const std::string& app_id) = 0; + // Called when the app becomes inactive to the user. + virtual void OnAppDeactivated(Profile* profile, + const std::string& app_id) = 0; + // Called when the app stops running. + virtual void OnAppStop(Profile* profile, const std::string& app_id) = 0; + + protected: + virtual ~Observer() {} + }; + + explicit AppLifetimeMonitor(Profile* profile); + virtual ~AppLifetimeMonitor(); + + void AddObserver(Observer* observer); + void RemoveObserver(Observer* observer); + + private: + // content::NotificationObserver overrides: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // extensions::ShellWindowRegistry::Observer overrides: + virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; + + // BrowserContextKeyedService overrides: + virtual void Shutdown() OVERRIDE; + + void NotifyAppStart(const std::string& app_id); + void NotifyAppActivated(const std::string& app_id); + void NotifyAppDeactivated(const std::string& app_id); + void NotifyAppStop(const std::string& app_id); + + content::NotificationRegistrar registrar_; + Profile* profile_; + ObserverList<Observer> observers_; + + DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor); +}; + +} // namespace apps + +#endif // APPS_APP_LIFETIME_MONITOR_H_ |