| 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/services/gcm/push_messaging_service_impl.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "chrome/browser/services/gcm/gcm_profile_service.h" | |
| 11 #include "components/gcm_driver/gcm_driver.h" | |
| 12 | |
| 13 namespace gcm { | |
| 14 | |
| 15 PushMessagingServiceImpl::PushMessagingServiceImpl( | |
| 16 GCMProfileService* gcm_profile_service) | |
| 17 : gcm_profile_service_(gcm_profile_service), | |
| 18 weak_factory_(this) {} | |
| 19 | |
| 20 PushMessagingServiceImpl::~PushMessagingServiceImpl() {} | |
| 21 | |
| 22 void PushMessagingServiceImpl::Register( | |
| 23 const std::string& app_id, | |
| 24 const std::string& sender_id, | |
| 25 const content::PushMessagingService::RegisterCallback& callback) { | |
| 26 // The GCMDriver could be NULL if GCMProfileService has been shut down. | |
| 27 if (!gcm_profile_service_->driver()) | |
| 28 return; | |
| 29 std::vector<std::string> sender_ids(1, sender_id); | |
| 30 gcm_profile_service_->driver()->Register( | |
| 31 app_id, | |
| 32 sender_ids, | |
| 33 base::Bind(&PushMessagingServiceImpl::DidRegister, | |
| 34 weak_factory_.GetWeakPtr(), | |
| 35 callback)); | |
| 36 } | |
| 37 | |
| 38 void PushMessagingServiceImpl::DidRegister( | |
| 39 const content::PushMessagingService::RegisterCallback& callback, | |
| 40 const std::string& registration_id, | |
| 41 GCMClient::Result result) { | |
| 42 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | |
| 43 bool error = (result != GCMClient::SUCCESS); | |
| 44 callback.Run(endpoint, registration_id, error); | |
| 45 } | |
| 46 | |
| 47 } // namespace gcm | |
| OLD | NEW |