Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: apps/app_restore_service.cc

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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());
74 // On a Chrome restart, restore the running apps. Otherwise, on startup,
koz (OOO until 15th September) 2013/05/23 07:32:22 I know Matt asked for this comment but I think it'
Matt Giuca 2013/05/24 00:24:02 OK I agree we shouldn't assume why the caller set
koz (OOO until 15th September) 2013/05/24 00:28:44 I love it!
Sam McNally 2013/05/24 00:46:03 Done.
75 // flush the retained file entries.
78 if (should_restore_apps) 76 if (should_restore_apps)
79 RestoreApp(*it, file_entries); 77 RestoreApp(*it);
78 else
79 SavedFilesService::Get(profile_)->MaybeClearQueue(extension);
80 } 80 }
81 } 81 }
82 } 82 }
83 83
84 void AppRestoreService::Observe(int type, 84 void AppRestoreService::Observe(int type,
85 const content::NotificationSource& source, 85 const content::NotificationSource& source,
86 const content::NotificationDetails& details) { 86 const content::NotificationDetails& details) {
87 switch (type) { 87 switch (type) {
88 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { 88 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
89 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 89 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void AppRestoreService::RecordAppStart(const std::string& extension_id) { 131 void AppRestoreService::RecordAppStart(const std::string& extension_id) {
132 ExtensionPrefs* extension_prefs = 132 ExtensionPrefs* extension_prefs =
133 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); 133 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
134 extension_prefs->SetExtensionRunning(extension_id, true); 134 extension_prefs->SetExtensionRunning(extension_id, true);
135 } 135 }
136 136
137 void AppRestoreService::RecordAppStop(const std::string& extension_id) { 137 void AppRestoreService::RecordAppStop(const std::string& extension_id) {
138 ExtensionPrefs* extension_prefs = 138 ExtensionPrefs* extension_prefs =
139 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); 139 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
140 extension_prefs->SetExtensionRunning(extension_id, false); 140 extension_prefs->SetExtensionRunning(extension_id, false);
141 extensions::app_file_handler_util::ClearSavedFileEntries(
142 extension_prefs, extension_id);
143 } 141 }
144 142
145 void AppRestoreService::RecordIfAppHasWindows( 143 void AppRestoreService::RecordIfAppHasWindows(
146 const std::string& id) { 144 const std::string& id) {
147 ExtensionService* extension_service = 145 ExtensionService* extension_service =
148 ExtensionSystem::Get(profile_)->extension_service(); 146 ExtensionSystem::Get(profile_)->extension_service();
149 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); 147 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
150 148
151 // If the extension isn't running then we will already have recorded whether 149 // If the extension isn't running then we will already have recorded whether
152 // it had windows or not. 150 // it had windows or not.
153 if (!extension_prefs->IsExtensionRunning(id)) 151 if (!extension_prefs->IsExtensionRunning(id))
154 return; 152 return;
155 153
156 extensions::ShellWindowRegistry* shell_window_registry = 154 extensions::ShellWindowRegistry* shell_window_registry =
157 extensions::ShellWindowRegistry::Factory::GetForProfile( 155 extensions::ShellWindowRegistry::Factory::GetForProfile(
158 profile_, false /* create */); 156 profile_, false /* create */);
159 if (!shell_window_registry) 157 if (!shell_window_registry)
160 return; 158 return;
161 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty(); 159 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty();
162 extension_prefs->SetHasWindows(id, has_windows); 160 extension_prefs->SetHasWindows(id, has_windows);
163 } 161 }
164 162
165 void AppRestoreService::RestoreApp( 163 void AppRestoreService::RestoreApp(const Extension* extension) {
166 const Extension* extension, 164 extensions::RestartPlatformApp(profile_, extension);
167 const std::vector<SavedFileEntry>& file_entries) {
168 extensions::RestartPlatformAppWithFileEntries(profile_,
169 extension,
170 file_entries);
171 } 165 }
172 166
173 void AppRestoreService::StartObservingShellWindows() { 167 void AppRestoreService::StartObservingShellWindows() {
174 extensions::ShellWindowRegistry* shell_window_registry = 168 extensions::ShellWindowRegistry* shell_window_registry =
175 extensions::ShellWindowRegistry::Factory::GetForProfile( 169 extensions::ShellWindowRegistry::Factory::GetForProfile(
176 profile_, false /* create */); 170 profile_, false /* create */);
177 if (shell_window_registry) 171 if (shell_window_registry)
178 shell_window_registry->AddObserver(this); 172 shell_window_registry->AddObserver(this);
179 } 173 }
180 174
181 void AppRestoreService::StopObservingShellWindows() { 175 void AppRestoreService::StopObservingShellWindows() {
182 extensions::ShellWindowRegistry* shell_window_registry = 176 extensions::ShellWindowRegistry* shell_window_registry =
183 extensions::ShellWindowRegistry::Factory::GetForProfile( 177 extensions::ShellWindowRegistry::Factory::GetForProfile(
184 profile_, false /* create */); 178 profile_, false /* create */);
185 if (shell_window_registry) 179 if (shell_window_registry)
186 shell_window_registry->RemoveObserver(this); 180 shell_window_registry->RemoveObserver(this);
187 } 181 }
188 182
189 } // namespace apps 183 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698