| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/copresence/handlers/gcm_handler_impl.h" | 5 #include "components/copresence/handlers/gcm_handler_impl.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 const char GCMHandlerImpl::kCopresenceAppId[] = | 37 const char GCMHandlerImpl::kCopresenceAppId[] = |
| 38 "com.google.android.gms.location.copresence"; | 38 "com.google.android.gms.location.copresence"; |
| 39 const char GCMHandlerImpl::kCopresenceSenderId[] = "745476177629"; | 39 const char GCMHandlerImpl::kCopresenceSenderId[] = "745476177629"; |
| 40 const char GCMHandlerImpl::kGcmMessageKey[] = "PUSH_MESSAGE"; | 40 const char GCMHandlerImpl::kGcmMessageKey[] = "PUSH_MESSAGE"; |
| 41 | 41 |
| 42 | 42 |
| 43 // Public functions. | 43 // Public functions. |
| 44 | 44 |
| 45 GCMHandlerImpl::GCMHandlerImpl(gcm::GCMDriver* gcm_driver, | 45 GCMHandlerImpl::GCMHandlerImpl(gcm::GCMDriver* gcm_driver, |
| 46 DirectiveHandler* directive_handler) | 46 DirectiveHandler* directive_handler, |
| 47 const MessagesCallback& new_messages_callback) |
| 47 : driver_(gcm_driver), | 48 : driver_(gcm_driver), |
| 48 directive_handler_(directive_handler), | 49 directive_handler_(directive_handler), |
| 50 new_messages_callback_(new_messages_callback), |
| 49 registration_callback_(base::Bind(&GCMHandlerImpl::RegistrationComplete, | 51 registration_callback_(base::Bind(&GCMHandlerImpl::RegistrationComplete, |
| 50 base::Unretained(this))) { | 52 base::Unretained(this))) { |
| 51 DCHECK(driver_); | 53 DCHECK(driver_); |
| 52 DCHECK(directive_handler_); | 54 DCHECK(directive_handler_); |
| 53 | 55 |
| 54 driver_->AddAppHandler(kCopresenceAppId, this); | 56 driver_->AddAppHandler(kCopresenceAppId, this); |
| 55 driver_->Register(kCopresenceAppId, | 57 driver_->Register(kCopresenceAppId, |
| 56 std::vector<std::string>(1, kCopresenceSenderId), | 58 std::vector<std::string>(1, kCopresenceSenderId), |
| 57 registration_callback_.callback()); | 59 registration_callback_.callback()); |
| 58 } | 60 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return; | 100 return; |
| 99 } | 101 } |
| 100 | 102 |
| 101 if (push_message.type() != PushMessage::REPORT) { | 103 if (push_message.type() != PushMessage::REPORT) { |
| 102 DVLOG(2) << "Discarding non-report GCM message"; | 104 DVLOG(2) << "Discarding non-report GCM message"; |
| 103 return; | 105 return; |
| 104 } | 106 } |
| 105 | 107 |
| 106 DVLOG(3) << "Processing " << push_message.report().directive_size() | 108 DVLOG(3) << "Processing " << push_message.report().directive_size() |
| 107 << " directive(s) from GCM message"; | 109 << " directive(s) from GCM message"; |
| 108 for (const Directive& directive : push_message.report().directive()) | 110 for (const Directive& directive : push_message.report().directive()) { |
| 111 // TODO(ckehoe): Use a callback here so GCMHandler |
| 112 // is decoupled from DirectiveHandler. |
| 109 directive_handler_->AddDirective(directive); | 113 directive_handler_->AddDirective(directive); |
| 114 } |
| 110 | 115 |
| 111 int message_count = push_message.report().subscribed_message_size(); | 116 new_messages_callback_.Run(push_message.report().subscribed_message()); |
| 112 LOG_IF(WARNING, message_count > 0) | |
| 113 << "Discarding " << message_count << " copresence messages sent via GCM"; | |
| 114 } | 117 } |
| 115 | 118 |
| 116 void GCMHandlerImpl::OnMessagesDeleted(const std::string& app_id) { | 119 void GCMHandlerImpl::OnMessagesDeleted(const std::string& app_id) { |
| 117 DCHECK_EQ(kCopresenceAppId, app_id); | 120 DCHECK_EQ(kCopresenceAppId, app_id); |
| 118 DVLOG(2) << "GCM message overflow reported"; | 121 DVLOG(2) << "GCM message overflow reported"; |
| 119 } | 122 } |
| 120 | 123 |
| 121 void GCMHandlerImpl::OnSendError( | 124 void GCMHandlerImpl::OnSendError( |
| 122 const std::string& /* app_id */, | 125 const std::string& /* app_id */, |
| 123 const GCMClient::SendErrorDetails& /* send_error_details */) { | 126 const GCMClient::SendErrorDetails& /* send_error_details */) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 146 } | 149 } |
| 147 | 150 |
| 148 for (const RegistrationCallback& callback : pending_id_requests_) { | 151 for (const RegistrationCallback& callback : pending_id_requests_) { |
| 149 callback.Run(result == GCMClient::SUCCESS ? | 152 callback.Run(result == GCMClient::SUCCESS ? |
| 150 registration_id : std::string()); | 153 registration_id : std::string()); |
| 151 } | 154 } |
| 152 pending_id_requests_.clear(); | 155 pending_id_requests_.clear(); |
| 153 } | 156 } |
| 154 | 157 |
| 155 } // namespace copresence | 158 } // namespace copresence |
| OLD | NEW |