| 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/push_messaging/push_messaging_service_impl.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 "result in user-visible messages. You can indicate this by calling " | 60 "result in user-visible messages. You can indicate this by calling " |
| 61 "pushManager.subscribe({userVisibleOnly: true}) instead. See " | 61 "pushManager.subscribe({userVisibleOnly: true}) instead. See " |
| 62 "https://goo.gl/yqv4Q4 for more details."; | 62 "https://goo.gl/yqv4Q4 for more details."; |
| 63 | 63 |
| 64 void RecordDeliveryStatus(content::PushDeliveryStatus status) { | 64 void RecordDeliveryStatus(content::PushDeliveryStatus status) { |
| 65 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus", status, | 65 UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus", status, |
| 66 content::PUSH_DELIVERY_STATUS_LAST + 1); | 66 content::PUSH_DELIVERY_STATUS_LAST + 1); |
| 67 } | 67 } |
| 68 | 68 |
| 69 blink::WebPushPermissionStatus ToPushPermission( | 69 blink::WebPushPermissionStatus ToPushPermission( |
| 70 content::PermissionStatus permission_status) { | 70 blink::mojom::PermissionStatus permission_status) { |
| 71 switch (permission_status) { | 71 switch (permission_status) { |
| 72 case content::PermissionStatus::GRANTED: | 72 case blink::mojom::PermissionStatus::GRANTED: |
| 73 return blink::WebPushPermissionStatusGranted; | 73 return blink::WebPushPermissionStatusGranted; |
| 74 case content::PermissionStatus::DENIED: | 74 case blink::mojom::PermissionStatus::DENIED: |
| 75 return blink::WebPushPermissionStatusDenied; | 75 return blink::WebPushPermissionStatusDenied; |
| 76 case content::PermissionStatus::ASK: | 76 case blink::mojom::PermissionStatus::ASK: |
| 77 return blink::WebPushPermissionStatusPrompt; | 77 return blink::WebPushPermissionStatusPrompt; |
| 78 default: | 78 default: |
| 79 NOTREACHED(); | 79 NOTREACHED(); |
| 80 return blink::WebPushPermissionStatusDenied; | 80 return blink::WebPushPermissionStatusDenied; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 void UnregisterCallbackToClosure(const base::Closure& closure, | 84 void UnregisterCallbackToClosure(const base::Closure& closure, |
| 85 content::PushUnregistrationStatus status) { | 85 content::PushUnregistrationStatus status) { |
| 86 closure.Run(); | 86 closure.Run(); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 SubscribeEnd(callback, subscription_id, | 511 SubscribeEnd(callback, subscription_id, |
| 512 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), | 512 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), |
| 513 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), | 513 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), |
| 514 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); | 514 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); |
| 515 } | 515 } |
| 516 | 516 |
| 517 void PushMessagingServiceImpl::DidRequestPermission( | 517 void PushMessagingServiceImpl::DidRequestPermission( |
| 518 const PushMessagingAppIdentifier& app_identifier, | 518 const PushMessagingAppIdentifier& app_identifier, |
| 519 const std::string& sender_id, | 519 const std::string& sender_id, |
| 520 const content::PushMessagingService::RegisterCallback& register_callback, | 520 const content::PushMessagingService::RegisterCallback& register_callback, |
| 521 content::PermissionStatus permission_status) { | 521 blink::mojom::PermissionStatus permission_status) { |
| 522 if (permission_status != content::PermissionStatus::GRANTED) { | 522 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { |
| 523 SubscribeEndWithError(register_callback, | 523 SubscribeEndWithError(register_callback, |
| 524 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 524 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 | 527 |
| 528 IncreasePushSubscriptionCount(1, true /* is_pending */); | 528 IncreasePushSubscriptionCount(1, true /* is_pending */); |
| 529 std::vector<std::string> sender_ids(1, sender_id); | 529 std::vector<std::string> sender_ids(1, sender_id); |
| 530 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids, | 530 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids, |
| 531 base::Bind(&PushMessagingServiceImpl::DidSubscribe, | 531 base::Bind(&PushMessagingServiceImpl::DidSubscribe, |
| 532 weak_factory_.GetWeakPtr(), | 532 weak_factory_.GetWeakPtr(), |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 blink::WebPushPermissionStatusGranted; | 755 blink::WebPushPermissionStatusGranted; |
| 756 } | 756 } |
| 757 | 757 |
| 758 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { | 758 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { |
| 759 gcm::GCMProfileService* gcm_profile_service = | 759 gcm::GCMProfileService* gcm_profile_service = |
| 760 gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 760 gcm::GCMProfileServiceFactory::GetForProfile(profile_); |
| 761 CHECK(gcm_profile_service); | 761 CHECK(gcm_profile_service); |
| 762 CHECK(gcm_profile_service->driver()); | 762 CHECK(gcm_profile_service->driver()); |
| 763 return gcm_profile_service->driver(); | 763 return gcm_profile_service->driver(); |
| 764 } | 764 } |
| OLD | NEW |