Chromium Code Reviews| Index: chrome/browser/push_messaging/push_messaging_service_impl.cc | 
| diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc | 
| index 11907fe0aef82fdc604ad56ccffb5078648836e8..88f639f885c7b67401c380060d48781ef76a6988 100644 | 
| --- a/chrome/browser/push_messaging/push_messaging_service_impl.cc | 
| +++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc | 
| @@ -62,7 +62,7 @@ | 
| using content::BrowserThread; | 
| namespace { | 
| -const int kMaxRegistrations = 1000000; | 
| +const int kMaxSubscriptions = 1000000; | 
| void RecordDeliveryStatus(content::PushDeliveryStatus status) { | 
| UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus", | 
| @@ -90,8 +90,8 @@ blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { | 
| } | 
| } | 
| -void UnregisterCallbackToClosure( | 
| - const base::Closure& closure, content::PushUnregistrationStatus status) { | 
| +void UnsubscribeCallbackToClosure( | 
| + const base::Closure& closure, content::PushUnsubscriptionStatus status) { | 
| closure.Run(); | 
| } | 
| @@ -122,13 +122,13 @@ void PushMessagingServiceImpl::InitializeForProfile(Profile* profile) { | 
| PushMessagingServiceImpl* push_service = | 
| PushMessagingServiceFactory::GetForProfile(profile); | 
| - push_service->IncreasePushRegistrationCount(count, false /* is_pending */); | 
| + push_service->IncreasePushSubscriptionCount(count, false /* is_pending */); | 
| } | 
| PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) | 
| : profile_(profile), | 
| - push_registration_count_(0), | 
| - pending_push_registration_count_(0), | 
| + push_subscription_count_(0), | 
| + pending_push_subscription_count_(0), | 
| weak_factory_(this) { | 
| DCHECK(profile); | 
| profile_->GetHostContentSettingsMap()->AddObserver(this); | 
| @@ -138,34 +138,34 @@ PushMessagingServiceImpl::~PushMessagingServiceImpl() { | 
| profile_->GetHostContentSettingsMap()->RemoveObserver(this); | 
| } | 
| -void PushMessagingServiceImpl::IncreasePushRegistrationCount(int add, | 
| +void PushMessagingServiceImpl::IncreasePushSubscriptionCount(int add, | 
| bool is_pending) { | 
| DCHECK(add > 0); | 
| - if (push_registration_count_ + pending_push_registration_count_ == 0) { | 
| + if (push_subscription_count_ + pending_push_subscription_count_ == 0) { | 
| GetGCMDriver()->AddAppHandler(kPushMessagingApplicationIdPrefix, this); | 
| } | 
| if (is_pending) { | 
| - pending_push_registration_count_ += add; | 
| + pending_push_subscription_count_ += add; | 
| } else { | 
| - push_registration_count_ += add; | 
| + push_subscription_count_ += add; | 
| profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 
| - push_registration_count_); | 
| + push_subscription_count_); | 
| } | 
| } | 
| -void PushMessagingServiceImpl::DecreasePushRegistrationCount(int subtract, | 
| +void PushMessagingServiceImpl::DecreasePushSubscriptionCount(int subtract, | 
| bool was_pending) { | 
| DCHECK(subtract > 0); | 
| if (was_pending) { | 
| - pending_push_registration_count_ -= subtract; | 
| - DCHECK(pending_push_registration_count_ >= 0); | 
| + pending_push_subscription_count_ -= subtract; | 
| + DCHECK(pending_push_subscription_count_ >= 0); | 
| } else { | 
| - push_registration_count_ -= subtract; | 
| - DCHECK(push_registration_count_ >= 0); | 
| + push_subscription_count_ -= subtract; | 
| + DCHECK(push_subscription_count_ >= 0); | 
| profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 
| - push_registration_count_); | 
| + push_subscription_count_); | 
| } | 
| - if (push_registration_count_ + pending_push_registration_count_ == 0) { | 
| + if (push_subscription_count_ + pending_push_subscription_count_ == 0) { | 
| GetGCMDriver()->RemoveAppHandler(kPushMessagingApplicationIdPrefix); | 
| } | 
| } | 
| @@ -190,14 +190,14 @@ void PushMessagingServiceImpl::OnMessage( | 
| : message_callback_for_testing_; | 
| PushMessagingApplicationId application_id = | 
| PushMessagingApplicationId::Get(profile_, app_id); | 
| - // Drop message and unregister if app id was unknown (maybe recently deleted). | 
| + // Drop message and unsibscribe if app id was unknown (recently deleted?). | 
| 
 
johnme
2015/05/07 13:31:25
Typo
 
 | 
| if (!application_id.IsValid()) { | 
| DeliverMessageCallback(app_id, GURL::EmptyGURL(), -1, message, | 
| message_handled_closure, | 
| content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID); | 
| return; | 
| } | 
| - // Drop message and unregister if |origin| has lost push permission. | 
| + // Drop message and unsubscribe if |origin| has lost push permission. | 
| if (!HasPermission(application_id.origin())) { | 
| DeliverMessageCallback(app_id, application_id.origin(), | 
| application_id.service_worker_registration_id(), | 
| @@ -273,9 +273,9 @@ void PushMessagingServiceImpl::DeliverMessageCallback( | 
| case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: | 
| case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: | 
| case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: | 
| - Unregister(app_id_guid, message.sender_id, | 
| - base::Bind(&UnregisterCallbackToClosure, | 
| - message_handled_closure)); | 
| + Unsubscribe(app_id_guid, message.sender_id, | 
| + base::Bind(&UnsubscribeCallbackToClosure, | 
| + message_handled_closure)); | 
| break; | 
| } | 
| RecordDeliveryStatus(status); | 
| @@ -560,26 +560,26 @@ GURL PushMessagingServiceImpl::GetPushEndpoint() { | 
| return GURL(std::string(kPushMessagingEndpoint)); | 
| } | 
| -// Register and GetPermissionStatus methods ------------------------------------ | 
| +// Subscribe and GetPermissionStatus methods ----------------------------------- | 
| -void PushMessagingServiceImpl::RegisterFromDocument( | 
| +void PushMessagingServiceImpl::SubscribeFromDocument( | 
| const GURL& requesting_origin, | 
| int64 service_worker_registration_id, | 
| const std::string& sender_id, | 
| int renderer_id, | 
| int render_frame_id, | 
| bool user_visible, | 
| - const content::PushMessagingService::RegisterCallback& callback) { | 
| + const content::PushMessagingService::SubscribeCallback& callback) { | 
| PushMessagingApplicationId application_id = | 
| PushMessagingApplicationId::Generate(requesting_origin, | 
| service_worker_registration_id); | 
| DCHECK(application_id.IsValid()); | 
| - if (push_registration_count_ + pending_push_registration_count_ | 
| - >= kMaxRegistrations) { | 
| - RegisterEnd(callback, | 
| - std::string(), | 
| - content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); | 
| + if (push_subscription_count_ + pending_push_subscription_count_ | 
| + >= kMaxSubscriptions) { | 
| + SubscribeEnd(callback, | 
| + std::string(), | 
| + content::PUSH_SUBSCRIPTION_STATUS_LIMIT_REACHED); | 
| return; | 
| } | 
| @@ -604,9 +604,9 @@ void PushMessagingServiceImpl::RegisterFromDocument( | 
| PushMessagingPermissionContextFactory::GetForProfile(profile_); | 
| if (permission_context == NULL || !user_visible) { | 
| - RegisterEnd(callback, | 
| - std::string(), | 
| - content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 
| + SubscribeEnd(callback, | 
| + std::string(), | 
| + content::PUSH_SUBSCRIPTION_STATUS_PERMISSION_DENIED); | 
| return; | 
| } | 
| @@ -622,26 +622,26 @@ void PushMessagingServiceImpl::RegisterFromDocument( | 
| callback)); | 
| } | 
| -void PushMessagingServiceImpl::RegisterFromWorker( | 
| +void PushMessagingServiceImpl::SubscribeFromWorker( | 
| const GURL& requesting_origin, | 
| int64 service_worker_registration_id, | 
| const std::string& sender_id, | 
| bool user_visible, | 
| - const content::PushMessagingService::RegisterCallback& register_callback) { | 
| + const content::PushMessagingService::SubscribeCallback& callback) { | 
| PushMessagingApplicationId application_id = | 
| PushMessagingApplicationId::Generate(requesting_origin, | 
| service_worker_registration_id); | 
| DCHECK(application_id.IsValid()); | 
| if (profile_->GetPrefs()->GetInteger( | 
| - prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { | 
| - RegisterEnd(register_callback, std::string(), | 
| - content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); | 
| + prefs::kPushMessagingRegistrationCount) >= kMaxSubscriptions) { | 
| + SubscribeEnd(callback, std::string(), | 
| + content::PUSH_SUBSCRIPTION_STATUS_LIMIT_REACHED); | 
| return; | 
| } | 
| // TODO(peter): Consider |user_visible| when getting the permission status | 
| - // for registering from a worker. | 
| + // for subscribing from a worker. | 
| GURL embedding_origin = requesting_origin; | 
| blink::WebPushPermissionStatus permission_status = | 
| @@ -649,18 +649,18 @@ void PushMessagingServiceImpl::RegisterFromWorker( | 
| embedding_origin, | 
| user_visible); | 
| if (permission_status != blink::WebPushPermissionStatusGranted) { | 
| - RegisterEnd(register_callback, std::string(), | 
| - content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 
| + SubscribeEnd(callback, std::string(), | 
| + content::PUSH_SUBSCRIPTION_STATUS_PERMISSION_DENIED); | 
| return; | 
| } | 
| - IncreasePushRegistrationCount(1, true /* is_pending */); | 
| + IncreasePushSubscriptionCount(1, true /* is_pending */); | 
| std::vector<std::string> sender_ids(1, sender_id); | 
| GetGCMDriver()->Register( | 
| application_id.app_id_guid(), sender_ids, | 
| - base::Bind(&PushMessagingServiceImpl::DidRegister, | 
| + base::Bind(&PushMessagingServiceImpl::DidSubscribe, | 
| weak_factory_.GetWeakPtr(), | 
| - application_id, register_callback)); | 
| + application_id, callback)); | 
| } | 
| blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( | 
| @@ -675,145 +675,144 @@ blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( | 
| requesting_origin, embedding_origin)); | 
| } | 
| -void PushMessagingServiceImpl::RegisterEnd( | 
| - const content::PushMessagingService::RegisterCallback& callback, | 
| - const std::string& registration_id, | 
| - content::PushRegistrationStatus status) { | 
| - callback.Run(registration_id, status); | 
| +void PushMessagingServiceImpl::SubscribeEnd( | 
| + const content::PushMessagingService::SubscribeCallback& callback, | 
| + const std::string& subscription_id, | 
| + content::PushSubscriptionStatus status) { | 
| + callback.Run(subscription_id, status); | 
| } | 
| -void PushMessagingServiceImpl::DidRegister( | 
| +void PushMessagingServiceImpl::DidSubscribe( | 
| const PushMessagingApplicationId& application_id, | 
| - const content::PushMessagingService::RegisterCallback& callback, | 
| - const std::string& registration_id, | 
| + const content::PushMessagingService::SubscribeCallback& callback, | 
| + const std::string& subscription_id, | 
| gcm::GCMClient::Result result) { | 
| - content::PushRegistrationStatus status = | 
| - content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; | 
| + content::PushSubscriptionStatus status = | 
| + content::PUSH_SUBSCRIPTION_STATUS_SERVICE_ERROR; | 
| switch (result) { | 
| case gcm::GCMClient::SUCCESS: | 
| - status = content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE; | 
| + status = content::PUSH_SUBSCRIPTION_STATUS_SUCCESS_FROM_PUSH_SERVICE; | 
| application_id.PersistToDisk(profile_); | 
| - IncreasePushRegistrationCount(1, false /* is_pending */); | 
| + IncreasePushSubscriptionCount(1, false /* is_pending */); | 
| break; | 
| case gcm::GCMClient::INVALID_PARAMETER: | 
| case gcm::GCMClient::GCM_DISABLED: | 
| case gcm::GCMClient::ASYNC_OPERATION_PENDING: | 
| case gcm::GCMClient::SERVER_ERROR: | 
| case gcm::GCMClient::UNKNOWN_ERROR: | 
| - status = content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; | 
| + status = content::PUSH_SUBSCRIPTION_STATUS_SERVICE_ERROR; | 
| break; | 
| case gcm::GCMClient::NETWORK_ERROR: | 
| case gcm::GCMClient::TTL_EXCEEDED: | 
| - status = content::PUSH_REGISTRATION_STATUS_NETWORK_ERROR; | 
| + status = content::PUSH_SUBSCRIPTION_STATUS_NETWORK_ERROR; | 
| break; | 
| } | 
| - RegisterEnd(callback, registration_id, status); | 
| - DecreasePushRegistrationCount(1, true /* was_pending */); | 
| + SubscribeEnd(callback, subscription_id, status); | 
| + DecreasePushSubscriptionCount(1, true /* was_pending */); | 
| } | 
| void PushMessagingServiceImpl::DidRequestPermission( | 
| const PushMessagingApplicationId& application_id, | 
| const std::string& sender_id, | 
| - const content::PushMessagingService::RegisterCallback& register_callback, | 
| + const content::PushMessagingService::SubscribeCallback& callback, | 
| ContentSetting content_setting) { | 
| if (content_setting != CONTENT_SETTING_ALLOW) { | 
| - RegisterEnd(register_callback, | 
| - std::string(), | 
| - content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 
| + SubscribeEnd(callback, std::string(), | 
| + content::PUSH_SUBSCRIPTION_STATUS_PERMISSION_DENIED); | 
| return; | 
| } | 
| - IncreasePushRegistrationCount(1, true /* is_pending */); | 
| + IncreasePushSubscriptionCount(1, true /* is_pending */); | 
| std::vector<std::string> sender_ids(1, sender_id); | 
| GetGCMDriver()->Register( | 
| application_id.app_id_guid(), | 
| sender_ids, | 
| - base::Bind(&PushMessagingServiceImpl::DidRegister, | 
| + base::Bind(&PushMessagingServiceImpl::DidSubscribe, | 
| weak_factory_.GetWeakPtr(), | 
| - application_id, register_callback)); | 
| + application_id, callback)); | 
| } | 
| -// Unregister methods ---------------------------------------------------------- | 
| +// Unsubscribe methods --------------------------------------------------------- | 
| -void PushMessagingServiceImpl::Unregister( | 
| +void PushMessagingServiceImpl::Unsubscribe( | 
| const GURL& requesting_origin, | 
| int64 service_worker_registration_id, | 
| const std::string& sender_id, | 
| - const content::PushMessagingService::UnregisterCallback& callback) { | 
| + const content::PushMessagingService::UnsubscribeCallback& callback) { | 
| PushMessagingApplicationId application_id = PushMessagingApplicationId::Get( | 
| profile_, requesting_origin, service_worker_registration_id); | 
| if (!application_id.IsValid()) { | 
| if (!callback.is_null()) { | 
| callback.Run( | 
| - content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); | 
| + content::PUSH_UNSUBSCRIPTION_STATUS_SUCCESS_WAS_NOT_SUBSCRIBED); | 
| } | 
| return; | 
| } | 
| - Unregister(application_id.app_id_guid(), sender_id, callback); | 
| + Unsubscribe(application_id.app_id_guid(), sender_id, callback); | 
| } | 
| -void PushMessagingServiceImpl::Unregister( | 
| +void PushMessagingServiceImpl::Unsubscribe( | 
| const std::string& app_id_guid, | 
| const std::string& sender_id, | 
| - const content::PushMessagingService::UnregisterCallback& callback) { | 
| + const content::PushMessagingService::UnsubscribeCallback& callback) { | 
| // Delete the mapping for this app id, to guarantee that no messages get | 
| - // delivered in future (even if unregistration fails). | 
| + // delivered in future (even if unsubscription fails). | 
| // TODO(johnme): Instead of deleting these app ids, store them elsewhere, and | 
| - // retry unregistration if it fails due to network errors (crbug.com/465399). | 
| + // retry unsubscription if it fails due to network errors (crbug.com/465399). | 
| PushMessagingApplicationId application_id = | 
| PushMessagingApplicationId::Get(profile_, app_id_guid); | 
| - bool was_registered = application_id.IsValid(); | 
| - if (was_registered) | 
| + bool was_subscribed = application_id.IsValid(); | 
| + if (was_subscribed) | 
| application_id.DeleteFromDisk(profile_); | 
| - const auto& unregister_callback = | 
| - base::Bind(&PushMessagingServiceImpl::DidUnregister, | 
| + const auto& unsubscribe_callback = | 
| + base::Bind(&PushMessagingServiceImpl::DidUnsubscribe, | 
| weak_factory_.GetWeakPtr(), | 
| - was_registered, callback); | 
| + was_subscribed, callback); | 
| #if defined(OS_ANDROID) | 
| // On Android the backend is different, and requires the original sender_id. | 
| - // UnregisterBecausePermissionRevoked sometimes calls us with an empty one. | 
| + // UnsubscribeBecausePermissionRevoked sometimes calls us with an empty one. | 
| if (sender_id.empty()) | 
| - unregister_callback.Run(gcm::GCMClient::INVALID_PARAMETER); | 
| + unsubscribe_callback.Run(gcm::GCMClient::INVALID_PARAMETER); | 
| else | 
| GetGCMDriver()->UnregisterWithSenderId(app_id_guid, sender_id, | 
| - unregister_callback); | 
| + unsubscribe_callback); | 
| #else | 
| - GetGCMDriver()->Unregister(app_id_guid, unregister_callback); | 
| + GetGCMDriver()->Unregister(app_id_guid, unsubscribe_callback); | 
| #endif | 
| } | 
| -void PushMessagingServiceImpl::DidUnregister( | 
| - bool was_registered, | 
| - const content::PushMessagingService::UnregisterCallback& callback, | 
| +void PushMessagingServiceImpl::DidUnsubscribe( | 
| + bool was_subscribed, | 
| + const content::PushMessagingService::UnsubscribeCallback& callback, | 
| gcm::GCMClient::Result result) { | 
| - if (was_registered) | 
| - DecreasePushRegistrationCount(1, false /* was_pending */); | 
| + if (was_subscribed) | 
| + DecreasePushSubscriptionCount(1, false /* was_pending */); | 
| // Internal calls pass a null callback. | 
| if (callback.is_null()) | 
| return; | 
| - if (!was_registered) { | 
| + if (!was_subscribed) { | 
| callback.Run( | 
| - content::PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED); | 
| + content::PUSH_UNSUBSCRIPTION_STATUS_SUCCESS_WAS_NOT_SUBSCRIBED); | 
| return; | 
| } | 
| switch (result) { | 
| case gcm::GCMClient::SUCCESS: | 
| - callback.Run(content::PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED); | 
| + callback.Run(content::PUSH_UNSUBSCRIPTION_STATUS_SUCCESS_UNSUBSCRIBED); | 
| break; | 
| case gcm::GCMClient::INVALID_PARAMETER: | 
| case gcm::GCMClient::GCM_DISABLED: | 
| case gcm::GCMClient::SERVER_ERROR: | 
| case gcm::GCMClient::UNKNOWN_ERROR: | 
| - callback.Run(content::PUSH_UNREGISTRATION_STATUS_PENDING_SERVICE_ERROR); | 
| + callback.Run(content::PUSH_UNSUBSCRIPTION_STATUS_PENDING_SERVICE_ERROR); | 
| break; | 
| case gcm::GCMClient::ASYNC_OPERATION_PENDING: | 
| case gcm::GCMClient::NETWORK_ERROR: | 
| case gcm::GCMClient::TTL_EXCEEDED: | 
| - callback.Run(content::PUSH_UNREGISTRATION_STATUS_PENDING_NETWORK_ERROR); | 
| + callback.Run(content::PUSH_UNSUBSCRIPTION_STATUS_PENDING_NETWORK_ERROR); | 
| break; | 
| } | 
| } | 
| @@ -858,28 +857,28 @@ void PushMessagingServiceImpl::OnContentSettingChanged( | 
| GetSenderId( | 
| profile_, id.origin(), id.service_worker_registration_id(), | 
| base::Bind( | 
| - &PushMessagingServiceImpl::UnregisterBecausePermissionRevoked, | 
| + &PushMessagingServiceImpl::UnsubscribeBecausePermissionRevoked, | 
| weak_factory_.GetWeakPtr(), id, barrier_closure)); | 
| } | 
| } | 
| -void PushMessagingServiceImpl::UnregisterBecausePermissionRevoked( | 
| +void PushMessagingServiceImpl::UnsubscribeBecausePermissionRevoked( | 
| const PushMessagingApplicationId& id, const base::Closure& closure, | 
| const std::string& sender_id, bool success, bool not_found) { | 
| base::Closure barrier_closure = base::BarrierClosure(2, closure); | 
| - // Unregister the PushMessagingApplicationId with the push service. | 
| + // Unsubscribe the PushMessagingApplicationId with the push service. | 
| // It's possible for GetSenderId to have failed and sender_id to be empty, if | 
| // cookies (and the SW database) for an origin got cleared before permissions | 
| - // are cleared for the origin. In that case Unregister will just delete the | 
| + // are cleared for the origin. In that case Unubscribe will just delete the | 
| // application ID to block future messages. | 
| - // TODO(johnme): Auto-unregister before SW DB is cleared | 
| + // TODO(johnme): Auto-unsubscribe before SW DB is cleared | 
| // (https://crbug.com/402458). | 
| - Unregister(id.app_id_guid(), sender_id, | 
| - base::Bind(&UnregisterCallbackToClosure, barrier_closure)); | 
| + Unsubscribe(id.app_id_guid(), sender_id, | 
| + base::Bind(&UnsubscribeCallbackToClosure, barrier_closure)); | 
| - // Clear the associated service worker push registration id. | 
| - ClearPushRegistrationID(profile_, id.origin(), | 
| + // Clear the associated service worker push subscription id. | 
| + ClearPushSubscriptionID(profile_, id.origin(), | 
| id.service_worker_registration_id(), barrier_closure); | 
| } |