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

Side by Side Diff: content/browser/push_messaging/push_messaging_manager.cc

Issue 2715903002: Re-design Unsubscribe and getPermissionStatus mojo interfaces. (Closed)
Patch Set: change ErrorType::Unknown to ErrorType::None Created 3 years, 9 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 "content/browser/push_messaging/push_messaging_manager.h" 5 #include "content/browser/push_messaging/push_messaging_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 636
637 void PushMessagingManager::DidUnregister( 637 void PushMessagingManager::DidUnregister(
638 const UnsubscribeCallback& callback, 638 const UnsubscribeCallback& callback,
639 PushUnregistrationStatus unregistration_status) { 639 PushUnregistrationStatus unregistration_status) {
640 // Only called from IO thread, but would be safe to call from UI thread. 640 // Only called from IO thread, but would be safe to call from UI thread.
641 DCHECK_CURRENTLY_ON(BrowserThread::IO); 641 DCHECK_CURRENTLY_ON(BrowserThread::IO);
642 switch (unregistration_status) { 642 switch (unregistration_status) {
643 case PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED: 643 case PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED:
644 case PUSH_UNREGISTRATION_STATUS_PENDING_NETWORK_ERROR: 644 case PUSH_UNREGISTRATION_STATUS_PENDING_NETWORK_ERROR:
645 case PUSH_UNREGISTRATION_STATUS_PENDING_SERVICE_ERROR: 645 case PUSH_UNREGISTRATION_STATUS_PENDING_SERVICE_ERROR:
646 callback.Run(true /* success */, true /* did_unsubscribe */, 646 callback.Run(blink::WebPushError::ErrorTypeNone /* success */,
Peter Beverloo 2017/02/27 09:32:50 nit: you could drop the /* success */ now since th
ke.he 2017/02/28 05:00:50 Done.
647 blink::WebPushError::ErrorTypeUnknown, 647 true /* did_unsubscribe */,
648 base::nullopt /* error_message */); 648 base::nullopt /* error_message */);
649 break; 649 break;
650 case PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED: 650 case PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED:
651 callback.Run(true /* success */, false /* did_unsubscribe */, 651 callback.Run(blink::WebPushError::ErrorTypeNone /* success */,
652 blink::WebPushError::ErrorTypeUnknown, 652 false /* did_unsubscribe */,
653 base::nullopt /* error_message */); 653 base::nullopt /* error_message */);
654 break; 654 break;
655 case PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER: 655 case PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER:
656 case PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE: 656 case PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE:
657 case PUSH_UNREGISTRATION_STATUS_STORAGE_ERROR: 657 case PUSH_UNREGISTRATION_STATUS_STORAGE_ERROR:
658 callback.Run( 658 callback.Run(blink::WebPushError::ErrorTypeAbort /* error */, false,
Peter Beverloo 2017/02/27 09:32:50 dito w/ /* error */, although the "false" after c
ke.he 2017/02/28 05:00:50 Done.
659 false /* error */, false, blink::WebPushError::ErrorTypeAbort, 659 std::string(PushUnregistrationStatusToString(
660 std::string(PushUnregistrationStatusToString(unregistration_status))); 660 unregistration_status)) /* error_message */);
661 break; 661 break;
662 case PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR: 662 case PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR:
663 NOTREACHED(); 663 NOTREACHED();
664 break; 664 break;
665 } 665 }
666 RecordUnregistrationStatus(unregistration_status); 666 RecordUnregistrationStatus(unregistration_status);
667 } 667 }
668 668
669 // GetSubscription methods on both IO and UI threads, merged in order of use 669 // GetSubscription methods on both IO and UI threads, merged in order of use
670 // from PushMessagingManager and Core. 670 // from PushMessagingManager and Core.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 804
805 void PushMessagingManager::GetPermissionStatus( 805 void PushMessagingManager::GetPermissionStatus(
806 int64_t service_worker_registration_id, 806 int64_t service_worker_registration_id,
807 bool user_visible, 807 bool user_visible,
808 const GetPermissionStatusCallback& callback) { 808 const GetPermissionStatusCallback& callback) {
809 DCHECK_CURRENTLY_ON(BrowserThread::IO); 809 DCHECK_CURRENTLY_ON(BrowserThread::IO);
810 ServiceWorkerRegistration* service_worker_registration = 810 ServiceWorkerRegistration* service_worker_registration =
811 service_worker_context_->GetLiveRegistration( 811 service_worker_context_->GetLiveRegistration(
812 service_worker_registration_id); 812 service_worker_registration_id);
813 if (!service_worker_registration) { 813 if (!service_worker_registration) {
814 callback.Run(false /* error */, blink::WebPushPermissionStatusDenied, 814 // Return error: ErrorTypeAbort.
815 blink::WebPushError::ErrorTypeAbort); 815 callback.Run(blink::WebPushError::ErrorTypeAbort,
816 blink::WebPushPermissionStatusDenied);
816 return; 817 return;
817 } 818 }
818 819
819 BrowserThread::PostTask( 820 BrowserThread::PostTask(
820 BrowserThread::UI, FROM_HERE, 821 BrowserThread::UI, FROM_HERE,
821 base::Bind(&Core::GetPermissionStatusOnUI, 822 base::Bind(&Core::GetPermissionStatusOnUI,
822 base::Unretained(ui_core_.get()), callback, 823 base::Unretained(ui_core_.get()), callback,
823 service_worker_registration->pattern().GetOrigin(), 824 service_worker_registration->pattern().GetOrigin(),
824 user_visible)); 825 user_visible));
825 } 826 }
826 827
827 void PushMessagingManager::Core::GetPermissionStatusOnUI( 828 void PushMessagingManager::Core::GetPermissionStatusOnUI(
828 const GetPermissionStatusCallback& callback, 829 const GetPermissionStatusCallback& callback,
829 const GURL& requesting_origin, 830 const GURL& requesting_origin,
830 bool user_visible) { 831 bool user_visible) {
831 DCHECK_CURRENTLY_ON(BrowserThread::UI); 832 DCHECK_CURRENTLY_ON(BrowserThread::UI);
832 blink::WebPushPermissionStatus permission_status; 833 blink::WebPushPermissionStatus permission_status;
833 PushMessagingService* push_service = service(); 834 PushMessagingService* push_service = service();
834 if (push_service) { 835 if (push_service) {
835 if (!user_visible && !push_service->SupportNonVisibleMessages()) { 836 if (!user_visible && !push_service->SupportNonVisibleMessages()) {
836 BrowserThread::PostTask( 837 BrowserThread::PostTask(
837 BrowserThread::IO, FROM_HERE, 838 BrowserThread::IO, FROM_HERE,
838 base::Bind(callback, false /* error */, 839 // Return error: ErrorTypeNotSupported.
839 blink::WebPushPermissionStatusDenied, 840 base::Bind(callback, blink::WebPushError::ErrorTypeNotSupported,
840 blink::WebPushError::ErrorTypeNotSupported)); 841 blink::WebPushPermissionStatusDenied));
841 return; 842 return;
842 } 843 }
843 permission_status = 844 permission_status =
844 push_service->GetPermissionStatus(requesting_origin, user_visible); 845 push_service->GetPermissionStatus(requesting_origin, user_visible);
845 } else if (is_incognito()) { 846 } else if (is_incognito()) {
846 // Return prompt, so the website can't detect incognito mode. 847 // Return prompt, so the website can't detect incognito mode.
847 permission_status = blink::WebPushPermissionStatusPrompt; 848 permission_status = blink::WebPushPermissionStatusPrompt;
848 } else { 849 } else {
849 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 850 BrowserThread::PostTask(
850 base::Bind(callback, false /* error */, 851 BrowserThread::IO, FROM_HERE,
851 blink::WebPushPermissionStatusDenied, 852 // Return error: ErrorTypeAbort.
852 blink::WebPushError::ErrorTypeAbort)); 853 base::Bind(callback, blink::WebPushError::ErrorTypeAbort,
854 blink::WebPushPermissionStatusDenied));
853 return; 855 return;
854 } 856 }
855 BrowserThread::PostTask( 857 BrowserThread::PostTask(
856 BrowserThread::IO, FROM_HERE, 858 BrowserThread::IO, FROM_HERE,
857 base::Bind(callback, true /* success */, permission_status, 859 // Return success: |permission_status|.
858 blink::WebPushError::ErrorTypeUnknown)); 860 base::Bind(callback, blink::WebPushError::ErrorTypeNone,
861 permission_status));
859 } 862 }
860 863
861 // Helper methods on both IO and UI threads, merged from 864 // Helper methods on both IO and UI threads, merged from
862 // PushMessagingManager and Core. 865 // PushMessagingManager and Core.
863 // ----------------------------------------------------------------------------- 866 // -----------------------------------------------------------------------------
864 867
865 void PushMessagingManager::Core::GetEncryptionInfoOnUI( 868 void PushMessagingManager::Core::GetEncryptionInfoOnUI(
866 const GURL& origin, 869 const GURL& origin,
867 int64_t service_worker_registration_id, 870 int64_t service_worker_registration_id,
868 const std::string& sender_id, 871 const std::string& sender_id,
(...skipping 25 matching lines...) Expand all
894 PushMessagingService* PushMessagingManager::Core::service() { 897 PushMessagingService* PushMessagingManager::Core::service() {
895 DCHECK_CURRENTLY_ON(BrowserThread::UI); 898 DCHECK_CURRENTLY_ON(BrowserThread::UI);
896 RenderProcessHost* process_host = 899 RenderProcessHost* process_host =
897 RenderProcessHost::FromID(render_process_id_); 900 RenderProcessHost::FromID(render_process_id_);
898 return process_host 901 return process_host
899 ? process_host->GetBrowserContext()->GetPushMessagingService() 902 ? process_host->GetBrowserContext()->GetPushMessagingService()
900 : nullptr; 903 : nullptr;
901 } 904 }
902 905
903 } // namespace content 906 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698