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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..145d92e04fbc27d0a6e42095d4dd60cbeaca4395 |
--- /dev/null |
+++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
+ |
+#include "base/bind.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/services/gcm/gcm_profile_service.h" |
+#include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
+ |
+PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) |
+ : profile_(profile) {} |
+ |
+PushMessagingServiceImpl::~PushMessagingServiceImpl() {} |
+ |
+void PushMessagingServiceImpl::Register( |
+ content::PushMessagingService::RegisterCallback callback) { |
+ std::string app_id = "test_app_id"; |
+ std::vector<std::string> sender_ids; |
+ sender_ids.push_back("test_sender_id"); |
+ gcm::GCMProfileServiceFactory::GetForProfile(profile_)->Register( |
+ app_id, |
+ sender_ids, |
+ base::Bind(&PushMessagingServiceImpl::DidRegister, this, callback)); |
+} |
+ |
+void PushMessagingServiceImpl::DidRegister( |
+ content::PushMessagingService::RegisterCallback callback, |
+ const std::string& registration_id, |
+ gcm::GCMClient::Result result) { |
+ callback.Run(registration_id, FromGCMClientResult(result)); |
+} |
+ |
+content::PushMessagingStatus PushMessagingServiceImpl::FromGCMClientResult( |
+ gcm::GCMClient::Result result) { |
+ switch (result) { |
+ case gcm::GCMClient::SUCCESS: |
+ return content::PUSH_MESSAGING_STATUS_OK; |
+ case gcm::GCMClient::INVALID_PARAMETER: |
+ return content::PUSH_MESSAGING_STATUS_INVALID_PARAMETER; |
+ case gcm::GCMClient::NOT_SIGNED_IN: |
+ return content::PUSH_MESSAGING_STATUS_NOT_SIGNED_IN; |
+ case gcm::GCMClient::ASYNC_OPERATION_PENDING: |
+ return content::PUSH_MESSAGING_STATUS_OPERATION_PENDING; |
+ case gcm::GCMClient::NETWORK_ERROR: |
+ return content::PUSH_MESSAGING_STATUS_NETWORK_ERROR; |
+ case gcm::GCMClient::SERVER_ERROR: |
+ return content::PUSH_MESSAGING_STATUS_SERVER_ERROR; |
+ case gcm::GCMClient::TTL_EXCEEDED: |
+ return content::PUSH_MESSAGING_STATUS_TTL_EXCEEDED; |
+ case gcm::GCMClient::UNKNOWN_ERROR: |
+ return content::PUSH_MESSAGING_STATUS_UNKNOWN_ERROR; |
+ }; |
+ NOTREACHED(); |
+ return content::PUSH_MESSAGING_STATUS_UNKNOWN_ERROR; |
+} |