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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 2906883003: Deprecate per notification type delegates. (Closed)
Patch Set: rebase Created 3 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 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.h"
12 #include "base/metrics/user_metrics_action.h" 12 #include "base/metrics/user_metrics_action.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
17 #include "chrome/browser/engagement/site_engagement_service.h" 17 #include "chrome/browser/engagement/site_engagement_service.h"
18 #include "chrome/browser/notifications/native_notification_delegate.h" 18 #include "chrome/browser/notifications/native_notification_delegate.h"
19 #include "chrome/browser/notifications/notification_common.h" 19 #include "chrome/browser/notifications/notification_common.h"
20 #include "chrome/browser/notifications/notification_display_service_factory.h" 20 #include "chrome/browser/notifications/notification_display_service_factory.h"
21 #include "chrome/browser/notifications/notification_object_proxy.h" 21 #include "chrome/browser/notifications/web_notification_delegate.h"
22 #include "chrome/browser/notifications/persistent_notification_delegate.h"
23 #include "chrome/browser/permissions/permission_manager.h" 22 #include "chrome/browser/permissions/permission_manager.h"
24 #include "chrome/browser/permissions/permission_result.h" 23 #include "chrome/browser/permissions/permission_result.h"
25 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_attributes_storage.h" 25 #include "chrome/browser/profiles/profile_attributes_storage.h"
27 #include "chrome/browser/profiles/profile_io_data.h" 26 #include "chrome/browser/profiles/profile_io_data.h"
28 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
29 #include "chrome/browser/safe_browsing/ping_manager.h" 28 #include "chrome/browser/safe_browsing/ping_manager.h"
30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 29 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
31 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
32 #include "chrome/common/chrome_features.h" 31 #include "chrome/common/chrome_features.h"
33 #include "chrome/common/features.h" 32 #include "chrome/common/features.h"
34 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
35 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
36 #include "components/content_settings/core/browser/host_content_settings_map.h" 35 #include "components/content_settings/core/browser/host_content_settings_map.h"
37 #include "components/content_settings/core/common/content_settings.h" 36 #include "components/content_settings/core/common/content_settings.h"
38 #include "components/content_settings/core/common/content_settings_types.h" 37 #include "components/content_settings/core/common/content_settings_types.h"
39 #include "components/prefs/pref_service.h" 38 #include "components/prefs/pref_service.h"
40 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/desktop_notification_delegate.h"
42 #include "content/public/browser/notification_event_dispatcher.h" 40 #include "content/public/browser/notification_event_dispatcher.h"
43 #include "content/public/common/notification_resources.h" 41 #include "content/public/common/notification_resources.h"
44 #include "content/public/common/platform_notification_data.h" 42 #include "content/public/common/platform_notification_data.h"
45 #include "extensions/features/features.h" 43 #include "extensions/features/features.h"
46 #include "third_party/skia/include/core/SkBitmap.h" 44 #include "third_party/skia/include/core/SkBitmap.h"
47 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/message_center/notification.h" 47 #include "ui/message_center/notification.h"
50 #include "ui/message_center/notification_types.h" 48 #include "ui/message_center/notification_types.h"
51 #include "ui/message_center/notifier_settings.h" 49 #include "ui/message_center/notifier_settings.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 293
296 return blink::mojom::PermissionStatus::ASK; 294 return blink::mojom::PermissionStatus::ASK;
297 } 295 }
298 296
299 void PlatformNotificationServiceImpl::DisplayNotification( 297 void PlatformNotificationServiceImpl::DisplayNotification(
300 BrowserContext* browser_context, 298 BrowserContext* browser_context,
301 const std::string& notification_id, 299 const std::string& notification_id,
302 const GURL& origin, 300 const GURL& origin,
303 const content::PlatformNotificationData& notification_data, 301 const content::PlatformNotificationData& notification_data,
304 const content::NotificationResources& notification_resources, 302 const content::NotificationResources& notification_resources,
305 std::unique_ptr<content::DesktopNotificationDelegate> delegate,
306 base::Closure* cancel_callback) { 303 base::Closure* cancel_callback) {
307 DCHECK_CURRENTLY_ON(BrowserThread::UI); 304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
308 305
309 // Posted tasks can request notifications to be added, which would cause a 306 // Posted tasks can request notifications to be added, which would cause a
310 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not 307 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not
311 // see the notification anyway, since we are shutting down. 308 // see the notification anyway, since we are shutting down.
312 if (g_browser_process->IsShuttingDown()) 309 if (g_browser_process->IsShuttingDown())
313 return; 310 return;
314 311
315 Profile* profile = Profile::FromBrowserContext(browser_context); 312 Profile* profile = Profile::FromBrowserContext(browser_context);
316 DCHECK(profile); 313 DCHECK(profile);
317 DCHECK_EQ(0u, notification_data.actions.size()); 314 DCHECK_EQ(0u, notification_data.actions.size());
318 DCHECK_EQ(0u, notification_resources.action_icons.size()); 315 DCHECK_EQ(0u, notification_resources.action_icons.size());
319 316
320 // Temporary change while the delegates are merged. 317 NotificationDelegate* notification_delegate = new WebNotificationDelegate(
321 NotificationDelegate* notification_delegate; 318 NotificationCommon::NON_PERSISTENT, profile, notification_id, origin);
322 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
323 if (base::FeatureList::IsEnabled(features::kNativeNotifications) &&
324 g_browser_process->notification_platform_bridge()) {
325 notification_delegate = new NativeNotificationDelegate(notification_id);
326 } else {
327 notification_delegate = new NotificationObjectProxy(
328 browser_context, notification_id, origin, std::move(delegate));
329 }
330 #else
331 notification_delegate = new NotificationObjectProxy(
332 browser_context, notification_id, origin, std::move(delegate));
333 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
334 319
335 Notification notification = CreateNotificationFromData( 320 Notification notification = CreateNotificationFromData(
336 profile, GURL() /* service_worker_scope */, origin, notification_data, 321 profile, GURL() /* service_worker_scope */, origin, notification_data,
337 notification_resources, notification_delegate); 322 notification_resources, notification_delegate);
338 323
339 GetNotificationDisplayService(profile)->Display( 324 GetNotificationDisplayService(profile)->Display(
340 NotificationCommon::NON_PERSISTENT, notification_id, notification); 325 NotificationCommon::NON_PERSISTENT, notification_id, notification);
341 if (cancel_callback) { 326 if (cancel_callback) {
342 #if defined(OS_WIN) 327 #if defined(OS_WIN)
343 std::string profile_id = 328 std::string profile_id =
(...skipping 17 matching lines...) Expand all
361 346
362 // Posted tasks can request notifications to be added, which would cause a 347 // Posted tasks can request notifications to be added, which would cause a
363 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not 348 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not
364 // see the notification anyway, since we are shutting down. 349 // see the notification anyway, since we are shutting down.
365 if (g_browser_process->IsShuttingDown()) 350 if (g_browser_process->IsShuttingDown())
366 return; 351 return;
367 352
368 Profile* profile = Profile::FromBrowserContext(browser_context); 353 Profile* profile = Profile::FromBrowserContext(browser_context);
369 DCHECK(profile); 354 DCHECK(profile);
370 355
371 // The notification settings button will be appended after the developer- 356 NotificationDelegate* delegate = new WebNotificationDelegate(
372 // supplied buttons, available in |notification_data.actions|. 357 NotificationCommon::PERSISTENT, profile, notification_id, origin);
373 int settings_button_index = notification_data.actions.size();
374
375 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate(
376 browser_context, notification_id, origin, settings_button_index);
377 358
378 Notification notification = CreateNotificationFromData( 359 Notification notification = CreateNotificationFromData(
379 profile, service_worker_scope, origin, notification_data, 360 profile, service_worker_scope, origin, notification_data,
380 notification_resources, delegate); 361 notification_resources, delegate);
381 362
382 GetNotificationDisplayService(profile)->Display( 363 GetNotificationDisplayService(profile)->Display(
383 NotificationCommon::PERSISTENT, notification_id, notification); 364 NotificationCommon::PERSISTENT, notification_id, notification);
384 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown")); 365 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown"));
385 } 366 }
386 367
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 534
554 void PlatformNotificationServiceImpl::RecordSiteEngagement( 535 void PlatformNotificationServiceImpl::RecordSiteEngagement(
555 BrowserContext* browser_context, 536 BrowserContext* browser_context,
556 const GURL& origin) { 537 const GURL& origin) {
557 // TODO(dominickn, peter): This would be better if the site engagement service 538 // TODO(dominickn, peter): This would be better if the site engagement service
558 // could directly observe each notification. 539 // could directly observe each notification.
559 SiteEngagementService* engagement_service = 540 SiteEngagementService* engagement_service =
560 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); 541 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context));
561 engagement_service->HandleNotificationInteraction(origin); 542 engagement_service->HandleNotificationInteraction(origin);
562 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698