Chromium Code Reviews| 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/saved_files_service.h" | |
| 7 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" | 8 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
| 8 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | |
| 9 #include "chrome/browser/extensions/event_router.h" | 9 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/platform_app_launcher.h" | 14 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 15 #include "chrome/browser/ui/extensions/shell_window.h" | 15 #include "chrome/browser/ui/extensions/shell_window.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_set.h" | 18 #include "chrome/common/extensions/extension_set.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 void AppRestoreService::HandleStartup(bool should_restore_apps) { | 63 void AppRestoreService::HandleStartup(bool should_restore_apps) { |
| 64 ExtensionService* extension_service = | 64 ExtensionService* extension_service = |
| 65 ExtensionSystem::Get(profile_)->extension_service(); | 65 ExtensionSystem::Get(profile_)->extension_service(); |
| 66 const ExtensionSet* extensions = extension_service->extensions(); | 66 const ExtensionSet* extensions = extension_service->extensions(); |
| 67 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); | 67 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); |
| 68 | 68 |
| 69 for (ExtensionSet::const_iterator it = extensions->begin(); | 69 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 70 it != extensions->end(); ++it) { | 70 it != extensions->end(); ++it) { |
| 71 const Extension* extension = *it; | 71 const Extension* extension = *it; |
| 72 if (extension_prefs->IsExtensionRunning(extension->id())) { | 72 if (extension_prefs->IsExtensionRunning(extension->id())) { |
| 73 std::vector<SavedFileEntry> file_entries; | |
| 74 extensions::app_file_handler_util::GetSavedFileEntries(extension_prefs, | |
| 75 extension->id(), | |
| 76 &file_entries); | |
| 77 RecordAppStop(extension->id()); | 73 RecordAppStop(extension->id()); |
| 78 if (should_restore_apps) | 74 if (should_restore_apps) |
|
Matt Giuca
2013/05/20 01:32:57
Not your fault, but can you please add a comment h
Sam McNally
2013/05/20 04:25:20
Done.
| |
| 79 RestoreApp(*it, file_entries); | 75 RestoreApp(*it); |
| 76 else | |
| 77 SavedFilesService::Get(profile_)->ClearRetainedFiles(extension); | |
| 80 } | 78 } |
| 81 } | 79 } |
| 82 } | 80 } |
| 83 | 81 |
| 84 void AppRestoreService::Observe(int type, | 82 void AppRestoreService::Observe(int type, |
| 85 const content::NotificationSource& source, | 83 const content::NotificationSource& source, |
| 86 const content::NotificationDetails& details) { | 84 const content::NotificationDetails& details) { |
| 87 switch (type) { | 85 switch (type) { |
| 88 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 86 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
| 89 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 87 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 void AppRestoreService::RecordAppStart(const std::string& extension_id) { | 129 void AppRestoreService::RecordAppStart(const std::string& extension_id) { |
| 132 ExtensionPrefs* extension_prefs = | 130 ExtensionPrefs* extension_prefs = |
| 133 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | 131 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
| 134 extension_prefs->SetExtensionRunning(extension_id, true); | 132 extension_prefs->SetExtensionRunning(extension_id, true); |
| 135 } | 133 } |
| 136 | 134 |
| 137 void AppRestoreService::RecordAppStop(const std::string& extension_id) { | 135 void AppRestoreService::RecordAppStop(const std::string& extension_id) { |
| 138 ExtensionPrefs* extension_prefs = | 136 ExtensionPrefs* extension_prefs = |
| 139 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | 137 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
| 140 extension_prefs->SetExtensionRunning(extension_id, false); | 138 extension_prefs->SetExtensionRunning(extension_id, false); |
| 141 extensions::app_file_handler_util::ClearSavedFileEntries( | |
| 142 extension_prefs, extension_id); | |
| 143 } | 139 } |
| 144 | 140 |
| 145 void AppRestoreService::RecordIfAppHasWindows( | 141 void AppRestoreService::RecordIfAppHasWindows( |
| 146 const std::string& id) { | 142 const std::string& id) { |
| 147 ExtensionService* extension_service = | 143 ExtensionService* extension_service = |
| 148 ExtensionSystem::Get(profile_)->extension_service(); | 144 ExtensionSystem::Get(profile_)->extension_service(); |
| 149 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); | 145 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); |
| 150 | 146 |
| 151 // If the extension isn't running then we will already have recorded whether | 147 // If the extension isn't running then we will already have recorded whether |
| 152 // it had windows or not. | 148 // it had windows or not. |
| 153 if (!extension_prefs->IsExtensionRunning(id)) | 149 if (!extension_prefs->IsExtensionRunning(id)) |
| 154 return; | 150 return; |
| 155 | 151 |
| 156 extensions::ShellWindowRegistry* shell_window_registry = | 152 extensions::ShellWindowRegistry* shell_window_registry = |
| 157 extensions::ShellWindowRegistry::Factory::GetForProfile( | 153 extensions::ShellWindowRegistry::Factory::GetForProfile( |
| 158 profile_, false /* create */); | 154 profile_, false /* create */); |
| 159 if (!shell_window_registry) | 155 if (!shell_window_registry) |
| 160 return; | 156 return; |
| 161 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty(); | 157 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty(); |
| 162 extension_prefs->SetHasWindows(id, has_windows); | 158 extension_prefs->SetHasWindows(id, has_windows); |
| 163 } | 159 } |
| 164 | 160 |
| 165 void AppRestoreService::RestoreApp( | 161 void AppRestoreService::RestoreApp(const Extension* extension) { |
| 166 const Extension* extension, | 162 extensions::RestartPlatformApp(profile_, extension); |
| 167 const std::vector<SavedFileEntry>& file_entries) { | |
| 168 extensions::RestartPlatformAppWithFileEntries(profile_, | |
| 169 extension, | |
| 170 file_entries); | |
| 171 } | 163 } |
| 172 | 164 |
| 173 void AppRestoreService::StartObservingShellWindows() { | 165 void AppRestoreService::StartObservingShellWindows() { |
| 174 extensions::ShellWindowRegistry* shell_window_registry = | 166 extensions::ShellWindowRegistry* shell_window_registry = |
| 175 extensions::ShellWindowRegistry::Factory::GetForProfile( | 167 extensions::ShellWindowRegistry::Factory::GetForProfile( |
| 176 profile_, false /* create */); | 168 profile_, false /* create */); |
| 177 if (shell_window_registry) | 169 if (shell_window_registry) |
| 178 shell_window_registry->AddObserver(this); | 170 shell_window_registry->AddObserver(this); |
| 179 } | 171 } |
| 180 | 172 |
| 181 void AppRestoreService::StopObservingShellWindows() { | 173 void AppRestoreService::StopObservingShellWindows() { |
| 182 extensions::ShellWindowRegistry* shell_window_registry = | 174 extensions::ShellWindowRegistry* shell_window_registry = |
| 183 extensions::ShellWindowRegistry::Factory::GetForProfile( | 175 extensions::ShellWindowRegistry::Factory::GetForProfile( |
| 184 profile_, false /* create */); | 176 profile_, false /* create */); |
| 185 if (shell_window_registry) | 177 if (shell_window_registry) |
| 186 shell_window_registry->RemoveObserver(this); | 178 shell_window_registry->RemoveObserver(this); |
| 187 } | 179 } |
| 188 | 180 |
| 189 } // namespace apps | 181 } // namespace apps |
| OLD | NEW |