Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/apps/ephemeral_app_service.cc

Issue 337323003: Remove the ability to retain local data of evicted ephemeral apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove an unused declaration Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/data_deleter.h"
11 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_util.h" 11 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
18 #include "extensions/browser/extension_prefs.h" 17 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/extension_system.h" 19 #include "extensions/browser/extension_system.h"
21 #include "extensions/browser/extension_util.h" 20 #include "extensions/browser/extension_util.h"
22 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
23 #include "extensions/common/extension_set.h" 22 #include "extensions/common/extension_set.h"
24 23
25 using extensions::Extension; 24 using extensions::Extension;
26 using extensions::ExtensionInfo;
27 using extensions::ExtensionPrefs; 25 using extensions::ExtensionPrefs;
28 using extensions::ExtensionSet; 26 using extensions::ExtensionSet;
29 using extensions::ExtensionSystem; 27 using extensions::ExtensionSystem;
30 using extensions::InstalledExtensionInfo;
31 28
32 namespace { 29 namespace {
33 30
34 // The number of seconds after startup before performing garbage collection 31 // The number of seconds after startup before performing garbage collection
35 // of ephemeral apps. 32 // of ephemeral apps.
36 const int kGarbageCollectAppsStartupDelay = 60; 33 const int kGarbageCollectAppsStartupDelay = 60;
37 34
38 // The number of seconds after an ephemeral app has been installed before 35 // The number of seconds after an ephemeral app has been installed before
39 // performing garbage collection. 36 // performing garbage collection.
40 const int kGarbageCollectAppsInstallDelay = 15; 37 const int kGarbageCollectAppsInstallDelay = 15;
41 38
42 // When the number of ephemeral apps reaches this count, trigger garbage 39 // When the number of ephemeral apps reaches this count, trigger garbage
43 // collection to trim off the least-recently used apps in excess of 40 // collection to trim off the least-recently used apps in excess of
44 // kMaxEphemeralAppsCount. 41 // kMaxEphemeralAppsCount.
45 const int kGarbageCollectAppsTriggerCount = 35; 42 const int kGarbageCollectAppsTriggerCount = 35;
46 43
47 // The number of seconds after startup before performing garbage collection
48 // of the data of evicted ephemeral apps.
49 const int kGarbageCollectDataStartupDelay = 120;
50
51 } // namespace 44 } // namespace
52 45
53 const int EphemeralAppService::kAppInactiveThreshold = 10; 46 const int EphemeralAppService::kAppInactiveThreshold = 10;
54 const int EphemeralAppService::kAppKeepThreshold = 1; 47 const int EphemeralAppService::kAppKeepThreshold = 1;
55 const int EphemeralAppService::kMaxEphemeralAppsCount = 30; 48 const int EphemeralAppService::kMaxEphemeralAppsCount = 30;
56 const int EphemeralAppService::kDataInactiveThreshold = 90;
57 49
58 // static 50 // static
59 EphemeralAppService* EphemeralAppService::Get(Profile* profile) { 51 EphemeralAppService* EphemeralAppService::Get(Profile* profile) {
60 return EphemeralAppServiceFactory::GetForProfile(profile); 52 return EphemeralAppServiceFactory::GetForProfile(profile);
61 } 53 }
62 54
63 EphemeralAppService::EphemeralAppService(Profile* profile) 55 EphemeralAppService::EphemeralAppService(Profile* profile)
64 : profile_(profile), 56 : profile_(profile),
65 extension_registry_observer_(this), 57 extension_registry_observer_(this),
66 ephemeral_app_count_(-1) { 58 ephemeral_app_count_(-1) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) { 116 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) {
125 --ephemeral_app_count_; 117 --ephemeral_app_count_;
126 DCHECK_GE(ephemeral_app_count_, 0); 118 DCHECK_GE(ephemeral_app_count_, 0);
127 } 119 }
128 } 120 }
129 121
130 void EphemeralAppService::Init() { 122 void EphemeralAppService::Init() {
131 InitEphemeralAppCount(); 123 InitEphemeralAppCount();
132 TriggerGarbageCollect( 124 TriggerGarbageCollect(
133 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay)); 125 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay));
134
135 garbage_collect_data_timer_.Start(
136 FROM_HERE,
137 base::TimeDelta::FromSeconds(kGarbageCollectDataStartupDelay),
138 this,
139 &EphemeralAppService::GarbageCollectData);
140 } 126 }
141 127
142 void EphemeralAppService::InitEphemeralAppCount() { 128 void EphemeralAppService::InitEphemeralAppCount() {
143 scoped_ptr<ExtensionSet> extensions = 129 scoped_ptr<ExtensionSet> extensions =
144 extensions::ExtensionRegistry::Get(profile_) 130 extensions::ExtensionRegistry::Get(profile_)
145 ->GenerateInstalledExtensionsSet(); 131 ->GenerateInstalledExtensionsSet();
146 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); 132 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
147 DCHECK(prefs); 133 DCHECK(prefs);
148 134
149 ephemeral_app_count_ = 0; 135 ephemeral_app_count_ = 0;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Remove ephemeral apps that have been inactive for a while or if the cache 224 // Remove ephemeral apps that have been inactive for a while or if the cache
239 // is larger than the desired size. 225 // is larger than the desired size.
240 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) { 226 if (it->first < inactive_threshold || app_count > kMaxEphemeralAppsCount) {
241 remove_app_ids->insert(it->second); 227 remove_app_ids->insert(it->second);
242 --app_count; 228 --app_count;
243 } else { 229 } else {
244 break; 230 break;
245 } 231 }
246 } 232 }
247 } 233 }
248
249 void EphemeralAppService::GarbageCollectData() {
250 ExtensionService* service =
251 ExtensionSystem::Get(profile_)->extension_service();
252 DCHECK(service);
253 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
254 DCHECK(prefs);
255 scoped_ptr<ExtensionPrefs::ExtensionsInfo> evicted_apps_info(
256 prefs->GetEvictedEphemeralAppsInfo());
257
258 base::Time time_now = base::Time::Now();
259 const base::Time inactive_threshold =
260 time_now - base::TimeDelta::FromDays(kDataInactiveThreshold);
261
262 for (size_t i = 0; i < evicted_apps_info->size(); ++i) {
263 ExtensionInfo* info = evicted_apps_info->at(i).get();
264 base::Time last_launch_time = prefs->GetLastLaunchTime(info->extension_id);
265 if (last_launch_time > inactive_threshold)
266 continue;
267
268 // Sanity check to ensure the app is not currently installed.
269 if (service->GetInstalledExtension(info->extension_id)) {
270 NOTREACHED();
271 continue;
272 }
273
274 // Ensure the app is not waiting to be installed.
275 scoped_ptr<ExtensionInfo> delayed_install(
276 prefs->GetDelayedInstallInfo(info->extension_id));
277 if (delayed_install.get())
278 continue;
279
280 if (info->extension_manifest.get()) {
281 std::string error;
282 scoped_refptr<const Extension> extension(Extension::Create(
283 info->extension_path,
284 info->extension_location,
285 *info->extension_manifest,
286 prefs->GetCreationFlags(info->extension_id),
287 info->extension_id,
288 &error));
289
290 if (extension.get())
291 extensions::DataDeleter::StartDeleting(profile_, extension.get());
292 }
293
294 prefs->RemoveEvictedEphemeralApp(info->extension_id);
295 }
296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698