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/data_deleter.h" | 10 #include "chrome/browser/extensions/data_deleter.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 const int EphemeralAppService::kMaxEphemeralAppsCount = 30; | 55 const int EphemeralAppService::kMaxEphemeralAppsCount = 30; |
56 const int EphemeralAppService::kDataInactiveThreshold = 90; | 56 const int EphemeralAppService::kDataInactiveThreshold = 90; |
57 | 57 |
58 // static | 58 // static |
59 EphemeralAppService* EphemeralAppService::Get(Profile* profile) { | 59 EphemeralAppService* EphemeralAppService::Get(Profile* profile) { |
60 return EphemeralAppServiceFactory::GetForProfile(profile); | 60 return EphemeralAppServiceFactory::GetForProfile(profile); |
61 } | 61 } |
62 | 62 |
63 EphemeralAppService::EphemeralAppService(Profile* profile) | 63 EphemeralAppService::EphemeralAppService(Profile* profile) |
64 : profile_(profile), | 64 : profile_(profile), |
65 extension_registry_observer_(this), | |
65 ephemeral_app_count_(-1) { | 66 ephemeral_app_count_(-1) { |
66 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 67 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kEnableEphemeralApps)) | 68 switches::kEnableEphemeralApps)) |
68 return; | 69 return; |
69 | 70 |
70 registrar_.Add(this, | 71 extension_registry_observer_.Add( |
71 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, | 72 extensions::ExtensionRegistry::Get(profile_)); |
72 content::Source<Profile>(profile_)); | |
73 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | |
74 content::Source<Profile>(profile_)); | |
75 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 73 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
76 content::Source<Profile>(profile_)); | 74 content::Source<Profile>(profile_)); |
77 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 75 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
78 content::Source<Profile>(profile_)); | 76 content::Source<Profile>(profile_)); |
79 } | 77 } |
80 | 78 |
81 EphemeralAppService::~EphemeralAppService() { | 79 EphemeralAppService::~EphemeralAppService() { |
82 } | 80 } |
83 | 81 |
84 void EphemeralAppService::Observe( | 82 void EphemeralAppService::Observe( |
85 int type, | 83 int type, |
86 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
87 const content::NotificationDetails& details) { | 85 const content::NotificationDetails& details) { |
88 switch (type) { | 86 switch (type) { |
89 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 87 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
90 Init(); | 88 Init(); |
91 break; | 89 break; |
92 } | 90 } |
93 case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: { | |
94 const Extension* extension = | |
95 content::Details<const InstalledExtensionInfo>(details)->extension; | |
96 DCHECK(extension); | |
97 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) { | |
98 ++ephemeral_app_count_; | |
99 if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount) | |
100 TriggerGarbageCollect( | |
101 base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay)); | |
102 } | |
103 break; | |
104 } | |
105 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | |
106 const Extension* extension = | |
107 content::Details<const Extension>(details).ptr(); | |
108 DCHECK(extension); | |
109 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) | |
110 --ephemeral_app_count_; | |
111 break; | |
112 } | |
113 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 91 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
114 // Ideally we need to know when the extension system is shutting down. | 92 // Ideally we need to know when the extension system is shutting down. |
115 garbage_collect_apps_timer_.Stop(); | 93 garbage_collect_apps_timer_.Stop(); |
116 break; | 94 break; |
117 } | 95 } |
118 default: | 96 default: |
119 NOTREACHED(); | 97 NOTREACHED(); |
120 } | 98 } |
121 } | 99 } |
122 | 100 |
101 void EphemeralAppService::OnExtensionWillBeInstalled( | |
102 content::BrowserContext* browser_context, | |
103 const extensions::Extension* extension, | |
104 bool is_update, | |
105 const std::string& old_name) { | |
106 DCHECK(extension); | |
not at google - send to devlin
2014/05/27 17:40:16
no need for DCHECK
limasdf
2014/05/27 17:54:07
Done.
| |
107 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) { | |
108 ++ephemeral_app_count_; | |
109 if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount) | |
110 TriggerGarbageCollect( | |
111 base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay)); | |
112 } | |
113 } | |
114 | |
115 void EphemeralAppService::OnExtensionUninstalled( | |
116 content::BrowserContext* browser_context, | |
117 const extensions::Extension* extension) { | |
118 DCHECK(extension); | |
not at google - send to devlin
2014/05/27 17:40:16
no need for DCHECK
limasdf
2014/05/27 17:54:07
Done.
| |
119 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) | |
120 --ephemeral_app_count_; | |
121 } | |
122 | |
123 void EphemeralAppService::Init() { | 123 void EphemeralAppService::Init() { |
124 InitEphemeralAppCount(); | 124 InitEphemeralAppCount(); |
125 TriggerGarbageCollect( | 125 TriggerGarbageCollect( |
126 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay)); | 126 base::TimeDelta::FromSeconds(kGarbageCollectAppsStartupDelay)); |
127 | 127 |
128 garbage_collect_data_timer_.Start( | 128 garbage_collect_data_timer_.Start( |
129 FROM_HERE, | 129 FROM_HERE, |
130 base::TimeDelta::FromSeconds(kGarbageCollectDataStartupDelay), | 130 base::TimeDelta::FromSeconds(kGarbageCollectDataStartupDelay), |
131 this, | 131 this, |
132 &EphemeralAppService::GarbageCollectData); | 132 &EphemeralAppService::GarbageCollectData); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 info->extension_id, | 280 info->extension_id, |
281 &error)); | 281 &error)); |
282 | 282 |
283 if (extension.get()) | 283 if (extension.get()) |
284 extensions::DataDeleter::StartDeleting(profile_, extension.get()); | 284 extensions::DataDeleter::StartDeleting(profile_, extension.get()); |
285 } | 285 } |
286 | 286 |
287 prefs->RemoveEvictedEphemeralApp(info->extension_id); | 287 prefs->RemoveEvictedEphemeralApp(info->extension_id); |
288 } | 288 } |
289 } | 289 } |
OLD | NEW |