OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/user_metrics.h" |
11 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
16 #include "chrome/browser/engagement/site_engagement_service.h" | 17 #include "chrome/browser/engagement/site_engagement_service.h" |
17 #include "chrome/browser/notifications/notification_display_service_factory.h" | 18 #include "chrome/browser/notifications/notification_display_service_factory.h" |
18 #include "chrome/browser/notifications/notification_object_proxy.h" | 19 #include "chrome/browser/notifications/notification_object_proxy.h" |
19 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 20 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
20 #include "chrome/browser/permissions/permission_manager.h" | 21 #include "chrome/browser/permissions/permission_manager.h" |
21 #include "chrome/browser/permissions/permission_result.h" | 22 #include "chrome/browser/permissions/permission_result.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_attributes_storage.h" | 24 #include "chrome/browser/profiles/profile_attributes_storage.h" |
24 #include "chrome/browser/profiles/profile_io_data.h" | 25 #include "chrome/browser/profiles/profile_io_data.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/safe_browsing/ping_manager.h" | 27 #include "chrome/browser/safe_browsing/ping_manager.h" |
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
31 #include "components/content_settings/core/browser/host_content_settings_map.h" | 32 #include "components/content_settings/core/browser/host_content_settings_map.h" |
32 #include "components/content_settings/core/common/content_settings.h" | 33 #include "components/content_settings/core/common/content_settings.h" |
33 #include "components/content_settings/core/common/content_settings_types.h" | 34 #include "components/content_settings/core/common/content_settings_types.h" |
34 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/desktop_notification_delegate.h" | 37 #include "content/public/browser/desktop_notification_delegate.h" |
37 #include "content/public/browser/notification_event_dispatcher.h" | 38 #include "content/public/browser/notification_event_dispatcher.h" |
38 #include "content/public/browser/user_metrics.h" | |
39 #include "content/public/common/notification_resources.h" | 39 #include "content/public/common/notification_resources.h" |
40 #include "content/public/common/platform_notification_data.h" | 40 #include "content/public/common/platform_notification_data.h" |
41 #include "extensions/features/features.h" | 41 #include "extensions/features/features.h" |
42 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
44 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
45 #include "ui/message_center/notification.h" | 45 #include "ui/message_center/notification.h" |
46 #include "ui/message_center/notification_types.h" | 46 #include "ui/message_center/notification_types.h" |
47 #include "ui/message_center/notifier_settings.h" | 47 #include "ui/message_center/notifier_settings.h" |
48 #include "url/url_constants.h" | 48 #include "url/url_constants.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 int action_index, | 127 int action_index, |
128 const base::NullableString16& reply) { | 128 const base::NullableString16& reply) { |
129 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
130 blink::mojom::PermissionStatus permission_status = | 130 blink::mojom::PermissionStatus permission_status = |
131 CheckPermissionOnUIThread(browser_context, origin, | 131 CheckPermissionOnUIThread(browser_context, origin, |
132 kInvalidRenderProcessId); | 132 kInvalidRenderProcessId); |
133 | 133 |
134 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. | 134 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. |
135 // Also change this method to be const again. | 135 // Also change this method to be const again. |
136 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { | 136 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { |
137 content::RecordAction(base::UserMetricsAction( | 137 base::RecordAction(base::UserMetricsAction( |
138 "Notifications.Persistent.ClickedWithoutPermission")); | 138 "Notifications.Persistent.ClickedWithoutPermission")); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 if (action_index == -1) { | 142 if (action_index == -1) { |
143 content::RecordAction(base::UserMetricsAction( | 143 base::RecordAction( |
144 "Notifications.Persistent.Clicked")); | 144 base::UserMetricsAction("Notifications.Persistent.Clicked")); |
145 } else { | 145 } else { |
146 content::RecordAction(base::UserMetricsAction( | 146 base::RecordAction(base::UserMetricsAction( |
147 "Notifications.Persistent.ClickedActionButton")); | 147 "Notifications.Persistent.ClickedActionButton")); |
148 } | 148 } |
149 | 149 |
150 #if BUILDFLAG(ENABLE_BACKGROUND) | 150 #if BUILDFLAG(ENABLE_BACKGROUND) |
151 // Ensure the browser stays alive while the event is processed. | 151 // Ensure the browser stays alive while the event is processed. |
152 if (pending_click_dispatch_events_++ == 0) { | 152 if (pending_click_dispatch_events_++ == 0) { |
153 click_dispatch_keep_alive_.reset( | 153 click_dispatch_keep_alive_.reset( |
154 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, | 154 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, |
155 KeepAliveRestartOption::DISABLED)); | 155 KeepAliveRestartOption::DISABLED)); |
156 } | 156 } |
(...skipping 13 matching lines...) Expand all Loading... |
170 const std::string& notification_id, | 170 const std::string& notification_id, |
171 const GURL& origin, | 171 const GURL& origin, |
172 bool by_user) { | 172 bool by_user) { |
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 173 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
174 | 174 |
175 // If we programatically closed this notification, don't dispatch any event. | 175 // If we programatically closed this notification, don't dispatch any event. |
176 if (closed_notifications_.erase(notification_id) != 0) | 176 if (closed_notifications_.erase(notification_id) != 0) |
177 return; | 177 return; |
178 | 178 |
179 if (by_user) { | 179 if (by_user) { |
180 content::RecordAction(base::UserMetricsAction( | 180 base::RecordAction( |
181 "Notifications.Persistent.ClosedByUser")); | 181 base::UserMetricsAction("Notifications.Persistent.ClosedByUser")); |
182 } else { | 182 } else { |
183 content::RecordAction(base::UserMetricsAction( | 183 base::RecordAction(base::UserMetricsAction( |
184 "Notifications.Persistent.ClosedProgrammatically")); | 184 "Notifications.Persistent.ClosedProgrammatically")); |
185 } | 185 } |
186 content::NotificationEventDispatcher::GetInstance() | 186 content::NotificationEventDispatcher::GetInstance() |
187 ->DispatchNotificationCloseEvent( | 187 ->DispatchNotificationCloseEvent( |
188 browser_context, notification_id, origin, by_user, | 188 browser_context, notification_id, origin, by_user, |
189 base::Bind( | 189 base::Bind( |
190 &PlatformNotificationServiceImpl::OnCloseEventDispatchComplete, | 190 &PlatformNotificationServiceImpl::OnCloseEventDispatchComplete, |
191 base::Unretained(this))); | 191 base::Unretained(this))); |
192 } | 192 } |
193 | 193 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 int settings_button_index = notification_data.actions.size(); | 356 int settings_button_index = notification_data.actions.size(); |
357 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 357 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
358 browser_context, notification_id, origin, settings_button_index); | 358 browser_context, notification_id, origin, settings_button_index); |
359 | 359 |
360 Notification notification = CreateNotificationFromData( | 360 Notification notification = CreateNotificationFromData( |
361 profile, service_worker_scope, origin, notification_data, | 361 profile, service_worker_scope, origin, notification_data, |
362 notification_resources, delegate); | 362 notification_resources, delegate); |
363 | 363 |
364 GetNotificationDisplayService(profile)->Display( | 364 GetNotificationDisplayService(profile)->Display( |
365 NotificationCommon::PERSISTENT, notification_id, notification); | 365 NotificationCommon::PERSISTENT, notification_id, notification); |
366 content::RecordAction( | 366 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown")); |
367 base::UserMetricsAction("Notifications.Persistent.Shown")); | |
368 } | 367 } |
369 | 368 |
370 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 369 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
371 BrowserContext* browser_context, | 370 BrowserContext* browser_context, |
372 const std::string& notification_id) { | 371 const std::string& notification_id) { |
373 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 372 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
374 | 373 |
375 Profile* profile = Profile::FromBrowserContext(browser_context); | 374 Profile* profile = Profile::FromBrowserContext(browser_context); |
376 DCHECK(profile); | 375 DCHECK(profile); |
377 | 376 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 535 |
537 void PlatformNotificationServiceImpl::RecordSiteEngagement( | 536 void PlatformNotificationServiceImpl::RecordSiteEngagement( |
538 BrowserContext* browser_context, | 537 BrowserContext* browser_context, |
539 const GURL& origin) { | 538 const GURL& origin) { |
540 // TODO(dominickn, peter): This would be better if the site engagement service | 539 // TODO(dominickn, peter): This would be better if the site engagement service |
541 // could directly observe each notification. | 540 // could directly observe each notification. |
542 SiteEngagementService* engagement_service = | 541 SiteEngagementService* engagement_service = |
543 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); | 542 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
544 engagement_service->HandleNotificationInteraction(origin); | 543 engagement_service->HandleNotificationInteraction(origin); |
545 } | 544 } |
OLD | NEW |