OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 10 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 11 |
| 12 PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile) |
| 13 : profile_(profile) {} |
| 14 |
| 15 PushMessagingServiceImpl::~PushMessagingServiceImpl() {} |
| 16 |
| 17 void PushMessagingServiceImpl::Register( |
| 18 content::PushMessagingService::RegisterCallback callback) { |
| 19 std::string app_id = "test_app_id"; |
| 20 std::vector<std::string> sender_ids; |
| 21 sender_ids.push_back("test_sender_id"); |
| 22 gcm::GCMProfileServiceFactory::GetForProfile(profile_)->Register( |
| 23 app_id, |
| 24 sender_ids, |
| 25 base::Bind(&PushMessagingServiceImpl::DidRegister, this, callback)); |
| 26 } |
| 27 |
| 28 void PushMessagingServiceImpl::DidRegister( |
| 29 content::PushMessagingService::RegisterCallback callback, |
| 30 const std::string& registration_id, |
| 31 gcm::GCMClient::Result result) { |
| 32 callback.Run(registration_id, FromGCMClientResult(result)); |
| 33 } |
| 34 |
| 35 content::PushMessagingStatus PushMessagingServiceImpl::FromGCMClientResult( |
| 36 gcm::GCMClient::Result result) { |
| 37 switch (result) { |
| 38 case gcm::GCMClient::SUCCESS: |
| 39 return content::PUSH_MESSAGING_STATUS_OK; |
| 40 case gcm::GCMClient::INVALID_PARAMETER: |
| 41 return content::PUSH_MESSAGING_STATUS_INVALID_PARAMETER; |
| 42 case gcm::GCMClient::NOT_SIGNED_IN: |
| 43 return content::PUSH_MESSAGING_STATUS_NOT_SIGNED_IN; |
| 44 case gcm::GCMClient::ASYNC_OPERATION_PENDING: |
| 45 return content::PUSH_MESSAGING_STATUS_OPERATION_PENDING; |
| 46 case gcm::GCMClient::NETWORK_ERROR: |
| 47 return content::PUSH_MESSAGING_STATUS_NETWORK_ERROR; |
| 48 case gcm::GCMClient::SERVER_ERROR: |
| 49 return content::PUSH_MESSAGING_STATUS_SERVER_ERROR; |
| 50 case gcm::GCMClient::TTL_EXCEEDED: |
| 51 return content::PUSH_MESSAGING_STATUS_TTL_EXCEEDED; |
| 52 case gcm::GCMClient::UNKNOWN_ERROR: |
| 53 return content::PUSH_MESSAGING_STATUS_UNKNOWN_ERROR; |
| 54 }; |
| 55 NOTREACHED(); |
| 56 return content::PUSH_MESSAGING_STATUS_UNKNOWN_ERROR; |
| 57 } |
OLD | NEW |