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

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

Issue 1026853002: Integrate the notification database with the normal code path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ConfirmShow
Patch Set: Created 5 years, 8 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 "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 29 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
30 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
32 #include "extensions/browser/info_map.h" 32 #include "extensions/browser/info_map.h"
33 #include "extensions/common/constants.h" 33 #include "extensions/common/constants.h"
34 #include "extensions/common/extension_set.h" 34 #include "extensions/common/extension_set.h"
35 #include "extensions/common/permissions/api_permission.h" 35 #include "extensions/common/permissions/api_permission.h"
36 #include "extensions/common/permissions/permissions_data.h" 36 #include "extensions/common/permissions/permissions_data.h"
37 #endif 37 #endif
38 38
39 #if defined(OS_ANDROID)
40 #include "base/strings/string_number_conversions.h"
41 #endif
42
39 using content::BrowserThread; 43 using content::BrowserThread;
40 using message_center::NotifierId; 44 using message_center::NotifierId;
41 45
42 namespace { 46 namespace {
43 47
44 void CancelNotification(const std::string& id, ProfileID profile_id) { 48 void CancelNotification(const std::string& id, ProfileID profile_id) {
45 PlatformNotificationServiceImpl::GetInstance() 49 PlatformNotificationServiceImpl::GetInstance()
46 ->GetNotificationUIManager()->CancelById(id, profile_id); 50 ->GetNotificationUIManager()->CancelById(id, profile_id);
47 } 51 }
48 52
49 } // namespace 53 } // namespace
50 54
51 // static 55 // static
52 PlatformNotificationServiceImpl* 56 PlatformNotificationServiceImpl*
53 PlatformNotificationServiceImpl::GetInstance() { 57 PlatformNotificationServiceImpl::GetInstance() {
54 return Singleton<PlatformNotificationServiceImpl>::get(); 58 return Singleton<PlatformNotificationServiceImpl>::get();
55 } 59 }
56 60
57 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() 61 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl()
58 : notification_ui_manager_for_tests_(nullptr) {} 62 : notification_ui_manager_for_tests_(nullptr) {}
59 63
60 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} 64 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
61 65
62 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( 66 void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
63 content::BrowserContext* browser_context, 67 content::BrowserContext* browser_context,
64 int64 service_worker_registration_id, 68 int64_t persistent_notification_id,
65 const std::string& notification_id,
66 const GURL& origin, 69 const GURL& origin,
67 const content::PlatformNotificationData& notification_data,
68 const base::Callback<void(content::PersistentNotificationStatus)>& 70 const base::Callback<void(content::PersistentNotificationStatus)>&
69 callback) const { 71 callback) const {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI); 72 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 content::NotificationEventDispatcher::GetInstance() 73 content::NotificationEventDispatcher::GetInstance()
72 ->DispatchNotificationClickEvent( 74 ->DispatchNotificationClickEvent(
73 browser_context, 75 browser_context,
76 persistent_notification_id,
74 origin, 77 origin,
75 service_worker_registration_id,
76 notification_id,
77 notification_data,
78 callback); 78 callback);
79 } 79 }
80 80
81 blink::WebNotificationPermission 81 blink::WebNotificationPermission
82 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( 82 PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
83 content::BrowserContext* browser_context, 83 content::BrowserContext* browser_context,
84 const GURL& origin, 84 const GURL& origin,
85 int render_process_id) { 85 int render_process_id) {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); 86 DCHECK_CURRENTLY_ON(BrowserThread::UI);
87 87
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 base::Bind(&CancelNotification, 211 base::Bind(&CancelNotification,
212 notification.delegate_id(), 212 notification.delegate_id(),
213 NotificationUIManager::GetProfileID(profile)); 213 NotificationUIManager::GetProfileID(profile));
214 214
215 profile->GetHostContentSettingsMap()->UpdateLastUsage( 215 profile->GetHostContentSettingsMap()->UpdateLastUsage(
216 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 216 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
217 } 217 }
218 218
219 void PlatformNotificationServiceImpl::DisplayPersistentNotification( 219 void PlatformNotificationServiceImpl::DisplayPersistentNotification(
220 content::BrowserContext* browser_context, 220 content::BrowserContext* browser_context,
221 int64 service_worker_registration_id, 221 int64_t persistent_notification_id,
222 const GURL& origin, 222 const GURL& origin,
223 const SkBitmap& icon, 223 const SkBitmap& icon,
224 const content::PlatformNotificationData& notification_data) { 224 const content::PlatformNotificationData& notification_data) {
225 DCHECK_CURRENTLY_ON(BrowserThread::UI); 225 DCHECK_CURRENTLY_ON(BrowserThread::UI);
226 226
227 Profile* profile = Profile::FromBrowserContext(browser_context); 227 Profile* profile = Profile::FromBrowserContext(browser_context);
228 DCHECK(profile); 228 DCHECK(profile);
229 229
230 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( 230 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate(
231 browser_context, 231 browser_context, persistent_notification_id, origin);
232 service_worker_registration_id,
233 origin,
234 notification_data);
235 232
236 Notification notification = CreateNotificationFromData( 233 Notification notification = CreateNotificationFromData(
237 profile, origin, icon, notification_data, delegate); 234 profile, origin, icon, notification_data, delegate);
238 235
236 // TODO(peter): Remove this mapping when we have reliable id generation for
237 // the message_center::Notification objects.
238 persistent_notifications_[persistent_notification_id] = notification.id();
239
239 GetNotificationUIManager()->Add(notification, profile); 240 GetNotificationUIManager()->Add(notification, profile);
240 241
241 profile->GetHostContentSettingsMap()->UpdateLastUsage( 242 profile->GetHostContentSettingsMap()->UpdateLastUsage(
242 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 243 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
243 } 244 }
244 245
245 void PlatformNotificationServiceImpl::ClosePersistentNotification( 246 void PlatformNotificationServiceImpl::ClosePersistentNotification(
246 content::BrowserContext* browser_context, 247 content::BrowserContext* browser_context,
247 const std::string& persistent_notification_id) { 248 int64_t persistent_notification_id) {
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); 249 DCHECK_CURRENTLY_ON(BrowserThread::UI);
249 250
250 Profile* profile = Profile::FromBrowserContext(browser_context); 251 Profile* profile = Profile::FromBrowserContext(browser_context);
251 DCHECK(profile); 252 DCHECK(profile);
252 253
254 #if defined(OS_ANDROID)
255 // TODO(peter): Remove this conversion when the notification ids are being
256 // generated by the caller of this method.
257 std::string textual_persistent_notification_id =
258 base::Int64ToString(persistent_notification_id);
253 GetNotificationUIManager()->CancelById( 259 GetNotificationUIManager()->CancelById(
254 persistent_notification_id, NotificationUIManager::GetProfileID(profile)); 260 textual_persistent_notification_id,
261 NotificationUIManager::GetProfileID(profile));
262 #else
263 auto iter = persistent_notifications_.find(persistent_notification_id);
264 if (iter == persistent_notifications_.end())
265 return;
266
267 GetNotificationUIManager()->CancelById(
268 iter->second, NotificationUIManager::GetProfileID(profile));
269
270 persistent_notifications_.erase(iter);
271 #endif
255 } 272 }
256 273
257 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( 274 Notification PlatformNotificationServiceImpl::CreateNotificationFromData(
258 Profile* profile, 275 Profile* profile,
259 const GURL& origin, 276 const GURL& origin,
260 const SkBitmap& icon, 277 const SkBitmap& icon,
261 const content::PlatformNotificationData& notification_data, 278 const content::PlatformNotificationData& notification_data,
262 NotificationDelegate* delegate) const { 279 NotificationDelegate* delegate) const {
263 base::string16 display_source = DisplayNameForOrigin(profile, origin); 280 base::string16 display_source = DisplayNameForOrigin(profile, origin);
264 281
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 formatted_origin.push_back(':'); 349 formatted_origin.push_back(':');
333 formatted_origin.append(base::UTF8ToUTF16(origin.port())); 350 formatted_origin.append(base::UTF8ToUTF16(origin.port()));
334 } 351 }
335 return formatted_origin; 352 return formatted_origin;
336 } 353 }
337 354
338 // TODO(dewittj): Once file:// URLs are passed in to the origin 355 // TODO(dewittj): Once file:// URLs are passed in to the origin
339 // GURL here, begin returning the path as the display name. 356 // GURL here, begin returning the path as the display name.
340 return net::FormatUrl(origin, languages); 357 return net::FormatUrl(origin, languages);
341 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698