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_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/engagement/site_engagement_service.h" |
16 #include "chrome/browser/notifications/notification_display_service_factory.h" | 17 #include "chrome/browser/notifications/notification_display_service_factory.h" |
17 #include "chrome/browser/notifications/notification_object_proxy.h" | 18 #include "chrome/browser/notifications/notification_object_proxy.h" |
18 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 19 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
19 #include "chrome/browser/permissions/permission_manager.h" | 20 #include "chrome/browser/permissions/permission_manager.h" |
20 #include "chrome/browser/permissions/permission_result.h" | 21 #include "chrome/browser/permissions/permission_result.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/profiles/profile_attributes_storage.h" | 23 #include "chrome/browser/profiles/profile_attributes_storage.h" |
23 #include "chrome/browser/profiles/profile_io_data.h" | 24 #include "chrome/browser/profiles/profile_io_data.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/safe_browsing/ping_manager.h" | 26 #include "chrome/browser/safe_browsing/ping_manager.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 #if BUILDFLAG(ENABLE_BACKGROUND) | 150 #if BUILDFLAG(ENABLE_BACKGROUND) |
150 // Ensure the browser stays alive while the event is processed. | 151 // Ensure the browser stays alive while the event is processed. |
151 if (pending_click_dispatch_events_++ == 0) { | 152 if (pending_click_dispatch_events_++ == 0) { |
152 click_dispatch_keep_alive_.reset( | 153 click_dispatch_keep_alive_.reset( |
153 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, | 154 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, |
154 KeepAliveRestartOption::DISABLED)); | 155 KeepAliveRestartOption::DISABLED)); |
155 } | 156 } |
156 #endif | 157 #endif |
157 | 158 |
| 159 RecordSiteEngagement(browser_context, origin); |
158 content::NotificationEventDispatcher::GetInstance() | 160 content::NotificationEventDispatcher::GetInstance() |
159 ->DispatchNotificationClickEvent( | 161 ->DispatchNotificationClickEvent( |
160 browser_context, notification_id, origin, action_index, reply, | 162 browser_context, notification_id, origin, action_index, reply, |
161 base::Bind( | 163 base::Bind( |
162 &PlatformNotificationServiceImpl::OnClickEventDispatchComplete, | 164 &PlatformNotificationServiceImpl::OnClickEventDispatchComplete, |
163 base::Unretained(this))); | 165 base::Unretained(this))); |
164 } | 166 } |
165 | 167 |
166 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( | 168 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( |
167 BrowserContext* browser_context, | 169 BrowserContext* browser_context, |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 524 } |
523 #endif | 525 #endif |
524 | 526 |
525 return base::string16(); | 527 return base::string16(); |
526 } | 528 } |
527 | 529 |
528 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 530 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
529 NotificationDisplayService* display_service) { | 531 NotificationDisplayService* display_service) { |
530 test_display_service_ = display_service; | 532 test_display_service_ = display_service; |
531 } | 533 } |
| 534 |
| 535 void PlatformNotificationServiceImpl::RecordSiteEngagement( |
| 536 BrowserContext* browser_context, |
| 537 const GURL& origin) { |
| 538 // TODO(dominickn, peter): This would be better if the site engagement service |
| 539 // could directly observe each notification. |
| 540 SiteEngagementService* engagement_service = |
| 541 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
| 542 engagement_service->HandleNotificationInteraction(origin); |
| 543 } |
OLD | NEW |