Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Side by Side Diff: google_apis/gcm/gcm_client_impl.cc

Issue 185133008: [GCM] Only allow the senders that the application is currently registered for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving the comment up Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gcm/gcm_client.h ('k') | google_apis/gcm/gcm_client_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "google_apis/gcm/gcm_client_impl.h" 5 #include "google_apis/gcm/gcm_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 else if (status != MCSClient::SENT) 449 else if (status != MCSClient::SENT)
450 delegate_->OnSendFinished(app_id, message_id, ToGCMClientResult(status)); 450 delegate_->OnSendFinished(app_id, message_id, ToGCMClientResult(status));
451 } 451 }
452 452
453 void GCMClientImpl::OnMCSError() { 453 void GCMClientImpl::OnMCSError() {
454 // TODO(fgorski): For now it replaces the initialization method. Long term it 454 // TODO(fgorski): For now it replaces the initialization method. Long term it
455 // should have an error or status passed in. 455 // should have an error or status passed in.
456 } 456 }
457 457
458 void GCMClientImpl::HandleIncomingMessage(const gcm::MCSMessage& message) { 458 void GCMClientImpl::HandleIncomingMessage(const gcm::MCSMessage& message) {
459 DCHECK(delegate_);
460
459 const mcs_proto::DataMessageStanza& data_message_stanza = 461 const mcs_proto::DataMessageStanza& data_message_stanza =
460 reinterpret_cast<const mcs_proto::DataMessageStanza&>( 462 reinterpret_cast<const mcs_proto::DataMessageStanza&>(
461 message.GetProtobuf()); 463 message.GetProtobuf());
464 DCHECK_EQ(data_message_stanza.device_user_id(), kDefaultUserSerialNumber);
465
462 IncomingMessage incoming_message; 466 IncomingMessage incoming_message;
463 MessageType message_type = DATA_MESSAGE; 467 MessageType message_type = DATA_MESSAGE;
464 for (int i = 0; i < data_message_stanza.app_data_size(); ++i) { 468 for (int i = 0; i < data_message_stanza.app_data_size(); ++i) {
465 std::string key = data_message_stanza.app_data(i).key(); 469 std::string key = data_message_stanza.app_data(i).key();
466 if (key == kMessageTypeKey) 470 if (key == kMessageTypeKey)
467 message_type = DecodeMessageType(data_message_stanza.app_data(i).value()); 471 message_type = DecodeMessageType(data_message_stanza.app_data(i).value());
468 else 472 else
469 incoming_message.data[key] = data_message_stanza.app_data(i).value(); 473 incoming_message.data[key] = data_message_stanza.app_data(i).value();
470 } 474 }
471 475
472 if (data_message_stanza.has_token())
473 incoming_message.collapse_key = data_message_stanza.token();
474
475 DCHECK_EQ(data_message_stanza.device_user_id(), kDefaultUserSerialNumber);
476 DCHECK(delegate_);
477 476
478 switch (message_type) { 477 switch (message_type) {
479 case DATA_MESSAGE: 478 case DATA_MESSAGE:
479 incoming_message.sender_id = data_message_stanza.from();
480 if (data_message_stanza.has_token())
481 incoming_message.collapse_key = data_message_stanza.token();
480 delegate_->OnMessageReceived(data_message_stanza.category(), 482 delegate_->OnMessageReceived(data_message_stanza.category(),
481 incoming_message); 483 incoming_message);
482 break; 484 break;
483 case DELETED_MESSAGES: 485 case DELETED_MESSAGES:
484 delegate_->OnMessagesDeleted(data_message_stanza.category()); 486 delegate_->OnMessagesDeleted(data_message_stanza.category());
485 break; 487 break;
486 case SEND_ERROR: 488 case SEND_ERROR:
487 NotifyDelegateOnMessageSendError( 489 NotifyDelegateOnMessageSendError(
488 delegate_, data_message_stanza.category(), incoming_message); 490 delegate_, data_message_stanza.category(), incoming_message);
489 break; 491 break;
(...skipping 15 matching lines...) Expand all
505 if (iter != incoming_message.data.end()) 507 if (iter != incoming_message.data.end())
506 message_id = iter->second; 508 message_id = iter->second;
507 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR); 509 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR);
508 } 510 }
509 511
510 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { 512 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) {
511 mcs_client_ = mcs_client.Pass(); 513 mcs_client_ = mcs_client.Pass();
512 } 514 }
513 515
514 } // namespace gcm 516 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/gcm_client.h ('k') | google_apis/gcm/gcm_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698