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/saved_files_service.h" | 5 #include "apps/saved_files_service.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "apps/saved_files_service_factory.h" | 14 #include "apps/saved_files_service_factory.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/value_conversions.h" | 16 #include "base/value_conversions.h" |
17 #include "chrome/browser/chrome_notification_types.h" | |
18 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
20 #include "extensions/browser/extension_host.h" | 19 #include "extensions/browser/extension_host.h" |
21 #include "extensions/browser/extension_prefs.h" | 20 #include "extensions/browser/extension_prefs.h" |
22 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
23 #include "extensions/browser/notification_types.h" | 22 #include "extensions/browser/notification_types.h" |
24 #include "extensions/common/permissions/api_permission.h" | 23 #include "extensions/common/permissions/api_permission.h" |
25 #include "extensions/common/permissions/permission_set.h" | 24 #include "extensions/common/permissions/permission_set.h" |
26 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
27 | 26 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // static | 194 // static |
196 SavedFilesService* SavedFilesService::Get(content::BrowserContext* context) { | 195 SavedFilesService* SavedFilesService::Get(content::BrowserContext* context) { |
197 return SavedFilesServiceFactory::GetForBrowserContext(context); | 196 return SavedFilesServiceFactory::GetForBrowserContext(context); |
198 } | 197 } |
199 | 198 |
200 SavedFilesService::SavedFilesService(content::BrowserContext* context) | 199 SavedFilesService::SavedFilesService(content::BrowserContext* context) |
201 : context_(context) { | 200 : context_(context) { |
202 registrar_.Add(this, | 201 registrar_.Add(this, |
203 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 202 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
204 content::NotificationService::AllSources()); | 203 content::NotificationService::AllSources()); |
205 registrar_.Add(this, | |
206 chrome::NOTIFICATION_APP_TERMINATING, | |
207 content::NotificationService::AllSources()); | |
208 } | 204 } |
209 | 205 |
210 SavedFilesService::~SavedFilesService() {} | 206 SavedFilesService::~SavedFilesService() {} |
211 | 207 |
212 void SavedFilesService::Observe(int type, | 208 void SavedFilesService::Observe(int type, |
213 const content::NotificationSource& source, | 209 const content::NotificationSource& source, |
214 const content::NotificationDetails& details) { | 210 const content::NotificationDetails& details) { |
215 switch (type) { | 211 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, type); |
216 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 212 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
217 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 213 const Extension* extension = host->extension(); |
218 const Extension* extension = host->extension(); | 214 if (extension) { |
219 if (extension) { | 215 ClearQueueIfNoRetainPermission(extension); |
220 ClearQueueIfNoRetainPermission(extension); | 216 Clear(extension->id()); |
221 Clear(extension->id()); | |
222 } | |
223 break; | |
224 } | |
225 | |
226 case chrome::NOTIFICATION_APP_TERMINATING: { | |
227 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular | |
228 // as all extension hosts will be destroyed as a result of shutdown. | |
229 registrar_.RemoveAll(); | |
230 break; | |
231 } | |
232 } | 217 } |
233 } | 218 } |
234 | 219 |
235 void SavedFilesService::RegisterFileEntry(const std::string& extension_id, | 220 void SavedFilesService::RegisterFileEntry(const std::string& extension_id, |
236 const std::string& id, | 221 const std::string& id, |
237 const base::FilePath& file_path, | 222 const base::FilePath& file_path, |
238 bool is_directory) { | 223 bool is_directory) { |
239 GetOrInsert(extension_id)->RegisterFileEntry(id, file_path, is_directory); | 224 GetOrInsert(extension_id)->RegisterFileEntry(id, file_path, is_directory); |
240 } | 225 } |
241 | 226 |
(...skipping 27 matching lines...) Expand all Loading... |
269 APIPermission::kFileSystemRetainEntries)) { | 254 APIPermission::kFileSystemRetainEntries)) { |
270 ClearQueue(extension); | 255 ClearQueue(extension); |
271 } | 256 } |
272 } | 257 } |
273 | 258 |
274 void SavedFilesService::ClearQueue(const extensions::Extension* extension) { | 259 void SavedFilesService::ClearQueue(const extensions::Extension* extension) { |
275 ClearSavedFileEntries(ExtensionPrefs::Get(context_), extension->id()); | 260 ClearSavedFileEntries(ExtensionPrefs::Get(context_), extension->id()); |
276 Clear(extension->id()); | 261 Clear(extension->id()); |
277 } | 262 } |
278 | 263 |
| 264 void SavedFilesService::OnApplicationTerminating() { |
| 265 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular |
| 266 // as all extension hosts will be destroyed as a result of shutdown. |
| 267 registrar_.RemoveAll(); |
| 268 } |
| 269 |
279 SavedFilesService::SavedFiles* SavedFilesService::Get( | 270 SavedFilesService::SavedFiles* SavedFilesService::Get( |
280 const std::string& extension_id) const { | 271 const std::string& extension_id) const { |
281 auto it = extension_id_to_saved_files_.find(extension_id); | 272 auto it = extension_id_to_saved_files_.find(extension_id); |
282 if (it != extension_id_to_saved_files_.end()) | 273 if (it != extension_id_to_saved_files_.end()) |
283 return it->second.get(); | 274 return it->second.get(); |
284 | 275 |
285 return NULL; | 276 return NULL; |
286 } | 277 } |
287 | 278 |
288 SavedFilesService::SavedFiles* SavedFilesService::GetOrInsert( | 279 SavedFilesService::SavedFiles* SavedFilesService::GetOrInsert( |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 void SavedFilesService::SetLruSizeForTest(int size) { | 438 void SavedFilesService::SetLruSizeForTest(int size) { |
448 g_max_saved_file_entries = size; | 439 g_max_saved_file_entries = size; |
449 } | 440 } |
450 | 441 |
451 // static | 442 // static |
452 void SavedFilesService::ClearLruSizeForTest() { | 443 void SavedFilesService::ClearLruSizeForTest() { |
453 g_max_saved_file_entries = kMaxSavedFileEntries; | 444 g_max_saved_file_entries = kMaxSavedFileEntries; |
454 } | 445 } |
455 | 446 |
456 } // namespace apps | 447 } // namespace apps |
OLD | NEW |