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

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

Issue 2095223002: Refactor notification operation functionality out of PNS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove renamed files Created 4 years, 5 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/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics_action.h" 12 #include "base/metrics/user_metrics_action.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.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/notifications/notification_display_service_factory.h" 18 #include "chrome/browser/notifications/notification_display_service_factory.h"
19 #include "chrome/browser/notifications/notification_object_proxy.h" 19 #include "chrome/browser/notifications/notification_object_proxy.h"
20 #include "chrome/browser/notifications/notification_ui_manager.h" 20 #include "chrome/browser/notifications/notification_ui_manager.h"
21 #include "chrome/browser/notifications/persistent_notification_delegate.h" 21 #include "chrome/browser/notifications/persistent_notification_delegate.h"
22 #include "chrome/browser/permissions/permission_manager.h" 22 #include "chrome/browser/permissions/permission_manager.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_attributes_storage.h" 24 #include "chrome/browser/profiles/profile_attributes_storage.h"
25 #include "chrome/browser/profiles/profile_io_data.h" 25 #include "chrome/browser/profiles/profile_io_data.h"
26 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/chrome_pages.h"
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
30 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
32 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
34 #include "components/content_settings/core/common/content_settings.h" 32 #include "components/content_settings/core/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.h" 33 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
37 #include "components/url_formatter/url_formatter.h" 35 #include "components/url_formatter/url_formatter.h"
38 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/desktop_notification_delegate.h" 37 #include "content/public/browser/desktop_notification_delegate.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 79
82 void OnCloseNonPersistentNotificationProfileLoaded( 80 void OnCloseNonPersistentNotificationProfileLoaded(
83 const std::string& notification_id, 81 const std::string& notification_id,
84 Profile* profile) { 82 Profile* profile) {
85 NotificationDisplayServiceFactory::GetForProfile(profile)->Close( 83 NotificationDisplayServiceFactory::GetForProfile(profile)->Close(
86 notification_id); 84 notification_id);
87 } 85 }
88 86
89 // Callback to run once the profile has been loaded in order to perform a 87 // Callback to run once the profile has been loaded in order to perform a
90 // given |operation| in a notification. 88 // given |operation| in a notification.
91 void ProfileLoadedCallback( 89 void ProfileLoadedCallback(NotificationCommon::Operation operation,
92 PlatformNotificationServiceImpl::NotificationOperation operation, 90 const GURL& origin,
93 const GURL& origin, 91 int64_t persistent_notification_id,
94 int64_t persistent_notification_id, 92 int action_index,
95 int action_index, 93 Profile* profile) {
96 Profile* profile) {
97 if (!profile) { 94 if (!profile) {
98 // TODO(miguelg): Add UMA for this condition. 95 // TODO(miguelg): Add UMA for this condition.
99 // Perhaps propagate this through PersistentNotificationStatus. 96 // Perhaps propagate this through PersistentNotificationStatus.
100 LOG(WARNING) << "Profile not loaded correctly"; 97 LOG(WARNING) << "Profile not loaded correctly";
101 return; 98 return;
102 } 99 }
103 100
104 switch (operation) { 101 switch (operation) {
105 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: 102 case NotificationCommon::NOTIFICATION_CLICK:
106 PlatformNotificationServiceImpl::GetInstance() 103 PlatformNotificationServiceImpl::GetInstance()
107 ->OnPersistentNotificationClick(profile, persistent_notification_id, 104 ->OnPersistentNotificationClick(profile, persistent_notification_id,
108 origin, action_index); 105 origin, action_index);
109 break; 106 break;
110 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: 107 case NotificationCommon::NOTIFICATION_CLOSE:
111 PlatformNotificationServiceImpl::GetInstance() 108 PlatformNotificationServiceImpl::GetInstance()
112 ->OnPersistentNotificationClose(profile, persistent_notification_id, 109 ->OnPersistentNotificationClose(profile, persistent_notification_id,
113 origin, true); 110 origin, true);
114 break; 111 break;
115 case PlatformNotificationServiceImpl::NOTIFICATION_SETTINGS: 112 case NotificationCommon::NOTIFICATION_SETTINGS:
116 PlatformNotificationServiceImpl::GetInstance()->OpenNotificationSettings( 113 NotificationCommon::OpenNotificationSettings(profile);
117 profile);
118 break; 114 break;
119 } 115 }
120 } 116 }
121 117
122 // Callback used to close an non-persistent notification from blink. 118 // Callback used to close an non-persistent notification from blink.
123 void CancelNotification(const std::string& notification_id, 119 void CancelNotification(const std::string& notification_id,
124 std::string profile_id, 120 std::string profile_id,
125 bool incognito) { 121 bool incognito) {
126 ProfileManager* profile_manager = g_browser_process->profile_manager(); 122 ProfileManager* profile_manager = g_browser_process->profile_manager();
127 DCHECK(profile_manager); 123 DCHECK(profile_manager);
(...skipping 14 matching lines...) Expand all
142 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() 138 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl()
143 : test_display_service_(nullptr) { 139 : test_display_service_(nullptr) {
144 #if BUILDFLAG(ENABLE_BACKGROUND) 140 #if BUILDFLAG(ENABLE_BACKGROUND)
145 pending_click_dispatch_events_ = 0; 141 pending_click_dispatch_events_ = 0;
146 #endif 142 #endif
147 } 143 }
148 144
149 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} 145 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
150 146
151 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( 147 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation(
152 NotificationOperation operation, 148 NotificationCommon::Operation operation,
153 const std::string& profile_id, 149 const std::string& profile_id,
154 bool incognito, 150 bool incognito,
155 const GURL& origin, 151 const GURL& origin,
156 int64_t persistent_notification_id, 152 int64_t persistent_notification_id,
157 int action_index) { 153 int action_index) {
158 ProfileManager* profile_manager = g_browser_process->profile_manager(); 154 ProfileManager* profile_manager = g_browser_process->profile_manager();
159 DCHECK(profile_manager); 155 DCHECK(profile_manager);
160 156
161 profile_manager->LoadProfile( 157 profile_manager->LoadProfile(
162 profile_id, incognito, 158 profile_id, incognito,
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 517 }
522 518
523 NotificationDisplayService* 519 NotificationDisplayService*
524 PlatformNotificationServiceImpl::GetNotificationDisplayService( 520 PlatformNotificationServiceImpl::GetNotificationDisplayService(
525 Profile* profile) { 521 Profile* profile) {
526 if (test_display_service_ != nullptr) 522 if (test_display_service_ != nullptr)
527 return test_display_service_; 523 return test_display_service_;
528 return NotificationDisplayServiceFactory::GetForProfile(profile); 524 return NotificationDisplayServiceFactory::GetForProfile(profile);
529 } 525 }
530 526
531 void PlatformNotificationServiceImpl::OpenNotificationSettings(
532 BrowserContext* browser_context) {
533 #if defined(OS_ANDROID)
534 NOTIMPLEMENTED();
535 #else
536
537 Profile* profile = Profile::FromBrowserContext(browser_context);
538 DCHECK(profile);
539
540 if (switches::SettingsWindowEnabled()) {
541 chrome::ShowContentSettingsExceptionsInWindow(
542 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
543 } else {
544 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile);
545 chrome::ShowContentSettingsExceptions(browser_displayer.browser(),
546 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
547 }
548
549 #endif // defined(OS_ANDROID)
550 }
551
552 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( 527 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage(
553 Profile* profile, 528 Profile* profile,
554 const GURL& origin) const { 529 const GURL& origin) const {
555 #if defined(ENABLE_EXTENSIONS) 530 #if defined(ENABLE_EXTENSIONS)
556 // If the source is an extension, lookup the display name. 531 // If the source is an extension, lookup the display name.
557 if (origin.SchemeIs(extensions::kExtensionScheme)) { 532 if (origin.SchemeIs(extensions::kExtensionScheme)) {
558 const extensions::Extension* extension = 533 const extensions::Extension* extension =
559 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 534 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
560 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 535 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
561 DCHECK(extension); 536 DCHECK(extension);
562 537
563 return base::UTF8ToUTF16(extension->name()); 538 return base::UTF8ToUTF16(extension->name());
564 } 539 }
565 #endif 540 #endif
566 541
567 return base::string16(); 542 return base::string16();
568 } 543 }
569 544
570 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( 545 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting(
571 NotificationDisplayService* display_service) { 546 NotificationDisplayService* display_service) {
572 test_display_service_ = display_service; 547 test_display_service_ = display_service;
573 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698