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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 extensions::ExtensionRegistry::Get(profile_)); | 64 extensions::ExtensionRegistry::Get(profile_)); |
65 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 65 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
66 content::Source<Profile>(profile_)); | 66 content::Source<Profile>(profile_)); |
67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
68 content::Source<Profile>(profile_)); | 68 content::Source<Profile>(profile_)); |
69 } | 69 } |
70 | 70 |
71 EphemeralAppService::~EphemeralAppService() { | 71 EphemeralAppService::~EphemeralAppService() { |
72 } | 72 } |
73 | 73 |
74 void EphemeralAppService::ClearCachedApps() { | |
75 // Cancel any pending garbage collects. | |
76 garbage_collect_apps_timer_.Stop(); | |
77 | |
78 scoped_ptr<ExtensionSet> extensions = | |
79 extensions::ExtensionRegistry::Get(profile_) | |
80 ->GenerateInstalledExtensionsSet(); | |
81 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); | |
82 DCHECK(prefs); | |
83 | |
84 ExtensionService* service = | |
85 ExtensionSystem::Get(profile_)->extension_service(); | |
86 DCHECK(service); | |
87 | |
88 for (ExtensionSet::const_iterator it = extensions->begin(); | |
89 it != extensions->end(); | |
90 ++it) { | |
91 std::string extension_id = (*it)->id(); | |
92 if (!prefs->IsEphemeralApp(extension_id) || | |
93 !service->GetInstalledExtension(extension_id)) { | |
tapted
2014/07/11 01:16:36
I think GetInstalledExtension(..) should return tr
tmdiep
2014/07/11 02:28:31
There is a CHECK in ExtensionService::UninstallExt
| |
94 continue; | |
95 } | |
96 | |
97 // Do not remove apps that are running. | |
98 if (!extensions::util::IsExtensionIdle(extension_id, profile_)) | |
99 continue; | |
100 | |
101 service->UninstallExtension( | |
102 extension_id, | |
103 ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | |
104 NULL); | |
105 } | |
106 } | |
107 | |
74 void EphemeralAppService::Observe( | 108 void EphemeralAppService::Observe( |
75 int type, | 109 int type, |
76 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
77 const content::NotificationDetails& details) { | 111 const content::NotificationDetails& details) { |
78 switch (type) { | 112 switch (type) { |
79 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 113 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
80 Init(); | 114 Init(); |
81 break; | 115 break; |
82 } | 116 } |
83 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 117 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 // the app will be removed. | 216 // the app will be removed. |
183 if (last_launch_time.is_null()) | 217 if (last_launch_time.is_null()) |
184 last_launch_time = prefs->GetInstallTime(extension->id()); | 218 last_launch_time = prefs->GetInstallTime(extension->id()); |
185 | 219 |
186 app_launch_times.insert(std::make_pair(last_launch_time, extension->id())); | 220 app_launch_times.insert(std::make_pair(last_launch_time, extension->id())); |
187 } | 221 } |
188 | 222 |
189 ExtensionService* service = | 223 ExtensionService* service = |
190 ExtensionSystem::Get(profile_)->extension_service(); | 224 ExtensionSystem::Get(profile_)->extension_service(); |
191 DCHECK(service); | 225 DCHECK(service); |
192 // Execute the replacement policies and remove apps marked for deletion. | 226 // Execute the eviction policies and remove apps marked for deletion. |
193 if (!app_launch_times.empty()) { | 227 if (!app_launch_times.empty()) { |
194 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); | 228 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); |
195 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); | 229 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); |
196 id != remove_app_ids.end(); ++id) { | 230 id != remove_app_ids.end(); ++id) { |
231 if (!service->GetInstalledExtension(*id)) | |
tapted
2014/07/11 01:16:36
I don't think I've wrapped my head around this bit
tmdiep
2014/07/11 02:28:31
Same reason as above - in case of cascading uninst
| |
232 continue; | |
233 | |
197 if (service->UninstallExtension( | 234 if (service->UninstallExtension( |
198 *id, | 235 *id, |
199 ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 236 ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
200 NULL)) { | 237 NULL)) { |
201 --app_count; | 238 --app_count; |
202 } | 239 } |
203 } | 240 } |
204 } | 241 } |
205 | 242 |
206 ephemeral_app_count_ = app_count; | 243 ephemeral_app_count_ = app_count; |
(...skipping 21 matching lines...) Expand all Loading... | |
228 // Remove ephemeral apps that have been inactive for a while or if the cache | 265 // Remove ephemeral apps that have been inactive for a while or if the cache |
229 // is larger than the desired size. | 266 // is larger than the desired size. |
230 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { | 267 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { |
231 remove_app_ids->insert(it->second); | 268 remove_app_ids->insert(it->second); |
232 --app_count; | 269 --app_count; |
233 } else { | 270 } else { |
234 break; | 271 break; |
235 } | 272 } |
236 } | 273 } |
237 } | 274 } |
OLD | NEW |