| 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 "chrome/browser/apps/ephemeral_app_service.h" | 5 #include "chrome/browser/apps/ephemeral_app_service.h" |
| 6 | 6 |
| 7 #include "apps/app_lifetime_monitor_factory.h" | 7 #include "apps/app_lifetime_monitor_factory.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/apps/ephemeral_app_service_factory.h" | 10 #include "chrome/browser/apps/ephemeral_app_service_factory.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 #include "content/public/browser/notification_source.h" | |
| 18 #include "content/public/browser/notification_types.h" | |
| 19 #include "extensions/browser/extension_prefs.h" | 15 #include "extensions/browser/extension_prefs.h" |
| 20 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/extension_util.h" | 18 #include "extensions/browser/extension_util.h" |
| 23 #include "extensions/browser/notification_types.h" | |
| 24 #include "extensions/browser/uninstall_reason.h" | 19 #include "extensions/browser/uninstall_reason.h" |
| 25 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 26 #include "extensions/common/extension_set.h" | 21 #include "extensions/common/extension_set.h" |
| 22 #include "extensions/common/one_shot_event.h" |
| 27 | 23 |
| 28 using extensions::Extension; | 24 using extensions::Extension; |
| 29 using extensions::ExtensionPrefs; | 25 using extensions::ExtensionPrefs; |
| 30 using extensions::ExtensionRegistry; | 26 using extensions::ExtensionRegistry; |
| 31 using extensions::ExtensionSet; | 27 using extensions::ExtensionSet; |
| 32 using extensions::ExtensionSystem; | 28 using extensions::ExtensionSystem; |
| 33 | 29 |
| 34 namespace { | 30 namespace { |
| 35 | 31 |
| 36 // The number of seconds after startup before performing garbage collection | 32 // The number of seconds after startup before performing garbage collection |
| (...skipping 27 matching lines...) Expand all Loading... |
| 64 return EphemeralAppServiceFactory::GetForProfile(profile); | 60 return EphemeralAppServiceFactory::GetForProfile(profile); |
| 65 } | 61 } |
| 66 | 62 |
| 67 EphemeralAppService::EphemeralAppService(Profile* profile) | 63 EphemeralAppService::EphemeralAppService(Profile* profile) |
| 68 : profile_(profile), | 64 : profile_(profile), |
| 69 extension_registry_observer_(this), | 65 extension_registry_observer_(this), |
| 70 app_lifetime_monitor_observer_(this), | 66 app_lifetime_monitor_observer_(this), |
| 71 ephemeral_app_count_(-1), | 67 ephemeral_app_count_(-1), |
| 72 disable_idle_app_delay_(kDefaultDisableAppDelay), | 68 disable_idle_app_delay_(kDefaultDisableAppDelay), |
| 73 weak_ptr_factory_(this) { | 69 weak_ptr_factory_(this) { |
| 74 registrar_.Add(this, | 70 ExtensionSystem::Get(profile_)->ready().Post( |
| 75 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 71 FROM_HERE, |
| 76 content::Source<Profile>(profile_)); | 72 base::Bind(&EphemeralAppService::Init, weak_ptr_factory_.GetWeakPtr())); |
| 77 } | 73 } |
| 78 | 74 |
| 79 EphemeralAppService::~EphemeralAppService() { | 75 EphemeralAppService::~EphemeralAppService() { |
| 80 } | 76 } |
| 81 | 77 |
| 82 void EphemeralAppService::ClearCachedApps() { | 78 void EphemeralAppService::ClearCachedApps() { |
| 83 // Cancel any pending garbage collects. | 79 // Cancel any pending garbage collects. |
| 84 garbage_collect_apps_timer_.Stop(); | 80 garbage_collect_apps_timer_.Stop(); |
| 85 | 81 |
| 86 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 82 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 108 DCHECK(registry->GetExtensionById(extension_id, | 104 DCHECK(registry->GetExtensionById(extension_id, |
| 109 ExtensionRegistry::EVERYTHING)); | 105 ExtensionRegistry::EVERYTHING)); |
| 110 service->UninstallExtension( | 106 service->UninstallExtension( |
| 111 extension_id, | 107 extension_id, |
| 112 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 108 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
| 113 base::Bind(&base::DoNothing), | 109 base::Bind(&base::DoNothing), |
| 114 NULL); | 110 NULL); |
| 115 } | 111 } |
| 116 } | 112 } |
| 117 | 113 |
| 118 void EphemeralAppService::Observe( | |
| 119 int type, | |
| 120 const content::NotificationSource& source, | |
| 121 const content::NotificationDetails& details) { | |
| 122 switch (type) { | |
| 123 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: { | |
| 124 Init(); | |
| 125 break; | |
| 126 } | |
| 127 default: | |
| 128 NOTREACHED(); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 void EphemeralAppService::OnExtensionWillBeInstalled( | 114 void EphemeralAppService::OnExtensionWillBeInstalled( |
| 133 content::BrowserContext* browser_context, | 115 content::BrowserContext* browser_context, |
| 134 const extensions::Extension* extension, | 116 const extensions::Extension* extension, |
| 135 bool is_update, | 117 bool is_update, |
| 136 bool from_ephemeral, | 118 bool from_ephemeral, |
| 137 const std::string& old_name) { | 119 const std::string& old_name) { |
| 138 if (from_ephemeral) { | 120 if (from_ephemeral) { |
| 139 // An ephemeral app was just promoted to a regular installed app. | 121 // An ephemeral app was just promoted to a regular installed app. |
| 140 --ephemeral_app_count_; | 122 --ephemeral_app_count_; |
| 141 DCHECK_GE(ephemeral_app_count_, 0); | 123 DCHECK_GE(ephemeral_app_count_, 0); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // Remove ephemeral apps that have been inactive for a while or if the cache | 361 // Remove ephemeral apps that have been inactive for a while or if the cache |
| 380 // is larger than the desired size. | 362 // is larger than the desired size. |
| 381 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { | 363 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { |
| 382 remove_app_ids->insert(it->second); | 364 remove_app_ids->insert(it->second); |
| 383 --app_count; | 365 --app_count; |
| 384 } else { | 366 } else { |
| 385 break; | 367 break; |
| 386 } | 368 } |
| 387 } | 369 } |
| 388 } | 370 } |
| OLD | NEW |