OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notifications/notifier_state_tracker.h" | 5 #include "chrome/browser/notifications/notifier_state_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 #if defined(ENABLE_EXTENSIONS) | 156 #if defined(ENABLE_EXTENSIONS) |
157 void NotifierStateTracker::OnExtensionUninstalled( | 157 void NotifierStateTracker::OnExtensionUninstalled( |
158 content::BrowserContext* browser_context, | 158 content::BrowserContext* browser_context, |
159 const extensions::Extension* extension, | 159 const extensions::Extension* extension, |
160 extensions::UninstallReason reason) { | 160 extensions::UninstallReason reason) { |
161 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 161 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
162 if (IsNotifierEnabled(notifier_id)) | 162 if (IsNotifierEnabled(notifier_id)) |
163 return; | 163 return; |
164 | 164 |
165 // The settings for ephemeral apps will be persisted across cache evictions. | |
166 if (extensions::util::IsEphemeralApp(extension->id(), profile_)) | |
167 return; | |
168 | |
169 SetNotifierEnabled(notifier_id, true); | 165 SetNotifierEnabled(notifier_id, true); |
170 } | 166 } |
171 | 167 |
172 void NotifierStateTracker::FirePermissionLevelChangedEvent( | 168 void NotifierStateTracker::FirePermissionLevelChangedEvent( |
173 const NotifierId& notifier_id, bool enabled) { | 169 const NotifierId& notifier_id, bool enabled) { |
174 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); | 170 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); |
175 extensions::api::notifications::PermissionLevel permission = | 171 extensions::api::notifications::PermissionLevel permission = |
176 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED | 172 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED |
177 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; | 173 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; |
178 scoped_ptr<base::ListValue> args(new base::ListValue()); | 174 scoped_ptr<base::ListValue> args(new base::ListValue()); |
179 args->Append(new base::StringValue( | 175 args->Append(new base::StringValue( |
180 extensions::api::notifications::ToString(permission))); | 176 extensions::api::notifications::ToString(permission))); |
181 scoped_ptr<extensions::Event> event(new extensions::Event( | 177 scoped_ptr<extensions::Event> event(new extensions::Event( |
182 extensions::events::NOTIFICATIONS_ON_PERMISSION_LEVEL_CHANGED, | 178 extensions::events::NOTIFICATIONS_ON_PERMISSION_LEVEL_CHANGED, |
183 extensions::api::notifications::OnPermissionLevelChanged::kEventName, | 179 extensions::api::notifications::OnPermissionLevelChanged::kEventName, |
184 args.Pass())); | 180 args.Pass())); |
185 extensions::EventRouter::Get(profile_) | 181 extensions::EventRouter::Get(profile_) |
186 ->DispatchEventToExtension(notifier_id.id, event.Pass()); | 182 ->DispatchEventToExtension(notifier_id.id, event.Pass()); |
187 | 183 |
188 // Tell the IO thread that this extension's permission for notifications | 184 // Tell the IO thread that this extension's permission for notifications |
189 // has changed. | 185 // has changed. |
190 extensions::InfoMap* extension_info_map = | 186 extensions::InfoMap* extension_info_map = |
191 extensions::ExtensionSystem::Get(profile_)->info_map(); | 187 extensions::ExtensionSystem::Get(profile_)->info_map(); |
192 content::BrowserThread::PostTask( | 188 content::BrowserThread::PostTask( |
193 content::BrowserThread::IO, FROM_HERE, | 189 content::BrowserThread::IO, FROM_HERE, |
194 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 190 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
195 extension_info_map, notifier_id.id, !enabled)); | 191 extension_info_map, notifier_id.id, !enabled)); |
196 } | 192 } |
197 #endif | 193 #endif |
OLD | NEW |