diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 21:51:12 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 21:51:12 +0000 |
commit | 025adfa494d92b8860ff9307eefabe09553657b8 (patch) | |
tree | 85f12ac3024cdbccf61c0f2b81b6dfc8fa82df81 /google_apis/gcm/monitoring | |
parent | 7fd6959f1d0dfae4ecb0cd8ab7894700db68a1fd (diff) | |
download | chromium_src-025adfa494d92b8860ff9307eefabe09553657b8.zip chromium_src-025adfa494d92b8860ff9307eefabe09553657b8.tar.gz chromium_src-025adfa494d92b8860ff9307eefabe09553657b8.tar.bz2 |
Rename GCMStatsRecorder to GCMStatsRecorderImpl
We also add the interface using the old name GCMStatsRecorder.
This is in preparation to move GCMClient to gcm_driver component.
We're going to move GCMActivity, GCMClient, GCMClientImpl, and
GCMStatsRecorderImpl to gcm_driver component while keeping
GCMStatsRecorder interface in google_apis/gcm.
BUG=356716
TEST=existing tests due to no functionality changes
R=juyik@chromium.org, zea@chromium.org
Review URL: https://codereview.chromium.org/312553002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gcm/monitoring')
-rw-r--r-- | google_apis/gcm/monitoring/fake_gcm_stats_recorder.cc | 107 | ||||
-rw-r--r-- | google_apis/gcm/monitoring/fake_gcm_stats_recorder.h | 71 | ||||
-rw-r--r-- | google_apis/gcm/monitoring/gcm_stats_recorder.h | 185 | ||||
-rw-r--r-- | google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc (renamed from google_apis/gcm/monitoring/gcm_stats_recorder.cc) | 79 | ||||
-rw-r--r-- | google_apis/gcm/monitoring/gcm_stats_recorder_impl.h | 156 | ||||
-rw-r--r-- | google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc (renamed from google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc) | 30 |
6 files changed, 443 insertions, 185 deletions
diff --git a/google_apis/gcm/monitoring/fake_gcm_stats_recorder.cc b/google_apis/gcm/monitoring/fake_gcm_stats_recorder.cc new file mode 100644 index 0000000..5ed8a1d --- /dev/null +++ b/google_apis/gcm/monitoring/fake_gcm_stats_recorder.cc @@ -0,0 +1,107 @@ +// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
+
+namespace gcm {
+
+FakeGCMStatsRecorder::FakeGCMStatsRecorder() {
+}
+
+FakeGCMStatsRecorder::~FakeGCMStatsRecorder() {
+}
+
+void FakeGCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) {
+}
+
+void FakeGCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) {
+}
+
+void FakeGCMStatsRecorder::RecordCheckinSuccess() {
+}
+
+void FakeGCMStatsRecorder::RecordCheckinFailure(std::string status,
+ bool will_retry) {
+}
+
+void FakeGCMStatsRecorder::RecordConnectionInitiated(const std::string& host) {
+}
+
+void FakeGCMStatsRecorder::RecordConnectionDelayedDueToBackoff(
+ int64 delay_msec) {
+}
+
+void FakeGCMStatsRecorder::RecordConnectionSuccess() {
+}
+
+void FakeGCMStatsRecorder::RecordConnectionFailure(int network_error) {
+}
+
+void FakeGCMStatsRecorder::RecordConnectionResetSignaled(
+ ConnectionFactory::ConnectionResetReason reason) {
+}
+
+void FakeGCMStatsRecorder::RecordRegistrationSent(
+ const std::string& app_id,
+ const std::string& sender_ids) {
+}
+
+void FakeGCMStatsRecorder::RecordRegistrationResponse(
+ const std::string& app_id,
+ const std::vector<std::string>& sender_ids,
+ RegistrationRequest::Status status) {
+}
+
+void FakeGCMStatsRecorder::RecordRegistrationRetryRequested(
+ const std::string& app_id,
+ const std::vector<std::string>& sender_ids,
+ int retries_left) {
+}
+
+void FakeGCMStatsRecorder::RecordUnregistrationSent(
+ const std::string& app_id) {
+}
+
+void FakeGCMStatsRecorder::RecordUnregistrationResponse(
+ const std::string& app_id,
+ UnregistrationRequest::Status status) {
+}
+
+void FakeGCMStatsRecorder::RecordUnregistrationRetryDelayed(
+ const std::string& app_id,
+ int64 delay_msec) {
+}
+
+void FakeGCMStatsRecorder::RecordDataMessageReceived(
+ const std::string& app_id,
+ const std::string& from,
+ int message_byte_size,
+ bool to_registered_app,
+ ReceivedMessageType message_type) {
+}
+
+void FakeGCMStatsRecorder::RecordDataSentToWire(
+ const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ int queued) {
+}
+
+void FakeGCMStatsRecorder::RecordNotifySendStatus(
+ const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ gcm::MCSClient::MessageSendStatus status,
+ int byte_size,
+ int ttl) {
+}
+
+void FakeGCMStatsRecorder::RecordIncomingSendError(
+ const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id) {
+}
+
+
+} // namespace gcm
diff --git a/google_apis/gcm/monitoring/fake_gcm_stats_recorder.h b/google_apis/gcm/monitoring/fake_gcm_stats_recorder.h new file mode 100644 index 0000000..1ada611 --- /dev/null +++ b/google_apis/gcm/monitoring/fake_gcm_stats_recorder.h @@ -0,0 +1,71 @@ +// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GOOGLE_APIS_GCM_MONITORING_FAKE_GCM_STATS_RECODER_H_
+#define GOOGLE_APIS_GCM_MONITORING_FAKE_GCM_STATS_RECODER_H_
+
+#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
+
+namespace gcm {
+
+// The fake version of GCMStatsRecorder that does nothing.
+class FakeGCMStatsRecorder : public GCMStatsRecorder {
+ public:
+ FakeGCMStatsRecorder();
+ virtual ~FakeGCMStatsRecorder();
+
+ virtual void RecordCheckinInitiated(uint64 android_id) OVERRIDE;
+ virtual void RecordCheckinDelayedDueToBackoff(int64 delay_msec) OVERRIDE;
+ virtual void RecordCheckinSuccess() OVERRIDE;
+ virtual void RecordCheckinFailure(std::string status,
+ bool will_retry) OVERRIDE;
+ virtual void RecordConnectionInitiated(const std::string& host) OVERRIDE;
+ virtual void RecordConnectionDelayedDueToBackoff(int64 delay_msec) OVERRIDE;
+ virtual void RecordConnectionSuccess() OVERRIDE;
+ virtual void RecordConnectionFailure(int network_error) OVERRIDE;
+ virtual void RecordConnectionResetSignaled(
+ ConnectionFactory::ConnectionResetReason reason) OVERRIDE;
+ virtual void RecordRegistrationSent(const std::string& app_id,
+ const std::string& sender_ids) OVERRIDE;
+ virtual void RecordRegistrationResponse(
+ const std::string& app_id,
+ const std::vector<std::string>& sender_ids,
+ RegistrationRequest::Status status) OVERRIDE;
+ virtual void RecordRegistrationRetryRequested(
+ const std::string& app_id,
+ const std::vector<std::string>& sender_ids,
+ int retries_left) OVERRIDE;
+ virtual void RecordUnregistrationSent(const std::string& app_id) OVERRIDE;
+ virtual void RecordUnregistrationResponse(
+ const std::string& app_id,
+ UnregistrationRequest::Status status) OVERRIDE;
+ virtual void RecordUnregistrationRetryDelayed(const std::string& app_id,
+ int64 delay_msec) OVERRIDE;
+ virtual void RecordDataMessageReceived(
+ const std::string& app_id,
+ const std::string& from,
+ int message_byte_size,
+ bool to_registered_app,
+ ReceivedMessageType message_type) OVERRIDE;
+ virtual void RecordDataSentToWire(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ int queued) OVERRIDE;
+ virtual void RecordNotifySendStatus(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id,
+ MCSClient::MessageSendStatus status,
+ int byte_size,
+ int ttl) OVERRIDE;
+ virtual void RecordIncomingSendError(const std::string& app_id,
+ const std::string& receiver_id,
+ const std::string& message_id) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FakeGCMStatsRecorder);
+};
+
+} // namespace gcm
+
+#endif // GOOGLE_APIS_GCM_MONITORING_FAKE_GCM_STATS_RECODER_H_
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder.h b/google_apis/gcm/monitoring/gcm_stats_recorder.h index 45cf5fc..7191569 100644 --- a/google_apis/gcm/monitoring/gcm_stats_recorder.h +++ b/google_apis/gcm/monitoring/gcm_stats_recorder.h @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ -#define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ +#ifndef GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_ +#define GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_ -#include <deque> #include <string> #include <vector> @@ -15,15 +14,11 @@ #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_activity.h" namespace gcm { -// Records GCM internal stats and activities for debugging purpose. Recording -// can be turned on/off by calling SetRecording(...) function. It is turned off -// by default. -// This class is not thread safe. It is meant to be owned by a gcm client -// instance. +// Defines the interface to record GCM internal stats and activities for +// debugging purpose. class GCM_EXPORT GCMStatsRecorder { public: // Type of a received message @@ -34,181 +29,107 @@ class GCM_EXPORT GCMStatsRecorder { DELETED_MESSAGES, }; - // A delegate interface that allows the GCMStatsRecorder instance to interact - // with its container. + // A delegate interface that allows the GCMStatsRecorderImpl instance to + // interact with its container. class Delegate { - public: - // Called when the GCMStatsRecorder is recording activities and a new + public: + // Called when the GCMStatsRecorderImpl is recording activities and a new // activity has just been recorded. virtual void OnActivityRecorded() = 0; }; - GCMStatsRecorder(); - virtual ~GCMStatsRecorder(); - - // Indicates whether the recorder is currently recording activities or not. - bool is_recording() const { - return is_recording_; - } - - // Turns recording on/off. - void SetRecording(bool recording); - - // Set a delegate to receive callback from the recorder. - void SetDelegate(Delegate* delegate); - - // Clear all recorded activities. - void Clear(); - - // All RecordXXXX methods below will record one activity. It will be inserted - // to the front of a queue so that entries in the queue had reverse - // chronological order. + GCMStatsRecorder() {} + virtual ~GCMStatsRecorder() {} // Records that a check-in has been initiated. - void RecordCheckinInitiated(uint64 android_id); + virtual void RecordCheckinInitiated(uint64 android_id) = 0; // Records that a check-in has been delayed due to backoff. - void RecordCheckinDelayedDueToBackoff(int64 delay_msec); + virtual void RecordCheckinDelayedDueToBackoff(int64 delay_msec) = 0; // Records that a check-in request has succeeded. - void RecordCheckinSuccess(); + virtual void RecordCheckinSuccess() = 0; // Records that a check-in request has failed. If a retry will be tempted then // will_retry should be true. - void RecordCheckinFailure(std::string status, bool will_retry); + virtual void RecordCheckinFailure(std::string status, bool will_retry) = 0; // Records that a connection to MCS has been initiated. - void RecordConnectionInitiated(const std::string& host); + virtual void RecordConnectionInitiated(const std::string& host) = 0; // Records that a connection has been delayed due to backoff. - void RecordConnectionDelayedDueToBackoff(int64 delay_msec); + virtual void RecordConnectionDelayedDueToBackoff(int64 delay_msec) = 0; // Records that connection has been successfully established. - void RecordConnectionSuccess(); + virtual void RecordConnectionSuccess() = 0; // Records that connection has failed with a network error code. - void RecordConnectionFailure(int network_error); + virtual void RecordConnectionFailure(int network_error) = 0; // Records that connection reset has been signaled. - void RecordConnectionResetSignaled( - ConnectionFactory::ConnectionResetReason reason); + virtual void RecordConnectionResetSignaled( + ConnectionFactory::ConnectionResetReason reason) = 0; // Records that a registration request has been sent. This could be initiated // directly from API, or from retry logic. - void RecordRegistrationSent(const std::string& app_id, - const std::string& sender_ids); + virtual void RecordRegistrationSent(const std::string& app_id, + const std::string& sender_ids) = 0; // Records that a registration response has been received from server. - void RecordRegistrationResponse(const std::string& app_id, - const std::vector<std::string>& sender_ids, - RegistrationRequest::Status status); + virtual void RecordRegistrationResponse( + const std::string& app_id, + const std::vector<std::string>& sender_ids, + RegistrationRequest::Status status) = 0; // Records that a registration retry has been requested. The actual retry // action may not occur until some time later according to backoff logic. - void RecordRegistrationRetryRequested( + virtual void RecordRegistrationRetryRequested( const std::string& app_id, const std::vector<std::string>& sender_ids, - int retries_left); + int retries_left) = 0; // Records that an unregistration request has been sent. This could be // initiated directly from API, or from retry logic. - void RecordUnregistrationSent(const std::string& app_id); + virtual void RecordUnregistrationSent(const std::string& app_id) = 0; // Records that an unregistration response has been received from server. - void RecordUnregistrationResponse(const std::string& app_id, - UnregistrationRequest::Status status); + virtual void RecordUnregistrationResponse( + const std::string& app_id, + UnregistrationRequest::Status status) = 0; // Records that an unregistration retry has been requested and delayed due to // backoff logic. - void RecordUnregistrationRetryDelayed(const std::string& app_id, - int64 delay_msec); + virtual void RecordUnregistrationRetryDelayed(const std::string& app_id, + int64 delay_msec) = 0; // Records that a data message has been received. If this message is not // sent to a registered app, to_registered_app shoudl be false. If it // indicates that a message has been dropped on the server, is_message_dropped // should be true. - void RecordDataMessageReceived(const std::string& app_id, - const std::string& from, - int message_byte_size, - bool to_registered_app, - ReceivedMessageType message_type); + virtual void RecordDataMessageReceived(const std::string& app_id, + const std::string& from, + int message_byte_size, + bool to_registered_app, + ReceivedMessageType message_type) = 0; // Records that an outgoing data message was sent over the wire. - void RecordDataSentToWire(const std::string& app_id, - const std::string& receiver_id, - const std::string& message_id, - int queued); + virtual void RecordDataSentToWire(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + int queued) = 0; // Records that the MCS client sent a 'send status' notification to callback. - void RecordNotifySendStatus(const std::string& app_id, - const std::string& receiver_id, - const std::string& message_id, - MCSClient::MessageSendStatus status, - int byte_size, - int ttl); + virtual void RecordNotifySendStatus(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + MCSClient::MessageSendStatus status, + int byte_size, + int ttl) = 0; // Records that a 'send error' message was received. - void RecordIncomingSendError(const std::string& app_id, - const std::string& receiver_id, - const std::string& message_id); - - // Collect all recorded activities into the struct. - void CollectActivities(RecordedActivities* recorder_activities) const; - - const std::deque<CheckinActivity>& checkin_activities() const { - return checkin_activities_; - } - const std::deque<ConnectionActivity>& connection_activities() const { - return connection_activities_; - } - const std::deque<RegistrationActivity>& registration_activities() const { - return registration_activities_; - } - const std::deque<ReceivingActivity>& receiving_activities() const { - return receiving_activities_; - } - const std::deque<SendingActivity>& sending_activities() const { - return sending_activities_; - } - - protected: - // Notify the recorder delegate, if it exists, that an activity has been - // recorded. - void NotifyActivityRecorded(); - - void RecordCheckin(const std::string& event, - const std::string& details); - - void RecordConnection(const std::string& event, - const std::string& details); - - void RecordRegistration(const std::string& app_id, - const std::string& sender_id, - const std::string& event, - const std::string& details); - - void RecordReceiving(const std::string& app_id, - const std::string& from, - int message_byte_size, - const std::string& event, - const std::string& details); - - void RecordSending(const std::string& app_id, - const std::string& receiver_id, - const std::string& message_id, - const std::string& event, - const std::string& details); - - bool is_recording_; - Delegate* delegate_; - - std::deque<CheckinActivity> checkin_activities_; - std::deque<ConnectionActivity> connection_activities_; - std::deque<RegistrationActivity> registration_activities_; - std::deque<ReceivingActivity> receiving_activities_; - std::deque<SendingActivity> sending_activities_; - - DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); + virtual void RecordIncomingSendError(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id) = 0; }; } // namespace gcm -#endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ +#endif // GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_ diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder.cc b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc index f6c3e0f..8786d51 100644 --- a/google_apis/gcm/monitoring/gcm_stats_recorder.cc +++ b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" +#include "google_apis/gcm/monitoring/gcm_stats_recorder_impl.h" #include <deque> #include <vector> @@ -140,21 +140,23 @@ std::string GetUnregistrationStatusString( } // namespace -GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false), delegate_(NULL) { +GCMStatsRecorderImpl::GCMStatsRecorderImpl() + : is_recording_(false), + delegate_(NULL) { } -GCMStatsRecorder::~GCMStatsRecorder() { +GCMStatsRecorderImpl::~GCMStatsRecorderImpl() { } -void GCMStatsRecorder::SetRecording(bool recording) { +void GCMStatsRecorderImpl::SetRecording(bool recording) { is_recording_ = recording; } -void GCMStatsRecorder::SetDelegate(Delegate* delegate) { +void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) { delegate_ = delegate; } -void GCMStatsRecorder::Clear() { +void GCMStatsRecorderImpl::Clear() { checkin_activities_.clear(); connection_activities_.clear(); registration_activities_.clear(); @@ -162,12 +164,12 @@ void GCMStatsRecorder::Clear() { sending_activities_.clear(); } -void GCMStatsRecorder::NotifyActivityRecorded() { +void GCMStatsRecorderImpl::NotifyActivityRecorded() { if (delegate_) delegate_->OnActivityRecorded(); } -void GCMStatsRecorder::RecordCheckin( +void GCMStatsRecorderImpl::RecordCheckin( const std::string& event, const std::string& details) { CheckinActivity data; @@ -178,14 +180,14 @@ void GCMStatsRecorder::RecordCheckin( NotifyActivityRecorded(); } -void GCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) { +void GCMStatsRecorderImpl::RecordCheckinInitiated(uint64 android_id) { if (!is_recording_) return; RecordCheckin("Checkin initiated", base::StringPrintf("Android Id: %" PRIu64, android_id)); } -void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { +void GCMStatsRecorderImpl::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { if (!is_recording_) return; RecordCheckin("Checkin backoff", @@ -193,13 +195,13 @@ void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { delay_msec)); } -void GCMStatsRecorder::RecordCheckinSuccess() { +void GCMStatsRecorderImpl::RecordCheckinSuccess() { if (!is_recording_) return; RecordCheckin("Checkin succeeded", std::string()); } -void GCMStatsRecorder::RecordCheckinFailure(std::string status, +void GCMStatsRecorderImpl::RecordCheckinFailure(std::string status, bool will_retry) { if (!is_recording_) return; @@ -209,7 +211,7 @@ void GCMStatsRecorder::RecordCheckinFailure(std::string status, will_retry ? " Will retry." : "Will not retry.")); } -void GCMStatsRecorder::RecordConnection( +void GCMStatsRecorderImpl::RecordConnection( const std::string& event, const std::string& details) { ConnectionActivity data; @@ -220,13 +222,14 @@ void GCMStatsRecorder::RecordConnection( NotifyActivityRecorded(); } -void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) { +void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) { if (!is_recording_) return; RecordConnection("Connection initiated", host); } -void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { +void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff( + int64 delay_msec) { if (!is_recording_) return; RecordConnection("Connection backoff", @@ -234,20 +237,20 @@ void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { delay_msec)); } -void GCMStatsRecorder::RecordConnectionSuccess() { +void GCMStatsRecorderImpl::RecordConnectionSuccess() { if (!is_recording_) return; RecordConnection("Connection succeeded", std::string()); } -void GCMStatsRecorder::RecordConnectionFailure(int network_error) { +void GCMStatsRecorderImpl::RecordConnectionFailure(int network_error) { if (!is_recording_) return; RecordConnection("Connection failed", base::StringPrintf("With network error %d", network_error)); } -void GCMStatsRecorder::RecordConnectionResetSignaled( +void GCMStatsRecorderImpl::RecordConnectionResetSignaled( ConnectionFactory::ConnectionResetReason reason) { if (!is_recording_) return; @@ -255,7 +258,7 @@ void GCMStatsRecorder::RecordConnectionResetSignaled( GetConnectionResetReasonString(reason)); } -void GCMStatsRecorder::RecordRegistration( +void GCMStatsRecorderImpl::RecordRegistration( const std::string& app_id, const std::string& sender_ids, const std::string& event, @@ -270,7 +273,7 @@ void GCMStatsRecorder::RecordRegistration( NotifyActivityRecorded(); } -void GCMStatsRecorder::RecordRegistrationSent( +void GCMStatsRecorderImpl::RecordRegistrationSent( const std::string& app_id, const std::string& sender_ids) { UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); @@ -280,7 +283,7 @@ void GCMStatsRecorder::RecordRegistrationSent( "Registration request sent", std::string()); } -void GCMStatsRecorder::RecordRegistrationResponse( +void GCMStatsRecorderImpl::RecordRegistrationResponse( const std::string& app_id, const std::vector<std::string>& sender_ids, RegistrationRequest::Status status) { @@ -291,7 +294,7 @@ void GCMStatsRecorder::RecordRegistrationResponse( GetRegistrationStatusString(status)); } -void GCMStatsRecorder::RecordRegistrationRetryRequested( +void GCMStatsRecorderImpl::RecordRegistrationRetryRequested( const std::string& app_id, const std::vector<std::string>& sender_ids, int retries_left) { @@ -302,7 +305,7 @@ void GCMStatsRecorder::RecordRegistrationRetryRequested( base::StringPrintf("Retries left: %d", retries_left)); } -void GCMStatsRecorder::RecordUnregistrationSent( +void GCMStatsRecorderImpl::RecordUnregistrationSent( const std::string& app_id) { UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1); if (!is_recording_) @@ -311,7 +314,7 @@ void GCMStatsRecorder::RecordUnregistrationSent( std::string()); } -void GCMStatsRecorder::RecordUnregistrationResponse( +void GCMStatsRecorderImpl::RecordUnregistrationResponse( const std::string& app_id, UnregistrationRequest::Status status) { if (!is_recording_) @@ -322,7 +325,7 @@ void GCMStatsRecorder::RecordUnregistrationResponse( GetUnregistrationStatusString(status)); } -void GCMStatsRecorder::RecordUnregistrationRetryDelayed( +void GCMStatsRecorderImpl::RecordUnregistrationRetryDelayed( const std::string& app_id, int64 delay_msec) { if (!is_recording_) @@ -334,7 +337,7 @@ void GCMStatsRecorder::RecordUnregistrationRetryDelayed( delay_msec)); } -void GCMStatsRecorder::RecordReceiving( +void GCMStatsRecorderImpl::RecordReceiving( const std::string& app_id, const std::string& from, int message_byte_size, @@ -351,7 +354,7 @@ void GCMStatsRecorder::RecordReceiving( NotifyActivityRecorded(); } -void GCMStatsRecorder::RecordDataMessageReceived( +void GCMStatsRecorderImpl::RecordDataMessageReceived( const std::string& app_id, const std::string& from, int message_byte_size, @@ -367,11 +370,11 @@ void GCMStatsRecorder::RecordDataMessageReceived( "No such registered app found"); } else { switch(message_type) { - case GCMStatsRecorder::DATA_MESSAGE: + case GCMStatsRecorderImpl::DATA_MESSAGE: RecordReceiving(app_id, from, message_byte_size, "Data msg received", std::string()); break; - case GCMStatsRecorder::DELETED_MESSAGES: + case GCMStatsRecorderImpl::DELETED_MESSAGES: RecordReceiving(app_id, from, message_byte_size, "Data msg received", "Message has been deleted on server"); break; @@ -381,7 +384,7 @@ void GCMStatsRecorder::RecordDataMessageReceived( } } -void GCMStatsRecorder::CollectActivities( +void GCMStatsRecorderImpl::CollectActivities( RecordedActivities* recorder_activities) const { recorder_activities->checkin_activities.insert( recorder_activities->checkin_activities.begin(), @@ -405,11 +408,11 @@ void GCMStatsRecorder::CollectActivities( sending_activities_.end()); } -void GCMStatsRecorder::RecordSending(const std::string& app_id, - const std::string& receiver_id, - const std::string& message_id, - const std::string& event, - const std::string& details) { +void GCMStatsRecorderImpl::RecordSending(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + const std::string& event, + const std::string& details) { SendingActivity data; SendingActivity* inserted_data = InsertCircularBuffer( &sending_activities_, data); @@ -421,7 +424,7 @@ void GCMStatsRecorder::RecordSending(const std::string& app_id, NotifyActivityRecorded(); } -void GCMStatsRecorder::RecordDataSentToWire( +void GCMStatsRecorderImpl::RecordDataSentToWire( const std::string& app_id, const std::string& receiver_id, const std::string& message_id, @@ -432,7 +435,7 @@ void GCMStatsRecorder::RecordDataSentToWire( base::StringPrintf("Msg queued for %d seconds", queued)); } -void GCMStatsRecorder::RecordNotifySendStatus( +void GCMStatsRecorderImpl::RecordNotifySendStatus( const std::string& app_id, const std::string& receiver_id, const std::string& message_id, @@ -452,7 +455,7 @@ void GCMStatsRecorder::RecordNotifySendStatus( base::StringPrintf("Msg size: %d bytes, TTL: %d", byte_size, ttl)); } -void GCMStatsRecorder::RecordIncomingSendError( +void GCMStatsRecorderImpl::RecordIncomingSendError( const std::string& app_id, const std::string& receiver_id, const std::string& message_id) { diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h new file mode 100644 index 0000000..434cb67 --- /dev/null +++ b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h @@ -0,0 +1,156 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_IMPL_H_ +#define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_IMPL_H_ + +#include <deque> +#include <string> +#include <vector> + +#include "base/time/time.h" +#include "google_apis/gcm/base/gcm_export.h" +#include "google_apis/gcm/engine/connection_factory.h" +#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_activity.h" +#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" + +namespace gcm { + +// Records GCM internal stats and activities for debugging purpose. Recording +// can be turned on/off by calling SetRecording(...) function. It is turned off +// by default. +// This class is not thread safe. It is meant to be owned by a gcm client +// instance. +class GCM_EXPORT GCMStatsRecorderImpl : public GCMStatsRecorder { + public: + GCMStatsRecorderImpl(); + virtual ~GCMStatsRecorderImpl(); + + // Indicates whether the recorder is currently recording activities or not. + bool is_recording() const { + return is_recording_; + } + + // Turns recording on/off. + void SetRecording(bool recording); + + // Set a delegate to receive callback from the recorder. + void SetDelegate(Delegate* delegate); + + // Clear all recorded activities. + void Clear(); + + // GCMStatsRecorder implementation: + virtual void RecordCheckinInitiated(uint64 android_id) OVERRIDE; + virtual void RecordCheckinDelayedDueToBackoff(int64 delay_msec) OVERRIDE; + virtual void RecordCheckinSuccess() OVERRIDE; + virtual void RecordCheckinFailure(std::string status, + bool will_retry) OVERRIDE; + virtual void RecordConnectionInitiated(const std::string& host) OVERRIDE; + virtual void RecordConnectionDelayedDueToBackoff(int64 delay_msec) OVERRIDE; + virtual void RecordConnectionSuccess() OVERRIDE; + virtual void RecordConnectionFailure(int network_error) OVERRIDE; + virtual void RecordConnectionResetSignaled( + ConnectionFactory::ConnectionResetReason reason) OVERRIDE; + virtual void RecordRegistrationSent(const std::string& app_id, + const std::string& sender_ids) OVERRIDE; + virtual void RecordRegistrationResponse( + const std::string& app_id, + const std::vector<std::string>& sender_ids, + RegistrationRequest::Status status) OVERRIDE; + virtual void RecordRegistrationRetryRequested( + const std::string& app_id, + const std::vector<std::string>& sender_ids, + int retries_left) OVERRIDE; + virtual void RecordUnregistrationSent(const std::string& app_id) OVERRIDE; + virtual void RecordUnregistrationResponse( + const std::string& app_id, + UnregistrationRequest::Status status) OVERRIDE; + virtual void RecordUnregistrationRetryDelayed(const std::string& app_id, + int64 delay_msec) OVERRIDE; + virtual void RecordDataMessageReceived( + const std::string& app_id, + const std::string& from, + int message_byte_size, + bool to_registered_app, + ReceivedMessageType message_type) OVERRIDE; + virtual void RecordDataSentToWire(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + int queued) OVERRIDE; + virtual void RecordNotifySendStatus(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + MCSClient::MessageSendStatus status, + int byte_size, + int ttl) OVERRIDE; + virtual void RecordIncomingSendError(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id) OVERRIDE; + + // Collect all recorded activities into the struct. + void CollectActivities(RecordedActivities* recorder_activities) const; + + const std::deque<CheckinActivity>& checkin_activities() const { + return checkin_activities_; + } + const std::deque<ConnectionActivity>& connection_activities() const { + return connection_activities_; + } + const std::deque<RegistrationActivity>& registration_activities() const { + return registration_activities_; + } + const std::deque<ReceivingActivity>& receiving_activities() const { + return receiving_activities_; + } + const std::deque<SendingActivity>& sending_activities() const { + return sending_activities_; + } + + protected: + // Notify the recorder delegate, if it exists, that an activity has been + // recorded. + void NotifyActivityRecorded(); + + void RecordCheckin(const std::string& event, + const std::string& details); + + void RecordConnection(const std::string& event, + const std::string& details); + + void RecordRegistration(const std::string& app_id, + const std::string& sender_id, + const std::string& event, + const std::string& details); + + void RecordReceiving(const std::string& app_id, + const std::string& from, + int message_byte_size, + const std::string& event, + const std::string& details); + + void RecordSending(const std::string& app_id, + const std::string& receiver_id, + const std::string& message_id, + const std::string& event, + const std::string& details); + + bool is_recording_; + Delegate* delegate_; + + std::deque<CheckinActivity> checkin_activities_; + std::deque<ConnectionActivity> connection_activities_; + std::deque<RegistrationActivity> registration_activities_; + std::deque<ReceivingActivity> receiving_activities_; + std::deque<SendingActivity> sending_activities_; + + DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderImpl); +}; + +} // namespace gcm + +#endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_IMPL_H_ diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc b/google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc index c8756ec..e870a60c 100644 --- a/google_apis/gcm/monitoring/gcm_stats_recorder_unittest.cc +++ b/google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" +#include "google_apis/gcm/monitoring/gcm_stats_recorder_impl.h" #include <deque> #include <string> @@ -97,10 +97,10 @@ static const char kIncomingSendErrorDetails[] = ""; } // namespace -class GCMStatsRecorderTest : public testing::Test { +class GCMStatsRecorderImplTest : public testing::Test { public: - GCMStatsRecorderTest(); - virtual ~GCMStatsRecorderTest(); + GCMStatsRecorderImplTest(); + virtual ~GCMStatsRecorderImplTest(); virtual void SetUp() OVERRIDE; void VerifyRecordedCheckinCount(int expected_count) { @@ -339,21 +339,21 @@ class GCMStatsRecorderTest : public testing::Test { } std::vector<std::string> sender_ids_; - GCMStatsRecorder recorder_; + GCMStatsRecorderImpl recorder_; }; -GCMStatsRecorderTest::GCMStatsRecorderTest(){ +GCMStatsRecorderImplTest::GCMStatsRecorderImplTest(){ } -GCMStatsRecorderTest::~GCMStatsRecorderTest() {} +GCMStatsRecorderImplTest::~GCMStatsRecorderImplTest() {} -void GCMStatsRecorderTest::SetUp(){ +void GCMStatsRecorderImplTest::SetUp(){ sender_ids_.push_back("s1"); sender_ids_.push_back("s2"); recorder_.SetRecording(true); } -TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) { +TEST_F(GCMStatsRecorderImplTest, StartStopRecordingTest) { EXPECT_TRUE(recorder_.is_recording()); recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); VerifyRecordedSendingCount(1); @@ -403,7 +403,7 @@ TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) { VerifyAllActivityQueueEmpty("no sending"); } -TEST_F(GCMStatsRecorderTest, ClearLogTest) { +TEST_F(GCMStatsRecorderImplTest, ClearLogTest) { recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); VerifyRecordedSendingCount(1); VerifyDataSentToWire("1st call"); @@ -417,7 +417,7 @@ TEST_F(GCMStatsRecorderTest, ClearLogTest) { VerifyRecordedSendingCount(0); } -TEST_F(GCMStatsRecorderTest, CheckinTest) { +TEST_F(GCMStatsRecorderImplTest, CheckinTest) { recorder_.RecordCheckinInitiated(kAndroidId); VerifyRecordedCheckinCount(1); VerifyCheckinInitiated("1st call"); @@ -435,7 +435,7 @@ TEST_F(GCMStatsRecorderTest, CheckinTest) { VerifyCheckinFailure("4th call"); } -TEST_F(GCMStatsRecorderTest, ConnectionTest) { +TEST_F(GCMStatsRecorderImplTest, ConnectionTest) { recorder_.RecordConnectionInitiated(kHost); VerifyRecordedConnectionCount(1); VerifyConnectionInitiated("1st call"); @@ -457,7 +457,7 @@ TEST_F(GCMStatsRecorderTest, ConnectionTest) { VerifyConnectionResetSignaled("5th call"); } -TEST_F(GCMStatsRecorderTest, RegistrationTest) { +TEST_F(GCMStatsRecorderImplTest, RegistrationTest) { recorder_.RecordRegistrationSent(kAppId, kSenderIds); VerifyRecordedRegistrationCount(1); VerifyRegistrationSent("1st call"); @@ -484,7 +484,7 @@ TEST_F(GCMStatsRecorderTest, RegistrationTest) { VerifyUnregistrationRetryDelayed("6th call"); } -TEST_F(GCMStatsRecorderTest, RecordReceivingTest) { +TEST_F(GCMStatsRecorderImplTest, RecordReceivingTest) { recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true, GCMStatsRecorder::DATA_MESSAGE); VerifyRecordedReceivingCount(1); @@ -501,7 +501,7 @@ TEST_F(GCMStatsRecorderTest, RecordReceivingTest) { VerifyDataMessageReceivedNotRegistered("3rd call"); } -TEST_F(GCMStatsRecorderTest, RecordSendingTest) { +TEST_F(GCMStatsRecorderImplTest, RecordSendingTest) { recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); VerifyRecordedSendingCount(1); VerifyDataSentToWire("1st call"); |