Chromium Code Reviews| Index: google_apis/gcm/gcm_client_impl.cc |
| diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc |
| index 0c9d0fa93713a178610c56529e0e201343eab0ab..3fd03b2536bfdca12f1f1ee52e9725903ff0d610 100644 |
| --- a/google_apis/gcm/gcm_client_impl.cc |
| +++ b/google_apis/gcm/gcm_client_impl.cc |
| @@ -4,6 +4,8 @@ |
| #include "google_apis/gcm/gcm_client_impl.h" |
| +#include <deque> |
|
jianli
2014/03/21 18:25:27
nit: not needed since it is included in gcm_stats_
juyik
2014/03/26 04:06:03
Done.
|
| + |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| @@ -11,6 +13,7 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/metrics/histogram.h" |
| #include "base/sequenced_task_runner.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/time/default_clock.h" |
| #include "google_apis/gcm/base/mcs_message.h" |
| #include "google_apis/gcm/base/mcs_util.h" |
| @@ -20,6 +23,7 @@ |
| #include "google_apis/gcm/engine/mcs_client.h" |
| #include "google_apis/gcm/engine/registration_request.h" |
| #include "google_apis/gcm/engine/unregistration_request.h" |
| +#include "google_apis/gcm/gcm_stats_recorder.h" |
| #include "google_apis/gcm/protocol/mcs.pb.h" |
| #include "net/http/http_network_session.h" |
| #include "net/url_request/url_request_context.h" |
| @@ -196,7 +200,8 @@ void GCMClientImpl::InitializeMCSClient( |
| mcs_client_.reset(new MCSClient(chrome_build_proto_.chrome_version(), |
| clock_.get(), |
| connection_factory_.get(), |
| - gcm_store_.get())); |
| + gcm_store_.get(), |
| + &recorder_)); |
| } |
| mcs_client_->Initialize( |
| @@ -413,6 +418,15 @@ void GCMClientImpl::Send(const std::string& app_id, |
| MCSMessage mcs_message(stanza); |
| DVLOG(1) << "MCS message size: " << mcs_message.size(); |
| + recorder_.RecordSendingWithUMACounts( |
| + app_id, |
| + receiver_id, |
| + message.id, |
| + "SEND is called", |
| + base::StringPrintf("Msg size: %d bytes, TTL: %d", stanza.ByteSize(), |
| + message.time_to_live), |
| + "GCM.SendAPICalled", |
| + 1); |
| mcs_client_->SendMessage(mcs_message); |
| } |
| @@ -434,16 +448,33 @@ std::string GCMClientImpl::GetStateString() const { |
| } |
| } |
| +void GCMClientImpl::SetRecording(bool recording) { |
| + recorder_.SetRecording(recording); |
| +} |
| + |
| +void GCMClientImpl::ClearActivityLogs() { |
| + recorder_.Clear(); |
| +} |
| + |
| GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { |
| GCMClient::GCMStatistics stats; |
| - stats.gcm_client_state = GCMClientImpl::GetStateString(); |
| + stats.is_recording = recorder_.is_recording(); |
| + stats.gcm_client_state = GetStateString(); |
| stats.connection_client_created = mcs_client_.get() != NULL; |
| if (mcs_client_.get()) { |
| stats.connection_state = mcs_client_->GetStateString(); |
| - // TODO(juyik): add more statistics such as message metadata list, etc. |
| + stats.send_queue_size = mcs_client_->GetSendQueueSize(); |
| + stats.unacked_queue_size = mcs_client_->GetUnackedQueueSize(); |
| } |
| if (device_checkin_info_.android_id > 0) |
| stats.android_id = device_checkin_info_.android_id; |
| + |
| + for (std::deque<GCMStatsRecorder::SendingActivity>::const_iterator it = |
| + recorder_.sending_activities().begin(); |
| + it != recorder_.sending_activities().end(); |
| + ++it) { |
| + stats.sending.push_back(*it); |
| + } |
| return stats; |
| } |
| @@ -561,6 +592,16 @@ void GCMClientImpl::HandleIncomingSendError( |
| send_error_details.additional_data.erase(iter); |
| } |
| + recorder_.RecordSendingWithUMACounts( |
| + data_message_stanza.category(), |
| + data_message_stanza.to(), |
| + data_message_stanza.id(), |
| + "SEND ERROR is received", |
| + base::StringPrintf("Msg size: %d bytes, TTL: %d", |
| + data_message_stanza.ByteSize(), |
| + data_message_stanza.ttl()), |
| + "GCM.SendMessageErrors", |
| + 1); |
| delegate_->OnMessageSendError(data_message_stanza.category(), |
| send_error_details); |
| } |