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/services/gcm/push_messaging_service_impl.h" | 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
6 | 6 |
7 #include <bitset> | 7 #include <bitset> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "chrome/browser/ui/browser.h" | 52 #include "chrome/browser/ui/browser.h" |
53 #include "chrome/browser/ui/browser_iterator.h" | 53 #include "chrome/browser/ui/browser_iterator.h" |
54 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 54 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
55 #endif | 55 #endif |
56 | 56 |
57 namespace gcm { | 57 namespace gcm { |
58 | 58 |
59 namespace { | 59 namespace { |
60 const int kMaxRegistrations = 1000000; | 60 const int kMaxRegistrations = 1000000; |
61 | 61 |
| 62 void RecordDeliveryStatus(content::PushDeliveryStatus status) { |
| 63 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus", |
| 64 status, |
| 65 content::PUSH_DELIVERY_STATUS_LAST + 1); |
| 66 } |
| 67 |
62 void RecordUserVisibleStatus(content::PushUserVisibleStatus status) { | 68 void RecordUserVisibleStatus(content::PushUserVisibleStatus status) { |
63 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UserVisibleStatus", | 69 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UserVisibleStatus", |
64 status, | 70 status, |
65 content::PUSH_USER_VISIBLE_STATUS_LAST + 1); | 71 content::PUSH_USER_VISIBLE_STATUS_LAST + 1); |
66 } | 72 } |
67 | 73 |
68 blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { | 74 blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { |
69 switch (setting) { | 75 switch (setting) { |
70 case CONTENT_SETTING_ALLOW: | 76 case CONTENT_SETTING_ALLOW: |
71 return blink::WebPushPermissionStatusGranted; | 77 return blink::WebPushPermissionStatusGranted; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 application_id.app_id_guid(), application_id.origin(), | 242 application_id.app_id_guid(), application_id.origin(), |
237 application_id.service_worker_registration_id(), message)); | 243 application_id.service_worker_registration_id(), message)); |
238 } | 244 } |
239 | 245 |
240 void PushMessagingServiceImpl::DeliverMessageCallback( | 246 void PushMessagingServiceImpl::DeliverMessageCallback( |
241 const std::string& app_id_guid, | 247 const std::string& app_id_guid, |
242 const GURL& requesting_origin, | 248 const GURL& requesting_origin, |
243 int64 service_worker_registration_id, | 249 int64 service_worker_registration_id, |
244 const GCMClient::IncomingMessage& message, | 250 const GCMClient::IncomingMessage& message, |
245 content::PushDeliveryStatus status) { | 251 content::PushDeliveryStatus status) { |
246 // TODO(mvanouwerkerk): UMA logging. | |
247 // TODO(mvanouwerkerk): Show a warning in the developer console of the | 252 // TODO(mvanouwerkerk): Show a warning in the developer console of the |
248 // Service Worker corresponding to app_id (and/or on an internals page). | 253 // Service Worker corresponding to app_id (and/or on an internals page). |
249 // TODO(mvanouwerkerk): Is there a way to recover from failure? | 254 // TODO(mvanouwerkerk): Is there a way to recover from failure? |
250 switch (status) { | 255 switch (status) { |
251 // Call RequireUserVisibleUX if the message was delivered to the Service | 256 // Call RequireUserVisibleUX if the message was delivered to the Service |
252 // Worker JS, even if the website's event handler failed (to prevent sites | 257 // Worker JS, even if the website's event handler failed (to prevent sites |
253 // deliberately failing in order to avoid having to show notifications). | 258 // deliberately failing in order to avoid having to show notifications). |
254 case content::PUSH_DELIVERY_STATUS_SUCCESS: | 259 case content::PUSH_DELIVERY_STATUS_SUCCESS: |
255 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED: | 260 case content::PUSH_DELIVERY_STATUS_EVENT_WAITUNTIL_REJECTED: |
256 RequireUserVisibleUX(requesting_origin, service_worker_registration_id); | 261 RequireUserVisibleUX(requesting_origin, service_worker_registration_id); |
257 break; | 262 break; |
258 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE: | 263 case content::PUSH_DELIVERY_STATUS_INVALID_MESSAGE: |
259 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR: | 264 case content::PUSH_DELIVERY_STATUS_SERVICE_WORKER_ERROR: |
260 break; | 265 break; |
261 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: | 266 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: |
262 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: | 267 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: |
263 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: | 268 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: |
264 Unregister(app_id_guid, message.sender_id, true /* retry_on_failure */, | 269 Unregister(app_id_guid, message.sender_id, true /* retry_on_failure */, |
265 UnregisterCallback()); | 270 UnregisterCallback()); |
266 break; | 271 break; |
267 } | 272 } |
| 273 RecordDeliveryStatus(status); |
268 } | 274 } |
269 | 275 |
270 void PushMessagingServiceImpl::RequireUserVisibleUX( | 276 void PushMessagingServiceImpl::RequireUserVisibleUX( |
271 const GURL& requesting_origin, int64 service_worker_registration_id) { | 277 const GURL& requesting_origin, int64 service_worker_registration_id) { |
272 #if defined(ENABLE_NOTIFICATIONS) | 278 #if defined(ENABLE_NOTIFICATIONS) |
273 // TODO(johnme): Relax this heuristic slightly. | 279 // TODO(johnme): Relax this heuristic slightly. |
274 PlatformNotificationServiceImpl* notification_service = | 280 PlatformNotificationServiceImpl* notification_service = |
275 PlatformNotificationServiceImpl::GetInstance(); | 281 PlatformNotificationServiceImpl::GetInstance(); |
276 // Can't use g_browser_process->notification_ui_manager(), since the test uses | 282 // Can't use g_browser_process->notification_ui_manager(), since the test uses |
277 // PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting. | 283 // PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 callback.Run(registration_id, status); | 584 callback.Run(registration_id, status); |
579 } | 585 } |
580 | 586 |
581 void PushMessagingServiceImpl::DidRegister( | 587 void PushMessagingServiceImpl::DidRegister( |
582 const PushMessagingApplicationId& application_id, | 588 const PushMessagingApplicationId& application_id, |
583 const content::PushMessagingService::RegisterCallback& callback, | 589 const content::PushMessagingService::RegisterCallback& callback, |
584 const std::string& registration_id, | 590 const std::string& registration_id, |
585 GCMClient::Result result) { | 591 GCMClient::Result result) { |
586 content::PushRegistrationStatus status = | 592 content::PushRegistrationStatus status = |
587 content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; | 593 content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; |
588 if (result == GCMClient::SUCCESS) { | 594 switch (result) { |
589 status = content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE; | 595 case GCMClient::SUCCESS: |
590 application_id.PersistToDisk(profile_); | 596 status = content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE; |
591 IncreasePushRegistrationCount(1, false /* is_pending */); | 597 application_id.PersistToDisk(profile_); |
| 598 IncreasePushRegistrationCount(1, false /* is_pending */); |
| 599 break; |
| 600 case GCMClient::INVALID_PARAMETER: |
| 601 case GCMClient::GCM_DISABLED: |
| 602 case GCMClient::ASYNC_OPERATION_PENDING: |
| 603 case GCMClient::SERVER_ERROR: |
| 604 case GCMClient::UNKNOWN_ERROR: |
| 605 status = content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; |
| 606 break; |
| 607 case GCMClient::NETWORK_ERROR: |
| 608 case GCMClient::TTL_EXCEEDED: |
| 609 status = content::PUSH_REGISTRATION_STATUS_NETWORK_ERROR; |
| 610 break; |
592 } | 611 } |
593 RegisterEnd(callback, registration_id, status); | 612 RegisterEnd(callback, registration_id, status); |
594 DecreasePushRegistrationCount(1, true /* was_pending */); | 613 DecreasePushRegistrationCount(1, true /* was_pending */); |
595 } | 614 } |
596 | 615 |
597 void PushMessagingServiceImpl::DidRequestPermission( | 616 void PushMessagingServiceImpl::DidRequestPermission( |
598 const PushMessagingApplicationId& application_id, | 617 const PushMessagingApplicationId& application_id, |
599 const std::string& sender_id, | 618 const std::string& sender_id, |
600 const content::PushMessagingService::RegisterCallback& register_callback, | 619 const content::PushMessagingService::RegisterCallback& register_callback, |
601 bool allow) { | 620 bool allow) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 return; | 710 return; |
692 } | 711 } |
693 | 712 |
694 application_id.DeleteFromDisk(profile_); | 713 application_id.DeleteFromDisk(profile_); |
695 DecreasePushRegistrationCount(1, false /* was_pending */); | 714 DecreasePushRegistrationCount(1, false /* was_pending */); |
696 } | 715 } |
697 | 716 |
698 // Internal calls pass a null callback. | 717 // Internal calls pass a null callback. |
699 if (!callback.is_null()) { | 718 if (!callback.is_null()) { |
700 switch (result) { | 719 switch (result) { |
701 case GCMClient::SUCCESS: | 720 case GCMClient::SUCCESS: |
702 callback.Run(content::PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTER); | 721 callback.Run(content::PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED); |
703 break; | 722 break; |
704 case GCMClient::NETWORK_ERROR: | 723 case GCMClient::INVALID_PARAMETER: |
705 case GCMClient::TTL_EXCEEDED: | 724 case GCMClient::GCM_DISABLED: |
706 case GCMClient::ASYNC_OPERATION_PENDING: | 725 case GCMClient::ASYNC_OPERATION_PENDING: |
707 callback.Run( | 726 case GCMClient::SERVER_ERROR: |
708 retry_on_failure | 727 case GCMClient::UNKNOWN_ERROR: |
709 ? content:: | 728 callback.Run(content::PUSH_UNREGISTRATION_STATUS_SERVICE_ERROR); |
710 PUSH_UNREGISTRATION_STATUS_SUCCESS_WILL_RETRY_NETWORK_ERROR | 729 break; |
711 : content::PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR); | 730 case GCMClient::NETWORK_ERROR: |
712 break; | 731 case GCMClient::TTL_EXCEEDED: |
713 case GCMClient::SERVER_ERROR: | 732 callback.Run( |
714 case GCMClient::INVALID_PARAMETER: | 733 retry_on_failure |
715 case GCMClient::GCM_DISABLED: | 734 ? content:: |
716 case GCMClient::UNKNOWN_ERROR: | 735 PUSH_UNREGISTRATION_STATUS_PENDING_WILL_RETRY_NETWORK_ERROR |
717 callback.Run(content::PUSH_UNREGISTRATION_STATUS_UNKNOWN_ERROR); | 736 : content::PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR); |
718 break; | 737 break; |
719 default: | |
720 NOTREACHED() << "Unexpected GCMClient::Result value."; | |
721 callback.Run(content::PUSH_UNREGISTRATION_STATUS_UNKNOWN_ERROR); | |
722 break; | |
723 } | 738 } |
724 } | 739 } |
725 } | 740 } |
726 | 741 |
727 // OnContentSettingChanged methods --------------------------------------------- | 742 // OnContentSettingChanged methods --------------------------------------------- |
728 | 743 |
729 void PushMessagingServiceImpl::OnContentSettingChanged( | 744 void PushMessagingServiceImpl::OnContentSettingChanged( |
730 const ContentSettingsPattern& primary_pattern, | 745 const ContentSettingsPattern& primary_pattern, |
731 const ContentSettingsPattern& secondary_pattern, | 746 const ContentSettingsPattern& secondary_pattern, |
732 ContentSettingsType content_type, | 747 ContentSettingsType content_type, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 return permission_context->GetPermissionStatus(origin, origin) == | 793 return permission_context->GetPermissionStatus(origin, origin) == |
779 CONTENT_SETTING_ALLOW; | 794 CONTENT_SETTING_ALLOW; |
780 } | 795 } |
781 | 796 |
782 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { | 797 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { |
783 profile_ = profile; | 798 profile_ = profile; |
784 profile_->GetHostContentSettingsMap()->AddObserver(this); | 799 profile_->GetHostContentSettingsMap()->AddObserver(this); |
785 } | 800 } |
786 | 801 |
787 } // namespace gcm | 802 } // namespace gcm |
OLD | NEW |