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 "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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 if (iter == persistent_notifications_.end()) | 299 if (iter == persistent_notifications_.end()) |
300 return; | 300 return; |
301 | 301 |
302 GetNotificationUIManager()->CancelById( | 302 GetNotificationUIManager()->CancelById( |
303 iter->second, NotificationUIManager::GetProfileID(profile)); | 303 iter->second, NotificationUIManager::GetProfileID(profile)); |
304 | 304 |
305 persistent_notifications_.erase(iter); | 305 persistent_notifications_.erase(iter); |
306 #endif | 306 #endif |
307 } | 307 } |
308 | 308 |
| 309 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( |
| 310 BrowserContext* browser_context, |
| 311 std::set<std::string>* displayed_notifications) { |
| 312 DCHECK(displayed_notifications); |
| 313 |
| 314 #if !defined(OS_ANDROID) |
| 315 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 316 if (!profile || profile->AsTestingProfile()) |
| 317 return false; // Tests will not have a message center. |
| 318 |
| 319 // TODO(peter): Filter for persistent notifications only. |
| 320 *displayed_notifications = |
| 321 GetNotificationUIManager()->GetAllIdsByProfile(profile); |
| 322 |
| 323 return true; |
| 324 #else |
| 325 // Android cannot reliably return the notifications that are currently being |
| 326 // displayed on the platform, see the comment in NotificationUIManagerAndroid. |
| 327 return false; |
| 328 #endif // !defined(OS_ANDROID) |
| 329 } |
| 330 |
309 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 331 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
310 Profile* profile, | 332 Profile* profile, |
311 const GURL& origin, | 333 const GURL& origin, |
312 const SkBitmap& icon, | 334 const SkBitmap& icon, |
313 const content::PlatformNotificationData& notification_data, | 335 const content::PlatformNotificationData& notification_data, |
314 NotificationDelegate* delegate) const { | 336 NotificationDelegate* delegate) const { |
315 base::string16 display_source = DisplayNameForOrigin(profile, origin); | 337 base::string16 display_source = DisplayNameForOrigin(profile, origin); |
316 | 338 |
317 // TODO(peter): Icons for Web Notifications are currently always requested for | 339 // TODO(peter): Icons for Web Notifications are currently always requested for |
318 // 1x scale, whereas the displays on which they can be displayed can have a | 340 // 1x scale, whereas the displays on which they can be displayed can have a |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 formatted_origin.push_back(':'); | 407 formatted_origin.push_back(':'); |
386 formatted_origin.append(base::UTF8ToUTF16(origin.port())); | 408 formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
387 } | 409 } |
388 return formatted_origin; | 410 return formatted_origin; |
389 } | 411 } |
390 | 412 |
391 // TODO(dewittj): Once file:// URLs are passed in to the origin | 413 // TODO(dewittj): Once file:// URLs are passed in to the origin |
392 // GURL here, begin returning the path as the display name. | 414 // GURL here, begin returning the path as the display name. |
393 return net::FormatUrl(origin, languages); | 415 return net::FormatUrl(origin, languages); |
394 } | 416 } |
OLD | NEW |