Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab562d2066e07cdb23124921c6c4f223228eb00e |
| --- /dev/null |
| +++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc |
| @@ -0,0 +1,45 @@ |
| +// 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/services/gcm/push_messaging_service_impl.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "chrome/browser/services/gcm/gcm_profile_service.h" |
| +#include "components/gcm_driver/gcm_driver.h" |
| + |
| +namespace gcm { |
| + |
| +PushMessagingServiceImpl::PushMessagingServiceImpl( |
| + GCMProfileService* gcm_profile_service) |
| + : gcm_profile_service_(gcm_profile_service) {} |
| + |
| +PushMessagingServiceImpl::~PushMessagingServiceImpl() {} |
| + |
| +void PushMessagingServiceImpl::Register( |
| + const std::string& app_id, |
| + const std::string& sender_id, |
| + const content::PushMessagingService::RegisterCallback& callback) { |
| + if (!gcm_profile_service_->driver()) |
|
jianli
2014/06/06 17:32:21
Please comment that GCMDriver could be NULL due to
johnme
2014/06/06 18:48:25
I added the comment, since in the current approach
|
| + return; |
| + std::vector<std::string> sender_ids(1, sender_id); |
| + gcm_profile_service_->driver()->Register( |
| + app_id, |
| + sender_ids, |
| + base::Bind(&PushMessagingServiceImpl::DidRegister, |
| + base::Unretained(this), |
| + callback)); |
| +} |
| + |
| +void PushMessagingServiceImpl::DidRegister( |
| + const content::PushMessagingService::RegisterCallback& callback, |
| + const std::string& registration_id, |
| + GCMClient::Result result) { |
| + GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); |
| + bool error = (result != GCMClient::SUCCESS); |
| + callback.Run(endpoint, registration_id, error); |
| +} |
| + |
| +} // namespace gcm |