| 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/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/notification_details.h" | 10 #include "content/public/browser/notification_details.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 #include "extensions/browser/extension_host.h" | 12 #include "extensions/browser/extension_host.h" |
| 13 #include "extensions/browser/notification_types.h" |
| 13 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 14 | 15 |
| 15 namespace apps { | 16 namespace apps { |
| 16 | 17 |
| 17 using extensions::Extension; | 18 using extensions::Extension; |
| 18 using extensions::ExtensionHost; | 19 using extensions::ExtensionHost; |
| 19 | 20 |
| 20 AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile) | 21 AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile) |
| 21 : profile_(profile) { | 22 : profile_(profile) { |
| 22 registrar_.Add( | 23 registrar_.Add(this, |
| 23 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 24 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 24 content::NotificationService::AllSources()); | 25 content::NotificationService::AllSources()); |
| 25 registrar_.Add( | 26 registrar_.Add(this, |
| 26 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 27 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 27 content::NotificationService::AllSources()); | 28 content::NotificationService::AllSources()); |
| 28 registrar_.Add( | 29 registrar_.Add( |
| 29 this, chrome::NOTIFICATION_APP_TERMINATING, | 30 this, chrome::NOTIFICATION_APP_TERMINATING, |
| 30 content::NotificationService::AllSources()); | 31 content::NotificationService::AllSources()); |
| 31 | 32 |
| 32 AppWindowRegistry* app_window_registry = | 33 AppWindowRegistry* app_window_registry = |
| 33 AppWindowRegistry::Factory::GetForBrowserContext(profile_, | 34 AppWindowRegistry::Factory::GetForBrowserContext(profile_, |
| 34 false /* create */); | 35 false /* create */); |
| 35 DCHECK(app_window_registry); | 36 DCHECK(app_window_registry); |
| 36 app_window_registry->AddObserver(this); | 37 app_window_registry->AddObserver(this); |
| 37 } | 38 } |
| 38 | 39 |
| 39 AppLifetimeMonitor::~AppLifetimeMonitor() {} | 40 AppLifetimeMonitor::~AppLifetimeMonitor() {} |
| 40 | 41 |
| 41 void AppLifetimeMonitor::AddObserver(Observer* observer) { | 42 void AppLifetimeMonitor::AddObserver(Observer* observer) { |
| 42 observers_.AddObserver(observer); | 43 observers_.AddObserver(observer); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void AppLifetimeMonitor::RemoveObserver(Observer* observer) { | 46 void AppLifetimeMonitor::RemoveObserver(Observer* observer) { |
| 46 observers_.RemoveObserver(observer); | 47 observers_.RemoveObserver(observer); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void AppLifetimeMonitor::Observe(int type, | 50 void AppLifetimeMonitor::Observe(int type, |
| 50 const content::NotificationSource& source, | 51 const content::NotificationSource& source, |
| 51 const content::NotificationDetails& details) { | 52 const content::NotificationDetails& details) { |
| 52 switch (type) { | 53 switch (type) { |
| 53 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 54 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
| 54 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 55 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 55 const Extension* extension = host->extension(); | 56 const Extension* extension = host->extension(); |
| 56 if (!extension || !extension->is_platform_app()) | 57 if (!extension || !extension->is_platform_app()) |
| 57 return; | 58 return; |
| 58 | 59 |
| 59 NotifyAppStart(extension->id()); | 60 NotifyAppStart(extension->id()); |
| 60 break; | 61 break; |
| 61 } | 62 } |
| 62 | 63 |
| 63 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 64 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 64 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 65 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 65 const Extension* extension = host->extension(); | 66 const Extension* extension = host->extension(); |
| 66 if (!extension || !extension->is_platform_app()) | 67 if (!extension || !extension->is_platform_app()) |
| 67 return; | 68 return; |
| 68 | 69 |
| 69 NotifyAppStop(extension->id()); | 70 NotifyAppStop(extension->id()); |
| 70 break; | 71 break; |
| 71 } | 72 } |
| 72 | 73 |
| 73 case chrome::NOTIFICATION_APP_TERMINATING: { | 74 case chrome::NOTIFICATION_APP_TERMINATING: { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 void AppLifetimeMonitor::NotifyAppStop(const std::string& app_id) { | 133 void AppLifetimeMonitor::NotifyAppStop(const std::string& app_id) { |
| 133 FOR_EACH_OBSERVER(Observer, observers_, OnAppStop(profile_, app_id)); | 134 FOR_EACH_OBSERVER(Observer, observers_, OnAppStop(profile_, app_id)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void AppLifetimeMonitor::NotifyChromeTerminating() { | 137 void AppLifetimeMonitor::NotifyChromeTerminating() { |
| 137 FOR_EACH_OBSERVER(Observer, observers_, OnChromeTerminating()); | 138 FOR_EACH_OBSERVER(Observer, observers_, OnChromeTerminating()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 } // namespace apps | 141 } // namespace apps |
| OLD | NEW |