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

Side by Side Diff: chrome/browser/services/gcm/push_messaging_service_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698