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

Unified Diff: chrome/browser/services/gcm/push_messaging_service_impl.cc

Issue 366323002: Push API: use an enum to indicate status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Tweak mock error message. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/push_messaging_service_impl.cc
diff --git a/chrome/browser/services/gcm/push_messaging_service_impl.cc b/chrome/browser/services/gcm/push_messaging_service_impl.cc
index dbc7f2f1fd8e278c9e8be9a3763c6429f7440e22..1ee383de4a2fb08eb139cdcf240e28b63c3fae51 100644
--- a/chrome/browser/services/gcm/push_messaging_service_impl.cc
+++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc
@@ -142,7 +142,11 @@ void PushMessagingServiceImpl::Register(
if (profile_->GetPrefs()->GetInteger(
prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) {
- DidRegister(app_id, callback, std::string(), GCMClient::UNKNOWN_ERROR);
+ RegisterEnd(
+ app_id,
+ callback,
+ std::string(),
+ content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_LIMIT_REACHED);
return;
}
@@ -177,7 +181,11 @@ void PushMessagingServiceImpl::Register(
gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
if (permission_context == NULL) {
- DidRegister(app_id, callback, std::string(), GCMClient::UNKNOWN_ERROR);
+ RegisterEnd(
+ app_id,
+ callback,
+ std::string(),
+ content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED);
return;
}
@@ -193,15 +201,14 @@ void PushMessagingServiceImpl::Register(
callback));
}
-void PushMessagingServiceImpl::DidRegister(
+void PushMessagingServiceImpl::RegisterEnd(
const std::string& app_id,
const content::PushMessagingService::RegisterCallback& callback,
const std::string& registration_id,
- GCMClient::Result result) {
+ content::PushMessagingStatus status) {
GURL endpoint = GURL("https://android.googleapis.com/gcm/send");
- bool success = (result == GCMClient::SUCCESS);
- callback.Run(endpoint, registration_id, success);
- if (success) {
+ callback.Run(endpoint, registration_id, status);
+ if (status == content::PUSH_MESSAGING_STATUS_OK) {
// TODO(johnme): Make sure the pref doesn't get out of sync after crashes.
int registration_count = profile_->GetPrefs()->GetInteger(
prefs::kPushMessagingRegistrationCount);
@@ -210,15 +217,29 @@ void PushMessagingServiceImpl::DidRegister(
}
}
+void PushMessagingServiceImpl::DidRegister(
+ const std::string& app_id,
+ const content::PushMessagingService::RegisterCallback& callback,
+ const std::string& registration_id,
+ GCMClient::Result result) {
+ content::PushMessagingStatus status =
+ result == GCMClient::SUCCESS
+ ? content::PUSH_MESSAGING_STATUS_OK
+ : content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_SERVICE_ERROR;
+ RegisterEnd(app_id, callback, registration_id, status);
+}
+
void PushMessagingServiceImpl::DidRequestPermission(
const std::string& sender_id,
const std::string& app_id,
const content::PushMessagingService::RegisterCallback& register_callback,
bool allow) {
if (!allow) {
- // TODO(miguelg) extend the error enum to allow for pemission failure.
- DidRegister(app_id, register_callback, std::string(),
- GCMClient::UNKNOWN_ERROR);
+ RegisterEnd(
+ app_id,
+ register_callback,
+ std::string(),
+ content::PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_PERMISSION_DENIED);
return;
}
« no previous file with comments | « chrome/browser/services/gcm/push_messaging_service_impl.h ('k') | content/browser/push_messaging_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698