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..383fbb2c188c457481d99118ed6b446159c41e2a 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> |
+ |
#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( |
@@ -250,7 +255,9 @@ void GCMClientImpl::StartCheckin(const CheckinInfo& checkin_info) { |
checkin_info.android_id, |
checkin_info.secret, |
account_ids_, |
- url_request_context_getter_)); |
+ url_request_context_getter_, |
+ &recorder_)); |
+ recorder_.RecordCheckin(checkin_info.android_id, GCMStatsRecorder::Initiated); |
checkin_request_->Start(); |
} |
@@ -318,8 +325,10 @@ void GCMClientImpl::Register(const std::string& app_id, |
weak_ptr_factory_.GetWeakPtr(), |
app_id), |
kMaxRegistrationRetries, |
- url_request_context_getter_); |
+ url_request_context_getter_, |
+ &recorder_); |
pending_registrations_[app_id] = registration_request; |
+ recorder_.RecordRegister(app_id, GCMStatsRecorder::Initiated, sender_ids); |
registration_request->Start(); |
} |
@@ -413,6 +422,8 @@ void GCMClientImpl::Send(const std::string& app_id, |
MCSMessage mcs_message(stanza); |
DVLOG(1) << "MCS message size: " << mcs_message.size(); |
+ recorder_.RecordSend(app_id, GCMStatsRecorder::Initiated, receiver_id, |
+ message.id, mcs_message.size()); |
mcs_client_->SendMessage(mcs_message); |
} |
@@ -434,16 +445,51 @@ 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.is_recording = recorder_.IsRecording(); |
stats.gcm_client_state = GCMClientImpl::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::CheckinActivity>::const_iterator it |
+ = recorder_.CheckinActivities().begin(); |
jianli
2014/03/18 23:53:23
nit: '=' should be moved to the end of previous li
juyik
2014/03/20 01:09:53
Done.
|
+ it != recorder_.CheckinActivities().end(); |
+ ++it) { |
+ stats.checkins.push_back(*it); |
+ } |
+ for (std::deque<GCMStatsRecorder::RegisterActivity>::const_iterator it |
+ = recorder_.RegisterActivities().begin(); |
+ it != recorder_.RegisterActivities().end(); |
+ ++it) { |
+ stats.registers.push_back(*it); |
+ } |
+ for (std::deque<GCMStatsRecorder::SendMessageActivity>::const_iterator it |
+ = recorder_.SendMessageActivities().begin(); |
+ it != recorder_.SendMessageActivities().end(); |
+ ++it) { |
+ stats.sent_messages.push_back(*it); |
+ } |
+ for (std::deque<GCMStatsRecorder::ReceiveMessageActivity>::const_iterator it |
+ = recorder_.ReceiveMessageActivities().begin(); |
+ it != recorder_.ReceiveMessageActivities().end(); |
+ ++it) { |
+ stats.received_messages.push_back(*it); |
+ } |
return stats; |
} |
@@ -522,6 +568,11 @@ void GCMClientImpl::HandleIncomingMessage(const gcm::MCSMessage& message) { |
HandleIncomingDataMessage(data_message_stanza, message_data); |
break; |
case DELETED_MESSAGES: |
+ recorder_.RecordReceiveWithDetails( |
+ GCMStatsRecorder::Success, |
+ data_message_stanza.from(), |
+ data_message_stanza.category(), |
+ "Received DELETED MESSAGE"); |
delegate_->OnMessagesDeleted(data_message_stanza.category()); |
break; |
case SEND_ERROR: |
@@ -531,6 +582,11 @@ void GCMClientImpl::HandleIncomingMessage(const gcm::MCSMessage& message) { |
default: // Treat default the same as UNKNOWN. |
DVLOG(1) << "Unknown message_type received. Message ignored. " |
<< "App ID: " << data_message_stanza.category() << "."; |
+ recorder_.RecordReceiveWithDetails( |
+ GCMStatsRecorder::Success, |
+ data_message_stanza.from(), |
+ data_message_stanza.category(), |
+ "Unknown message type received"); |
break; |
} |
} |
@@ -543,6 +599,9 @@ void GCMClientImpl::HandleIncomingDataMessage( |
if (data_message_stanza.has_token()) |
incoming_message.collapse_key = data_message_stanza.token(); |
incoming_message.data = message_data; |
+ recorder_.RecordReceiveDataMessage(incoming_message.sender_id, |
+ data_message_stanza.category(), |
+ incoming_message.data.size()); |
delegate_->OnMessageReceived(data_message_stanza.category(), |
incoming_message); |
} |
@@ -561,6 +620,12 @@ void GCMClientImpl::HandleIncomingSendError( |
send_error_details.additional_data.erase(iter); |
} |
+ recorder_.RecordReceiveWithDetails( |
+ GCMStatsRecorder::Error, |
+ std::string(), |
+ data_message_stanza.category(), |
+ base::StringPrintf("Send nessage server error. Message id: %s", |
+ send_error_details.message_id.c_str())); |
delegate_->OnMessageSendError(data_message_stanza.category(), |
send_error_details); |
} |