OLD | NEW |
---|---|
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 mcs_proto::AppData* app_data = stanza.add_app_data(); | 406 mcs_proto::AppData* app_data = stanza.add_app_data(); |
407 app_data->set_key(iter->first); | 407 app_data->set_key(iter->first); |
408 app_data->set_value(iter->second); | 408 app_data->set_value(iter->second); |
409 } | 409 } |
410 | 410 |
411 MCSMessage mcs_message(stanza); | 411 MCSMessage mcs_message(stanza); |
412 DVLOG(1) << "MCS message size: " << mcs_message.size(); | 412 DVLOG(1) << "MCS message size: " << mcs_message.size(); |
413 mcs_client_->SendMessage(mcs_message); | 413 mcs_client_->SendMessage(mcs_message); |
414 } | 414 } |
415 | 415 |
416 std::string GCMClientImpl::GetStateString(gcm::GCMClientImpl::State state) { | |
417 switch(state) { | |
418 case GCMClientImpl::INITIALIZED: | |
419 return "INITIALIZED"; | |
420 case GCMClientImpl::UNINITIALIZED: | |
421 return "UNINITIALIZED"; | |
422 case GCMClientImpl::LOADING: | |
423 return "LOADING"; | |
424 case GCMClientImpl::INITIAL_DEVICE_CHECKIN: | |
425 return "INITIAL_DEVICE_CHECKIN"; | |
426 case GCMClientImpl::READY: | |
427 return "READY"; | |
jianli
2014/03/04 23:47:39
nit: Please handle default case.
juyik
2014/03/05 05:08:08
Done.
| |
428 } | |
429 return std::string(); | |
430 } | |
431 | |
432 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { | |
433 GCMClient::GCMStatistics stats; | |
434 stats.gcm_client_state = GCMClientImpl::GetStateString(state_); | |
435 stats.connection_client_created = (mcs_client_.get() != NULL); | |
jianli
2014/03/04 23:47:39
nit: parentheses are not needed
juyik
2014/03/05 05:08:08
Done.
| |
436 if (mcs_client_.get()) { | |
437 stats.connection_state = MCSClient::GetStateString(mcs_client_->state()); | |
438 // TODO(juyik): add more statistics such as message metadata list, etc. | |
439 } | |
440 return stats; | |
441 } | |
442 | |
416 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { | 443 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { |
417 switch (message.tag()) { | 444 switch (message.tag()) { |
418 case kLoginResponseTag: | 445 case kLoginResponseTag: |
419 DVLOG(1) << "Login response received by GCM Client. Ignoring."; | 446 DVLOG(1) << "Login response received by GCM Client. Ignoring."; |
420 return; | 447 return; |
421 case kDataMessageStanzaTag: | 448 case kDataMessageStanzaTag: |
422 DVLOG(1) << "A downstream message received. Processing..."; | 449 DVLOG(1) << "A downstream message received. Processing..."; |
423 HandleIncomingMessage(message); | 450 HandleIncomingMessage(message); |
424 return; | 451 return; |
425 default: | 452 default: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 if (iter != incoming_message.data.end()) | 529 if (iter != incoming_message.data.end()) |
503 message_id = iter->second; | 530 message_id = iter->second; |
504 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR); | 531 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR); |
505 } | 532 } |
506 | 533 |
507 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { | 534 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { |
508 mcs_client_ = mcs_client.Pass(); | 535 mcs_client_ = mcs_client.Pass(); |
509 } | 536 } |
510 | 537 |
511 } // namespace gcm | 538 } // namespace gcm |
OLD | NEW |