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

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

Issue 2921263002: Remove many delegates, let's see what breaks
Patch Set: compile 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 "base/time/time.h" 14 #include "base/time/time.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
18 #include "chrome/browser/engagement/site_engagement_service.h" 18 #include "chrome/browser/engagement/site_engagement_service.h"
19 #include "chrome/browser/notifications/native_notification_delegate.h"
20 #include "chrome/browser/notifications/notification_common.h" 19 #include "chrome/browser/notifications/notification_common.h"
21 #include "chrome/browser/notifications/notification_display_service_factory.h" 20 #include "chrome/browser/notifications/notification_display_service_factory.h"
22 #include "chrome/browser/notifications/notification_object_proxy.h" 21 #include "chrome/browser/notifications/web_notification_delegate.h"
23 #include "chrome/browser/notifications/persistent_notification_delegate.h"
24 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" 22 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
25 #include "chrome/browser/permissions/permission_manager.h" 23 #include "chrome/browser/permissions/permission_manager.h"
26 #include "chrome/browser/permissions/permission_result.h" 24 #include "chrome/browser/permissions/permission_result.h"
27 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/profiles/profile_attributes_storage.h" 26 #include "chrome/browser/profiles/profile_attributes_storage.h"
29 #include "chrome/browser/profiles/profile_io_data.h" 27 #include "chrome/browser/profiles/profile_io_data.h"
30 #include "chrome/browser/profiles/profile_manager.h" 28 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/browser/safe_browsing/ping_manager.h" 29 #include "chrome/browser/safe_browsing/ping_manager.h"
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
33 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
34 #include "chrome/common/chrome_features.h" 32 #include "chrome/common/chrome_features.h"
35 #include "chrome/common/features.h" 33 #include "chrome/common/features.h"
36 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
37 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
38 #include "components/content_settings/core/browser/host_content_settings_map.h" 36 #include "components/content_settings/core/browser/host_content_settings_map.h"
39 #include "components/content_settings/core/common/content_settings.h" 37 #include "components/content_settings/core/common/content_settings.h"
40 #include "components/content_settings/core/common/content_settings_types.h" 38 #include "components/content_settings/core/common/content_settings_types.h"
41 #include "components/prefs/pref_service.h" 39 #include "components/prefs/pref_service.h"
42 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/desktop_notification_delegate.h"
44 #include "content/public/browser/notification_event_dispatcher.h" 41 #include "content/public/browser/notification_event_dispatcher.h"
45 #include "content/public/common/notification_resources.h" 42 #include "content/public/common/notification_resources.h"
46 #include "content/public/common/platform_notification_data.h" 43 #include "content/public/common/platform_notification_data.h"
47 #include "extensions/features/features.h" 44 #include "extensions/features/features.h"
48 #include "third_party/skia/include/core/SkBitmap.h" 45 #include "third_party/skia/include/core/SkBitmap.h"
49 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
50 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
51 #include "ui/message_center/notification.h" 48 #include "ui/message_center/notification.h"
52 #include "ui/message_center/notification_types.h" 49 #include "ui/message_center/notification_types.h"
53 #include "ui/message_center/notifier_settings.h" 50 #include "ui/message_center/notifier_settings.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ? blink::mojom::PermissionStatus::ASK 305 ? blink::mojom::PermissionStatus::ASK
309 : blink::mojom::PermissionStatus::DENIED; 306 : blink::mojom::PermissionStatus::DENIED;
310 } 307 }
311 308
312 void PlatformNotificationServiceImpl::DisplayNotification( 309 void PlatformNotificationServiceImpl::DisplayNotification(
313 BrowserContext* browser_context, 310 BrowserContext* browser_context,
314 const std::string& notification_id, 311 const std::string& notification_id,
315 const GURL& origin, 312 const GURL& origin,
316 const content::PlatformNotificationData& notification_data, 313 const content::PlatformNotificationData& notification_data,
317 const content::NotificationResources& notification_resources, 314 const content::NotificationResources& notification_resources,
318 std::unique_ptr<content::DesktopNotificationDelegate> delegate,
319 base::Closure* cancel_callback) { 315 base::Closure* cancel_callback) {
320 DCHECK_CURRENTLY_ON(BrowserThread::UI); 316 DCHECK_CURRENTLY_ON(BrowserThread::UI);
321 317
322 // Posted tasks can request notifications to be added, which would cause a 318 // Posted tasks can request notifications to be added, which would cause a
323 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not 319 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not
324 // see the notification anyway, since we are shutting down. 320 // see the notification anyway, since we are shutting down.
325 if (g_browser_process->IsShuttingDown()) 321 if (g_browser_process->IsShuttingDown())
326 return; 322 return;
327 323
328 Profile* profile = Profile::FromBrowserContext(browser_context); 324 Profile* profile = Profile::FromBrowserContext(browser_context);
329 DCHECK(profile); 325 DCHECK(profile);
330 DCHECK_EQ(0u, notification_data.actions.size()); 326 DCHECK_EQ(0u, notification_data.actions.size());
331 DCHECK_EQ(0u, notification_resources.action_icons.size()); 327 DCHECK_EQ(0u, notification_resources.action_icons.size());
332 328
333 // Temporary change while the delegates are merged. 329 NotificationDelegate* notification_delegate = new WebNotificationDelegate(
334 NotificationDelegate* notification_delegate; 330 NotificationCommon::NON_PERSISTENT, profile, notification_id, origin);
335 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
336 if (base::FeatureList::IsEnabled(features::kNativeNotifications) &&
337 g_browser_process->notification_platform_bridge()) {
338 notification_delegate = new NativeNotificationDelegate(notification_id);
339 } else {
340 notification_delegate = new NotificationObjectProxy(
341 browser_context, notification_id, origin, std::move(delegate));
342 }
343 #else
344 notification_delegate = new NotificationObjectProxy(
345 browser_context, notification_id, origin, std::move(delegate));
346 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
347 331
348 Notification notification = CreateNotificationFromData( 332 Notification notification = CreateNotificationFromData(
349 profile, GURL() /* service_worker_scope */, origin, notification_data, 333 profile, GURL() /* service_worker_scope */, origin, notification_data,
350 notification_resources, notification_delegate); 334 notification_resources, notification_delegate);
351 335
352 GetNotificationDisplayService(profile)->Display( 336 GetNotificationDisplayService(profile)->Display(
353 NotificationCommon::NON_PERSISTENT, notification_id, notification); 337 NotificationCommon::NON_PERSISTENT, notification_id, notification);
354 if (cancel_callback) { 338 if (cancel_callback) {
355 #if defined(OS_WIN) 339 #if defined(OS_WIN)
356 std::string profile_id = 340 std::string profile_id =
(...skipping 17 matching lines...) Expand all
374 358
375 // Posted tasks can request notifications to be added, which would cause a 359 // Posted tasks can request notifications to be added, which would cause a
376 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not 360 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not
377 // see the notification anyway, since we are shutting down. 361 // see the notification anyway, since we are shutting down.
378 if (g_browser_process->IsShuttingDown()) 362 if (g_browser_process->IsShuttingDown())
379 return; 363 return;
380 364
381 Profile* profile = Profile::FromBrowserContext(browser_context); 365 Profile* profile = Profile::FromBrowserContext(browser_context);
382 DCHECK(profile); 366 DCHECK(profile);
383 367
384 // The notification settings button will be appended after the developer- 368 NotificationDelegate* delegate = new WebNotificationDelegate(
385 // supplied buttons, available in |notification_data.actions|. 369 NotificationCommon::PERSISTENT, profile, notification_id, origin);
386 int settings_button_index = notification_data.actions.size();
387
388 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate(
389 browser_context, notification_id, origin, settings_button_index);
390 370
391 Notification notification = CreateNotificationFromData( 371 Notification notification = CreateNotificationFromData(
392 profile, service_worker_scope, origin, notification_data, 372 profile, service_worker_scope, origin, notification_data,
393 notification_resources, delegate); 373 notification_resources, delegate);
394 374
395 GetNotificationDisplayService(profile)->Display( 375 GetNotificationDisplayService(profile)->Display(
396 NotificationCommon::PERSISTENT, notification_id, notification); 376 NotificationCommon::PERSISTENT, notification_id, notification);
397 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown")); 377 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown"));
398 } 378 }
399 379
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 546
567 void PlatformNotificationServiceImpl::RecordSiteEngagement( 547 void PlatformNotificationServiceImpl::RecordSiteEngagement(
568 BrowserContext* browser_context, 548 BrowserContext* browser_context,
569 const GURL& origin) { 549 const GURL& origin) {
570 // TODO(dominickn, peter): This would be better if the site engagement service 550 // TODO(dominickn, peter): This would be better if the site engagement service
571 // could directly observe each notification. 551 // could directly observe each notification.
572 SiteEngagementService* engagement_service = 552 SiteEngagementService* engagement_service =
573 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); 553 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context));
574 engagement_service->HandleNotificationInteraction(origin); 554 engagement_service->HandleNotificationInteraction(origin);
575 } 555 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698