| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_restore_service.h" | 5 #include "apps/app_restore_service.h" |
| 6 | 6 |
| 7 #include "apps/app_lifetime_monitor_factory.h" | 7 #include "apps/app_lifetime_monitor_factory.h" |
| 8 #include "apps/app_restore_service_factory.h" | 8 #include "apps/app_restore_service_factory.h" |
| 9 #include "apps/launcher.h" | 9 #include "apps/launcher.h" |
| 10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 extension); | 59 extension); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool AppRestoreService::IsAppRestorable(const std::string& extension_id) { | 65 bool AppRestoreService::IsAppRestorable(const std::string& extension_id) { |
| 66 return ExtensionPrefs::Get(profile_)->IsExtensionRunning(extension_id); | 66 return ExtensionPrefs::Get(profile_)->IsExtensionRunning(extension_id); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void AppRestoreService::OnApplicationTerminating() { |
| 70 // We want to preserve the state when the app begins terminating, so stop |
| 71 // listening to app lifetime events. |
| 72 StopObservingAppLifetime(); |
| 73 } |
| 74 |
| 69 // static | 75 // static |
| 70 AppRestoreService* AppRestoreService::Get(Profile* profile) { | 76 AppRestoreService* AppRestoreService::Get(Profile* profile) { |
| 71 return apps::AppRestoreServiceFactory::GetForProfile(profile); | 77 return apps::AppRestoreServiceFactory::GetForProfile(profile); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void AppRestoreService::OnAppStart(Profile* profile, | 80 void AppRestoreService::OnAppStart(Profile* profile, |
| 75 const std::string& app_id) { | 81 const std::string& app_id) { |
| 76 RecordAppStart(app_id); | 82 RecordAppStart(app_id); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void AppRestoreService::OnAppActivated(Profile* profile, | 85 void AppRestoreService::OnAppActivated(Profile* profile, |
| 80 const std::string& app_id) { | 86 const std::string& app_id) { |
| 81 RecordAppActiveState(app_id, true); | 87 RecordAppActiveState(app_id, true); |
| 82 } | 88 } |
| 83 | 89 |
| 84 void AppRestoreService::OnAppDeactivated(Profile* profile, | 90 void AppRestoreService::OnAppDeactivated(Profile* profile, |
| 85 const std::string& app_id) { | 91 const std::string& app_id) { |
| 86 RecordAppActiveState(app_id, false); | 92 RecordAppActiveState(app_id, false); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void AppRestoreService::OnAppStop(Profile* profile, const std::string& app_id) { | 95 void AppRestoreService::OnAppStop(Profile* profile, const std::string& app_id) { |
| 90 RecordAppStop(app_id); | 96 RecordAppStop(app_id); |
| 91 } | 97 } |
| 92 | 98 |
| 93 void AppRestoreService::OnChromeTerminating() { | |
| 94 // We want to preserve the state when the app begins terminating, so stop | |
| 95 // listening to app lifetime events. | |
| 96 StopObservingAppLifetime(); | |
| 97 } | |
| 98 | |
| 99 void AppRestoreService::Shutdown() { | 99 void AppRestoreService::Shutdown() { |
| 100 StopObservingAppLifetime(); | 100 StopObservingAppLifetime(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void AppRestoreService::RecordAppStart(const std::string& extension_id) { | 103 void AppRestoreService::RecordAppStart(const std::string& extension_id) { |
| 104 ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, true); | 104 ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, true); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AppRestoreService::RecordAppStop(const std::string& extension_id) { | 107 void AppRestoreService::RecordAppStop(const std::string& extension_id) { |
| 108 ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, false); | 108 ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, false); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 133 | 133 |
| 134 void AppRestoreService::StopObservingAppLifetime() { | 134 void AppRestoreService::StopObservingAppLifetime() { |
| 135 AppLifetimeMonitor* app_lifetime_monitor = | 135 AppLifetimeMonitor* app_lifetime_monitor = |
| 136 AppLifetimeMonitorFactory::GetForProfile(profile_); | 136 AppLifetimeMonitorFactory::GetForProfile(profile_); |
| 137 // This might be NULL in tests. | 137 // This might be NULL in tests. |
| 138 if (app_lifetime_monitor) | 138 if (app_lifetime_monitor) |
| 139 app_lifetime_monitor->RemoveObserver(this); | 139 app_lifetime_monitor->RemoveObserver(this); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace apps | 142 } // namespace apps |
| OLD | NEW |