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

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: rebase 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
« no previous file with comments | « apps/app_restore_service.h ('k') | apps/app_restore_service_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
78 if (should_restore_apps) 74 // If we are not restoring apps (e.g., because it is a clean restart), and
79 RestoreApp(*it, file_entries); 75 // the app does not have retain permission, explicitly clear the retained
76 // entries queue.
77 if (should_restore_apps) {
78 RestoreApp(*it);
79 } else {
80 SavedFilesService::Get(profile_)->ClearQueueIfNoRetainPermission(
81 extension);
82 }
80 } 83 }
81 } 84 }
82 } 85 }
83 86
84 void AppRestoreService::Observe(int type, 87 void AppRestoreService::Observe(int type,
85 const content::NotificationSource& source, 88 const content::NotificationSource& source,
86 const content::NotificationDetails& details) { 89 const content::NotificationDetails& details) {
87 switch (type) { 90 switch (type) {
88 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { 91 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
89 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 92 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) { 134 void AppRestoreService::RecordAppStart(const std::string& extension_id) {
132 ExtensionPrefs* extension_prefs = 135 ExtensionPrefs* extension_prefs =
133 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); 136 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
134 extension_prefs->SetExtensionRunning(extension_id, true); 137 extension_prefs->SetExtensionRunning(extension_id, true);
135 } 138 }
136 139
137 void AppRestoreService::RecordAppStop(const std::string& extension_id) { 140 void AppRestoreService::RecordAppStop(const std::string& extension_id) {
138 ExtensionPrefs* extension_prefs = 141 ExtensionPrefs* extension_prefs =
139 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); 142 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
140 extension_prefs->SetExtensionRunning(extension_id, false); 143 extension_prefs->SetExtensionRunning(extension_id, false);
141 extensions::app_file_handler_util::ClearSavedFileEntries(
142 extension_prefs, extension_id);
143 } 144 }
144 145
145 void AppRestoreService::RecordIfAppHasWindows( 146 void AppRestoreService::RecordIfAppHasWindows(
146 const std::string& id) { 147 const std::string& id) {
147 ExtensionService* extension_service = 148 ExtensionService* extension_service =
148 ExtensionSystem::Get(profile_)->extension_service(); 149 ExtensionSystem::Get(profile_)->extension_service();
149 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); 150 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
150 151
151 // If the extension isn't running then we will already have recorded whether 152 // If the extension isn't running then we will already have recorded whether
152 // it had windows or not. 153 // it had windows or not.
153 if (!extension_prefs->IsExtensionRunning(id)) 154 if (!extension_prefs->IsExtensionRunning(id))
154 return; 155 return;
155 156
156 extensions::ShellWindowRegistry* shell_window_registry = 157 extensions::ShellWindowRegistry* shell_window_registry =
157 extensions::ShellWindowRegistry::Factory::GetForProfile( 158 extensions::ShellWindowRegistry::Factory::GetForProfile(
158 profile_, false /* create */); 159 profile_, false /* create */);
159 if (!shell_window_registry) 160 if (!shell_window_registry)
160 return; 161 return;
161 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty(); 162 bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty();
162 extension_prefs->SetHasWindows(id, has_windows); 163 extension_prefs->SetHasWindows(id, has_windows);
163 } 164 }
164 165
165 void AppRestoreService::RestoreApp( 166 void AppRestoreService::RestoreApp(const Extension* extension) {
166 const Extension* extension, 167 extensions::RestartPlatformApp(profile_, extension);
167 const std::vector<SavedFileEntry>& file_entries) {
168 extensions::RestartPlatformAppWithFileEntries(profile_,
169 extension,
170 file_entries);
171 } 168 }
172 169
173 void AppRestoreService::StartObservingShellWindows() { 170 void AppRestoreService::StartObservingShellWindows() {
174 extensions::ShellWindowRegistry* shell_window_registry = 171 extensions::ShellWindowRegistry* shell_window_registry =
175 extensions::ShellWindowRegistry::Factory::GetForProfile( 172 extensions::ShellWindowRegistry::Factory::GetForProfile(
176 profile_, false /* create */); 173 profile_, false /* create */);
177 if (shell_window_registry) 174 if (shell_window_registry)
178 shell_window_registry->AddObserver(this); 175 shell_window_registry->AddObserver(this);
179 } 176 }
180 177
181 void AppRestoreService::StopObservingShellWindows() { 178 void AppRestoreService::StopObservingShellWindows() {
182 extensions::ShellWindowRegistry* shell_window_registry = 179 extensions::ShellWindowRegistry* shell_window_registry =
183 extensions::ShellWindowRegistry::Factory::GetForProfile( 180 extensions::ShellWindowRegistry::Factory::GetForProfile(
184 profile_, false /* create */); 181 profile_, false /* create */);
185 if (shell_window_registry) 182 if (shell_window_registry)
186 shell_window_registry->RemoveObserver(this); 183 shell_window_registry->RemoveObserver(this);
187 } 184 }
188 185
189 } // namespace apps 186 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_restore_service.h ('k') | apps/app_restore_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698