| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/apps/ephemeral_app_service_factory.h" | 8 #include "chrome/browser/apps/ephemeral_app_service_factory.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 // Do not remove apps that are running. | 97 // Do not remove apps that are running. |
| 98 if (!extensions::util::IsExtensionIdle(extension_id, profile_)) | 98 if (!extensions::util::IsExtensionIdle(extension_id, profile_)) |
| 99 continue; | 99 continue; |
| 100 | 100 |
| 101 DCHECK(registry->GetExtensionById(extension_id, | 101 DCHECK(registry->GetExtensionById(extension_id, |
| 102 ExtensionRegistry::EVERYTHING)); | 102 ExtensionRegistry::EVERYTHING)); |
| 103 service->UninstallExtension( | 103 service->UninstallExtension( |
| 104 extension_id, | 104 extension_id, |
| 105 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 105 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
| 106 base::Bind(&base::DoNothing), |
| 106 NULL); | 107 NULL); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 void EphemeralAppService::Observe( | 111 void EphemeralAppService::Observe( |
| 111 int type, | 112 int type, |
| 112 const content::NotificationSource& source, | 113 const content::NotificationSource& source, |
| 113 const content::NotificationDetails& details) { | 114 const content::NotificationDetails& details) { |
| 114 switch (type) { | 115 switch (type) { |
| 115 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 116 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (!app_launch_times.empty()) { | 232 if (!app_launch_times.empty()) { |
| 232 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); | 233 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); |
| 233 | 234 |
| 234 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); | 235 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); |
| 235 id != remove_app_ids.end(); ++id) { | 236 id != remove_app_ids.end(); ++id) { |
| 236 // Protect against cascading uninstalls. | 237 // Protect against cascading uninstalls. |
| 237 if (!registry->GetExtensionById(*id, ExtensionRegistry::EVERYTHING)) | 238 if (!registry->GetExtensionById(*id, ExtensionRegistry::EVERYTHING)) |
| 238 continue; | 239 continue; |
| 239 | 240 |
| 240 service->UninstallExtension( | 241 service->UninstallExtension( |
| 241 *id, extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, NULL); | 242 *id, |
| 243 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
| 244 base::Bind(&base::DoNothing), |
| 245 NULL); |
| 242 } | 246 } |
| 243 } | 247 } |
| 244 } | 248 } |
| 245 | 249 |
| 246 // static | 250 // static |
| 247 void EphemeralAppService::GetAppsToRemove( | 251 void EphemeralAppService::GetAppsToRemove( |
| 248 int app_count, | 252 int app_count, |
| 249 const LaunchTimeAppMap& app_launch_times, | 253 const LaunchTimeAppMap& app_launch_times, |
| 250 std::set<std::string>* remove_app_ids) { | 254 std::set<std::string>* remove_app_ids) { |
| 251 base::Time time_now = base::Time::Now(); | 255 base::Time time_now = base::Time::Now(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 265 // Remove ephemeral apps that have been inactive for a while or if the cache | 269 // Remove ephemeral apps that have been inactive for a while or if the cache |
| 266 // is larger than the desired size. | 270 // is larger than the desired size. |
| 267 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { | 271 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { |
| 268 remove_app_ids->insert(it->second); | 272 remove_app_ids->insert(it->second); |
| 269 --app_count; | 273 --app_count; |
| 270 } else { | 274 } else { |
| 271 break; | 275 break; |
| 272 } | 276 } |
| 273 } | 277 } |
| 274 } | 278 } |
| OLD | NEW |