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" |
11 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
18 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
20 #include "extensions/browser/extension_util.h" | 20 #include "extensions/browser/extension_util.h" |
| 21 #include "extensions/browser/uninstall_reason.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_set.h" | 23 #include "extensions/common/extension_set.h" |
23 | 24 |
24 using extensions::Extension; | 25 using extensions::Extension; |
25 using extensions::ExtensionPrefs; | 26 using extensions::ExtensionPrefs; |
26 using extensions::ExtensionRegistry; | 27 using extensions::ExtensionRegistry; |
27 using extensions::ExtensionSet; | 28 using extensions::ExtensionSet; |
28 using extensions::ExtensionSystem; | 29 using extensions::ExtensionSystem; |
29 | 30 |
30 namespace { | 31 namespace { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 continue; | 95 continue; |
95 | 96 |
96 // Do not remove apps that are running. | 97 // Do not remove apps that are running. |
97 if (!extensions::util::IsExtensionIdle(extension_id, profile_)) | 98 if (!extensions::util::IsExtensionIdle(extension_id, profile_)) |
98 continue; | 99 continue; |
99 | 100 |
100 DCHECK(registry->GetExtensionById(extension_id, | 101 DCHECK(registry->GetExtensionById(extension_id, |
101 ExtensionRegistry::EVERYTHING)); | 102 ExtensionRegistry::EVERYTHING)); |
102 service->UninstallExtension( | 103 service->UninstallExtension( |
103 extension_id, | 104 extension_id, |
104 ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | 105 extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, |
105 NULL); | 106 NULL); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 void EphemeralAppService::Observe( | 110 void EphemeralAppService::Observe( |
110 int type, | 111 int type, |
111 const content::NotificationSource& source, | 112 const content::NotificationSource& source, |
112 const content::NotificationDetails& details) { | 113 const content::NotificationDetails& details) { |
113 switch (type) { | 114 switch (type) { |
114 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 115 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
(...skipping 25 matching lines...) Expand all Loading... |
140 ++ephemeral_app_count_; | 141 ++ephemeral_app_count_; |
141 if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount) { | 142 if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount) { |
142 TriggerGarbageCollect( | 143 TriggerGarbageCollect( |
143 base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay)); | 144 base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay)); |
144 } | 145 } |
145 } | 146 } |
146 } | 147 } |
147 | 148 |
148 void EphemeralAppService::OnExtensionUninstalled( | 149 void EphemeralAppService::OnExtensionUninstalled( |
149 content::BrowserContext* browser_context, | 150 content::BrowserContext* browser_context, |
150 const extensions::Extension* extension) { | 151 const extensions::Extension* extension, |
| 152 extensions::UninstallReason reason) { |
151 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) { | 153 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) { |
152 --ephemeral_app_count_; | 154 --ephemeral_app_count_; |
153 DCHECK_GE(ephemeral_app_count_, 0); | 155 DCHECK_GE(ephemeral_app_count_, 0); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
157 void EphemeralAppService::Init() { | 159 void EphemeralAppService::Init() { |
158 InitEphemeralAppCount(); | 160 InitEphemeralAppCount(); |
159 TriggerGarbageCollect( | 161 TriggerGarbageCollect( |
160 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay)); | 162 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (!app_launch_times.empty()) { | 231 if (!app_launch_times.empty()) { |
230 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); | 232 GetAppsToRemove(app_count, app_launch_times, &remove_app_ids); |
231 | 233 |
232 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); | 234 for (std::set<std::string>::const_iterator id = remove_app_ids.begin(); |
233 id != remove_app_ids.end(); ++id) { | 235 id != remove_app_ids.end(); ++id) { |
234 // Protect against cascading uninstalls. | 236 // Protect against cascading uninstalls. |
235 if (!registry->GetExtensionById(*id, ExtensionRegistry::EVERYTHING)) | 237 if (!registry->GetExtensionById(*id, ExtensionRegistry::EVERYTHING)) |
236 continue; | 238 continue; |
237 | 239 |
238 service->UninstallExtension( | 240 service->UninstallExtension( |
239 *id, | 241 *id, extensions::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, NULL); |
240 ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION, | |
241 NULL); | |
242 } | 242 } |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 // static | 246 // static |
247 void EphemeralAppService::GetAppsToRemove( | 247 void EphemeralAppService::GetAppsToRemove( |
248 int app_count, | 248 int app_count, |
249 const LaunchTimeAppMap& app_launch_times, | 249 const LaunchTimeAppMap& app_launch_times, |
250 std::set<std::string>* remove_app_ids) { | 250 std::set<std::string>* remove_app_ids) { |
251 base::Time time_now = base::Time::Now(); | 251 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 | 265 // Remove ephemeral apps that have been inactive for a while or if the cache |
266 // is larger than the desired size. | 266 // is larger than the desired size. |
267 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { | 267 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { |
268 remove_app_ids->insert(it->second); | 268 remove_app_ids->insert(it->second); |
269 --app_count; | 269 --app_count; |
270 } else { | 270 } else { |
271 break; | 271 break; |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
OLD | NEW |