OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef APPS_APP_LIFETIME_MONITOR_H_ | 5 #ifndef APPS_APP_LIFETIME_MONITOR_H_ |
6 #define APPS_APP_LIFETIME_MONITOR_H_ | 6 #define APPS_APP_LIFETIME_MONITOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "apps/shell_window_registry.h" | 11 #include "apps/app_window_registry.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 class Extension; | 18 class Extension; |
19 } | 19 } |
20 | 20 |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 namespace apps { | 23 namespace apps { |
24 | 24 |
25 // Observes startup of apps and their windows and notifies observers of these | 25 // Observes startup of apps and their windows and notifies observers of these |
26 // events. | 26 // events. |
27 class AppLifetimeMonitor : public BrowserContextKeyedService, | 27 class AppLifetimeMonitor : public BrowserContextKeyedService, |
28 public content::NotificationObserver, | 28 public content::NotificationObserver, |
29 public ShellWindowRegistry::Observer { | 29 public AppWindowRegistry::Observer { |
30 public: | 30 public: |
31 class Observer { | 31 class Observer { |
32 public: | 32 public: |
33 // Called when the app starts running. | 33 // Called when the app starts running. |
34 virtual void OnAppStart(Profile* profile, const std::string& app_id) = 0; | 34 virtual void OnAppStart(Profile* profile, const std::string& app_id) = 0; |
35 // Called when the app becomes active to the user, i.e. it opens a window. | 35 // Called when the app becomes active to the user, i.e. it opens a window. |
36 virtual void OnAppActivated(Profile* profile, | 36 virtual void OnAppActivated(Profile* profile, |
37 const std::string& app_id) = 0; | 37 const std::string& app_id) = 0; |
38 // Called when the app becomes inactive to the user. | 38 // Called when the app becomes inactive to the user. |
39 virtual void OnAppDeactivated(Profile* profile, | 39 virtual void OnAppDeactivated(Profile* profile, |
(...skipping 14 matching lines...) Expand all Loading... |
54 | 54 |
55 void AddObserver(Observer* observer); | 55 void AddObserver(Observer* observer); |
56 void RemoveObserver(Observer* observer); | 56 void RemoveObserver(Observer* observer); |
57 | 57 |
58 private: | 58 private: |
59 // content::NotificationObserver overrides: | 59 // content::NotificationObserver overrides: |
60 virtual void Observe(int type, | 60 virtual void Observe(int type, |
61 const content::NotificationSource& source, | 61 const content::NotificationSource& source, |
62 const content::NotificationDetails& details) OVERRIDE; | 62 const content::NotificationDetails& details) OVERRIDE; |
63 | 63 |
64 // ShellWindowRegistry::Observer overrides: | 64 // AppWindowRegistry::Observer overrides: |
65 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; | 65 virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE; |
66 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE; | 66 virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE; |
67 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; | 67 virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE; |
68 | 68 |
69 // BrowserContextKeyedService overrides: | 69 // BrowserContextKeyedService overrides: |
70 virtual void Shutdown() OVERRIDE; | 70 virtual void Shutdown() OVERRIDE; |
71 | 71 |
72 void NotifyAppStart(const std::string& app_id); | 72 void NotifyAppStart(const std::string& app_id); |
73 void NotifyAppActivated(const std::string& app_id); | 73 void NotifyAppActivated(const std::string& app_id); |
74 void NotifyAppDeactivated(const std::string& app_id); | 74 void NotifyAppDeactivated(const std::string& app_id); |
75 void NotifyAppStop(const std::string& app_id); | 75 void NotifyAppStop(const std::string& app_id); |
76 void NotifyChromeTerminating(); | 76 void NotifyChromeTerminating(); |
77 | 77 |
78 content::NotificationRegistrar registrar_; | 78 content::NotificationRegistrar registrar_; |
79 Profile* profile_; | 79 Profile* profile_; |
80 ObserverList<Observer> observers_; | 80 ObserverList<Observer> observers_; |
81 | 81 |
82 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor); | 82 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor); |
83 }; | 83 }; |
84 | 84 |
85 } // namespace apps | 85 } // namespace apps |
86 | 86 |
87 #endif // APPS_APP_LIFETIME_MONITOR_H_ | 87 #endif // APPS_APP_LIFETIME_MONITOR_H_ |
OLD | NEW |