| 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" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 void EphemeralAppService::InitEphemeralAppCount() { | 206 void EphemeralAppService::InitEphemeralAppCount() { |
| 207 scoped_ptr<ExtensionSet> extensions = | 207 scoped_ptr<ExtensionSet> extensions = |
| 208 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet(); | 208 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet(); |
| 209 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); | 209 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); |
| 210 DCHECK(prefs); | 210 DCHECK(prefs); |
| 211 | 211 |
| 212 ephemeral_app_count_ = 0; | 212 ephemeral_app_count_ = 0; |
| 213 for (ExtensionSet::const_iterator it = extensions->begin(); | 213 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 214 it != extensions->end(); ++it) { | 214 it != extensions->end(); ++it) { |
| 215 const Extension* extension = *it; | 215 const Extension* extension = it->get(); |
| 216 if (prefs->IsEphemeralApp(extension->id())) | 216 if (prefs->IsEphemeralApp(extension->id())) |
| 217 ++ephemeral_app_count_; | 217 ++ephemeral_app_count_; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void EphemeralAppService::DisableEphemeralApp(const std::string& app_id) { | 221 void EphemeralAppService::DisableEphemeralApp(const std::string& app_id) { |
| 222 if (!extensions::util::IsEphemeralApp(app_id, profile_) || | 222 if (!extensions::util::IsEphemeralApp(app_id, profile_) || |
| 223 !extensions::util::IsExtensionIdle(app_id, profile_)) { | 223 !extensions::util::IsExtensionIdle(app_id, profile_)) { |
| 224 return; | 224 return; |
| 225 } | 225 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 240 DCHECK(service); | 240 DCHECK(service); |
| 241 | 241 |
| 242 // Ensure that all inactive ephemeral apps are disabled to prevent all | 242 // Ensure that all inactive ephemeral apps are disabled to prevent all |
| 243 // background activity. This is done on startup to catch any apps that escaped | 243 // background activity. This is done on startup to catch any apps that escaped |
| 244 // being disabled on shutdown. | 244 // being disabled on shutdown. |
| 245 scoped_ptr<ExtensionSet> extensions = | 245 scoped_ptr<ExtensionSet> extensions = |
| 246 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet(); | 246 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet(); |
| 247 for (ExtensionSet::const_iterator it = extensions->begin(); | 247 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 248 it != extensions->end(); | 248 it != extensions->end(); |
| 249 ++it) { | 249 ++it) { |
| 250 const Extension* extension = *it; | 250 const Extension* extension = it->get(); |
| 251 if (!prefs->IsEphemeralApp(extension->id())) | 251 if (!prefs->IsEphemeralApp(extension->id())) |
| 252 continue; | 252 continue; |
| 253 | 253 |
| 254 // Only V2 apps are installed ephemerally. Remove other ephemeral app types | 254 // Only V2 apps are installed ephemerally. Remove other ephemeral app types |
| 255 // that were cached before this policy was introduced. | 255 // that were cached before this policy was introduced. |
| 256 if (!extension->is_platform_app()) { | 256 if (!extension->is_platform_app()) { |
| 257 service->UninstallExtension( | 257 service->UninstallExtension( |
| 258 extension->id(), | 258 extension->id(), |
| 259 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 259 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
| 260 base::Bind(&base::DoNothing), | 260 base::Bind(&base::DoNothing), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 scoped_ptr<ExtensionSet> extensions = | 307 scoped_ptr<ExtensionSet> extensions = |
| 308 registry->GenerateInstalledExtensionsSet(); | 308 registry->GenerateInstalledExtensionsSet(); |
| 309 | 309 |
| 310 int app_count = 0; | 310 int app_count = 0; |
| 311 LaunchTimeAppMap app_launch_times; | 311 LaunchTimeAppMap app_launch_times; |
| 312 std::set<std::string> remove_app_ids; | 312 std::set<std::string> remove_app_ids; |
| 313 | 313 |
| 314 // Populate a list of ephemeral apps, ordered by their last launch time. | 314 // Populate a list of ephemeral apps, ordered by their last launch time. |
| 315 for (ExtensionSet::const_iterator it = extensions->begin(); | 315 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 316 it != extensions->end(); ++it) { | 316 it != extensions->end(); ++it) { |
| 317 const Extension* extension = *it; | 317 const Extension* extension = it->get(); |
| 318 if (!prefs->IsEphemeralApp(extension->id())) | 318 if (!prefs->IsEphemeralApp(extension->id())) |
| 319 continue; | 319 continue; |
| 320 | 320 |
| 321 ++app_count; | 321 ++app_count; |
| 322 | 322 |
| 323 // Do not remove ephemeral apps that are running. | 323 // Do not remove ephemeral apps that are running. |
| 324 if (!extensions::util::IsExtensionIdle(extension->id(), profile_)) | 324 if (!extensions::util::IsExtensionIdle(extension->id(), profile_)) |
| 325 continue; | 325 continue; |
| 326 | 326 |
| 327 base::Time last_launch_time = prefs->GetLastLaunchTime(extension->id()); | 327 base::Time last_launch_time = prefs->GetLastLaunchTime(extension->id()); |
| (...skipping 51 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 | 379 // Remove ephemeral apps that have been inactive for a while or if the cache |
| 380 // is larger than the desired size. | 380 // is larger than the desired size. |
| 381 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { | 381 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { |
| 382 remove_app_ids->insert(it->second); | 382 remove_app_ids->insert(it->second); |
| 383 --app_count; | 383 --app_count; |
| 384 } else { | 384 } else { |
| 385 break; | 385 break; |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 } | 388 } |
| OLD | NEW |