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" |
11 #include "chrome/browser/notifications/notification_object_proxy.h" | 11 #include "chrome/browser/notifications/notification_object_proxy.h" |
12 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
13 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 13 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_io_data.h" | 15 #include "chrome/browser/profiles/profile_io_data.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
18 #include "components/content_settings/core/common/content_settings.h" | 18 #include "components/content_settings/core/common/content_settings.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/desktop_notification_delegate.h" | 20 #include "content/public/browser/desktop_notification_delegate.h" |
21 #include "content/public/browser/notification_event_dispatcher.h" | 21 #include "content/public/browser/notification_event_dispatcher.h" |
22 #include "content/public/browser/platform_notification_context.h" | 22 #include "content/public/browser/platform_notification_context.h" |
23 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
24 #include "content/public/browser/user_metrics.h" | |
24 #include "content/public/common/platform_notification_data.h" | 25 #include "content/public/common/platform_notification_data.h" |
25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
26 #include "ui/message_center/notifier_settings.h" | 27 #include "ui/message_center/notifier_settings.h" |
27 #include "url/url_constants.h" | 28 #include "url/url_constants.h" |
28 | 29 |
29 #if defined(ENABLE_EXTENSIONS) | 30 #if defined(ENABLE_EXTENSIONS) |
30 #include "chrome/browser/notifications/desktop_notification_service.h" | 31 #include "chrome/browser/notifications/desktop_notification_service.h" |
31 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 32 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
32 #include "extensions/browser/extension_registry.h" | 33 #include "extensions/browser/extension_registry.h" |
33 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
34 #include "extensions/browser/info_map.h" | 35 #include "extensions/browser/info_map.h" |
35 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
36 #include "extensions/common/extension_set.h" | 37 #include "extensions/common/extension_set.h" |
37 #include "extensions/common/permissions/api_permission.h" | 38 #include "extensions/common/permissions/api_permission.h" |
38 #include "extensions/common/permissions/permissions_data.h" | 39 #include "extensions/common/permissions/permissions_data.h" |
39 #endif | 40 #endif |
40 | 41 |
41 #if defined(OS_ANDROID) | |
42 #include "base/strings/string_number_conversions.h" | 42 #include "base/strings/string_number_conversions.h" |
43 #endif | |
44 | 43 |
45 using content::BrowserContext; | 44 using content::BrowserContext; |
46 using content::BrowserThread; | 45 using content::BrowserThread; |
47 using content::PlatformNotificationContext; | 46 using content::PlatformNotificationContext; |
48 using message_center::NotifierId; | 47 using message_center::NotifierId; |
49 | 48 |
50 namespace { | 49 namespace { |
51 | 50 |
52 // Callback to provide when deleting the data associated with persistent Web | 51 // Callback to provide when deleting the data associated with persistent Web |
53 // Notifications from the notification database. | 52 // Notifications from the notification database. |
54 void OnPersistentNotificationDataDeleted(bool success) { | 53 void OnPersistentNotificationDataDeleted(bool success) { |
55 // TODO(peter): Record UMA for notification deletion requests created by the | 54 content::RecordAction( |
Peter Beverloo
2015/05/21 11:33:10
I was thinking of using a UMA_HISTOGRAM_BOOLEAN()
Deepak
2015/05/21 14:37:02
Done.
| |
56 // PlatformNotificationService. | 55 base::UserMetricsAction("PersistentNotificationDataDeleted")); |
57 } | 56 } |
58 | 57 |
59 // Persistent notifications fired through the delegate do not care about the | 58 // Persistent notifications fired through the delegate do not care about the |
60 // lifetime of the Service Worker responsible for executing the event. | 59 // lifetime of the Service Worker responsible for executing the event. |
61 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { | 60 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { |
62 // TODO(peter): Record UMA statistics about the result status of running | 61 content::RecordAction( |
63 // events for persistent Web Notifications. | 62 base::UserMetricsAction("PersistentWebNotificationComplete")); |
64 } | 63 } |
65 | 64 |
66 void CancelNotification(const std::string& id, ProfileID profile_id) { | 65 void CancelNotification(const std::string& id, ProfileID profile_id) { |
67 PlatformNotificationServiceImpl::GetInstance() | 66 PlatformNotificationServiceImpl::GetInstance() |
68 ->GetNotificationUIManager()->CancelById(id, profile_id); | 67 ->GetNotificationUIManager()->CancelById(id, profile_id); |
69 } | 68 } |
70 | 69 |
71 } // namespace | 70 } // namespace |
72 | 71 |
73 // static | 72 // static |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( | 308 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( |
310 BrowserContext* browser_context, | 309 BrowserContext* browser_context, |
311 std::set<std::string>* displayed_notifications) { | 310 std::set<std::string>* displayed_notifications) { |
312 DCHECK(displayed_notifications); | 311 DCHECK(displayed_notifications); |
313 | 312 |
314 #if !defined(OS_ANDROID) | 313 #if !defined(OS_ANDROID) |
315 Profile* profile = Profile::FromBrowserContext(browser_context); | 314 Profile* profile = Profile::FromBrowserContext(browser_context); |
316 if (!profile || profile->AsTestingProfile()) | 315 if (!profile || profile->AsTestingProfile()) |
317 return false; // Tests will not have a message center. | 316 return false; // Tests will not have a message center. |
318 | 317 |
319 // TODO(peter): Filter for persistent notifications only. | 318 std::set<std::string> persistent_notifications; |
Peter Beverloo
2015/05/21 11:33:10
Please let this TODO be for now, I'm working on a
| |
320 *displayed_notifications = | 319 std::set<std::string> all_notifications = |
321 GetNotificationUIManager()->GetAllIdsByProfile(profile); | 320 GetNotificationUIManager()->GetAllIdsByProfile(profile); |
322 | 321 for (std::set<std::string>::iterator itr_notification = |
322 all_notifications.begin(); | |
323 itr_notification != all_notifications.end(); itr_notification++) { | |
324 int64_t id; | |
325 if (base::StringToInt64(*itr_notification, &id) && | |
326 persistent_notifications_.find(id) != persistent_notifications_.end()) { | |
327 persistent_notifications.insert(*itr_notification); | |
328 } | |
329 } | |
330 *displayed_notifications = persistent_notifications; | |
323 return true; | 331 return true; |
324 #else | 332 #else |
325 // Android cannot reliably return the notifications that are currently being | 333 // Android cannot reliably return the notifications that are currently being |
326 // displayed on the platform, see the comment in NotificationUIManagerAndroid. | 334 // displayed on the platform, see the comment in NotificationUIManagerAndroid. |
327 return false; | 335 return false; |
328 #endif // !defined(OS_ANDROID) | 336 #endif // !defined(OS_ANDROID) |
329 } | 337 } |
330 | 338 |
331 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 339 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
332 Profile* profile, | 340 Profile* profile, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 formatted_origin.push_back(':'); | 415 formatted_origin.push_back(':'); |
408 formatted_origin.append(base::UTF8ToUTF16(origin.port())); | 416 formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
409 } | 417 } |
410 return formatted_origin; | 418 return formatted_origin; |
411 } | 419 } |
412 | 420 |
413 // TODO(dewittj): Once file:// URLs are passed in to the origin | 421 // TODO(dewittj): Once file:// URLs are passed in to the origin |
414 // GURL here, begin returning the path as the display name. | 422 // GURL here, begin returning the path as the display name. |
415 return net::FormatUrl(origin, languages); | 423 return net::FormatUrl(origin, languages); |
416 } | 424 } |
OLD | NEW |