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 #include "apps/app_lifetime_monitor.h" | 5 #include "apps/app_lifetime_monitor.h" |
6 | 6 |
7 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
11 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
12 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
13 | 14 |
14 namespace apps { | 15 namespace apps { |
15 | 16 |
16 using extensions::Extension; | 17 using extensions::Extension; |
17 using extensions::ExtensionHost; | 18 using extensions::ExtensionHost; |
18 | 19 |
19 AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile) | 20 AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile) |
20 : profile_(profile) { | 21 : profile_(profile) { |
21 registrar_.Add( | 22 registrar_.Add( |
22 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 23 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
23 content::NotificationService::AllSources()); | 24 content::NotificationService::AllSources()); |
24 registrar_.Add( | 25 registrar_.Add( |
25 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 26 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
26 content::NotificationService::AllSources()); | 27 content::NotificationService::AllSources()); |
27 registrar_.Add( | 28 registrar_.Add( |
28 this, chrome::NOTIFICATION_APP_TERMINATING, | 29 this, chrome::NOTIFICATION_APP_TERMINATING, |
29 content::NotificationService::AllSources()); | 30 content::NotificationService::AllSources()); |
30 | 31 |
31 ShellWindowRegistry* shell_window_registry = | 32 ShellWindowRegistry* shell_window_registry = |
32 ShellWindowRegistry::Factory::GetForProfile( | 33 ShellWindowRegistry::Factory::GetForBrowserContext( |
33 profile_, false /* create */); | 34 profile_, false /* create */); |
34 DCHECK(shell_window_registry); | 35 DCHECK(shell_window_registry); |
35 shell_window_registry->AddObserver(this); | 36 shell_window_registry->AddObserver(this); |
36 } | 37 } |
37 | 38 |
38 AppLifetimeMonitor::~AppLifetimeMonitor() {} | 39 AppLifetimeMonitor::~AppLifetimeMonitor() {} |
39 | 40 |
40 void AppLifetimeMonitor::AddObserver(Observer* observer) { | 41 void AppLifetimeMonitor::AddObserver(Observer* observer) { |
41 observers_.AddObserver(observer); | 42 observers_.AddObserver(observer); |
42 } | 43 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void AppLifetimeMonitor::OnShellWindowRemoved(ShellWindow* shell_window) { | 93 void AppLifetimeMonitor::OnShellWindowRemoved(ShellWindow* shell_window) { |
93 ShellWindowRegistry::ShellWindowList windows = | 94 ShellWindowRegistry::ShellWindowList windows = |
94 ShellWindowRegistry::Get(shell_window->profile())-> | 95 ShellWindowRegistry::Get(shell_window->profile())-> |
95 GetShellWindowsForApp(shell_window->extension_id()); | 96 GetShellWindowsForApp(shell_window->extension_id()); |
96 if (windows.empty()) | 97 if (windows.empty()) |
97 NotifyAppDeactivated(shell_window->extension_id()); | 98 NotifyAppDeactivated(shell_window->extension_id()); |
98 } | 99 } |
99 | 100 |
100 void AppLifetimeMonitor::Shutdown() { | 101 void AppLifetimeMonitor::Shutdown() { |
101 ShellWindowRegistry* shell_window_registry = | 102 ShellWindowRegistry* shell_window_registry = |
102 ShellWindowRegistry::Factory::GetForProfile( | 103 ShellWindowRegistry::Factory::GetForBrowserContext( |
103 profile_, false /* create */); | 104 profile_, false /* create */); |
104 if (shell_window_registry) | 105 if (shell_window_registry) |
105 shell_window_registry->RemoveObserver(this); | 106 shell_window_registry->RemoveObserver(this); |
106 } | 107 } |
107 | 108 |
108 void AppLifetimeMonitor::NotifyAppStart(const std::string& app_id) { | 109 void AppLifetimeMonitor::NotifyAppStart(const std::string& app_id) { |
109 FOR_EACH_OBSERVER(Observer, observers_, OnAppStart(profile_, app_id)); | 110 FOR_EACH_OBSERVER(Observer, observers_, OnAppStart(profile_, app_id)); |
110 } | 111 } |
111 | 112 |
112 void AppLifetimeMonitor::NotifyAppActivated(const std::string& app_id) { | 113 void AppLifetimeMonitor::NotifyAppActivated(const std::string& app_id) { |
113 FOR_EACH_OBSERVER(Observer, observers_, OnAppActivated(profile_, app_id)); | 114 FOR_EACH_OBSERVER(Observer, observers_, OnAppActivated(profile_, app_id)); |
114 } | 115 } |
115 | 116 |
116 void AppLifetimeMonitor::NotifyAppDeactivated(const std::string& app_id) { | 117 void AppLifetimeMonitor::NotifyAppDeactivated(const std::string& app_id) { |
117 FOR_EACH_OBSERVER(Observer, observers_, OnAppDeactivated(profile_, app_id)); | 118 FOR_EACH_OBSERVER(Observer, observers_, OnAppDeactivated(profile_, app_id)); |
118 } | 119 } |
119 | 120 |
120 void AppLifetimeMonitor::NotifyAppStop(const std::string& app_id) { | 121 void AppLifetimeMonitor::NotifyAppStop(const std::string& app_id) { |
121 FOR_EACH_OBSERVER(Observer, observers_, OnAppStop(profile_, app_id)); | 122 FOR_EACH_OBSERVER(Observer, observers_, OnAppStop(profile_, app_id)); |
122 } | 123 } |
123 | 124 |
124 void AppLifetimeMonitor::NotifyChromeTerminating() { | 125 void AppLifetimeMonitor::NotifyChromeTerminating() { |
125 FOR_EACH_OBSERVER(Observer, observers_, OnChromeTerminating()); | 126 FOR_EACH_OBSERVER(Observer, observers_, OnChromeTerminating()); |
126 } | 127 } |
127 | 128 |
128 } // namespace apps | 129 } // namespace apps |
OLD | NEW |