Commit 025adfa4 authored by jianli@chromium.org's avatar jianli@chromium.org

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
parent 7fd6959f
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <vector> #include <vector>
#include "google_apis/gcm/engine/checkin_request.h" #include "google_apis/gcm/engine/checkin_request.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "google_apis/gcm/protocol/checkin.pb.h" #include "google_apis/gcm/protocol/checkin.pb.h"
#include "net/base/backoff_entry.h" #include "net/base/backoff_entry.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
...@@ -92,7 +92,7 @@ class CheckinRequestTest : public testing::Test { ...@@ -92,7 +92,7 @@ class CheckinRequestTest : public testing::Test {
checkin_proto::ChromeBuildProto chrome_build_proto_; checkin_proto::ChromeBuildProto chrome_build_proto_;
std::vector<std::string> account_ids_; std::vector<std::string> account_ids_;
scoped_ptr<CheckinRequest> request_; scoped_ptr<CheckinRequest> request_;
GCMStatsRecorder recorder_; FakeGCMStatsRecorder recorder_;
}; };
CheckinRequestTest::CheckinRequestTest() CheckinRequestTest::CheckinRequestTest()
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/test/simple_test_tick_clock.h" #include "base/test/simple_test_tick_clock.h"
#include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/base/mcs_util.h"
#include "google_apis/gcm/engine/fake_connection_handler.h" #include "google_apis/gcm/engine/fake_connection_handler.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "net/base/backoff_entry.h" #include "net/base/backoff_entry.h"
#include "net/http/http_network_session.h" #include "net/http/http_network_session.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -150,7 +150,7 @@ class TestConnectionFactoryImpl : public ConnectionFactoryImpl { ...@@ -150,7 +150,7 @@ class TestConnectionFactoryImpl : public ConnectionFactoryImpl {
base::Closure finished_callback_; base::Closure finished_callback_;
// The current fake connection handler.. // The current fake connection handler..
FakeConnectionHandler* fake_handler_; FakeConnectionHandler* fake_handler_;
GCMStatsRecorder dummy_recorder_; FakeGCMStatsRecorder dummy_recorder_;
}; };
TestConnectionFactoryImpl::TestConnectionFactoryImpl( TestConnectionFactoryImpl::TestConnectionFactoryImpl(
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "google_apis/gcm/engine/fake_connection_factory.h" #include "google_apis/gcm/engine/fake_connection_factory.h"
#include "google_apis/gcm/engine/fake_connection_handler.h" #include "google_apis/gcm/engine/fake_connection_handler.h"
#include "google_apis/gcm/engine/gcm_store_impl.h" #include "google_apis/gcm/engine/gcm_store_impl.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace gcm { namespace gcm {
...@@ -139,7 +139,7 @@ class MCSClientTest : public testing::Test { ...@@ -139,7 +139,7 @@ class MCSClientTest : public testing::Test {
std::string sent_message_id_; std::string sent_message_id_;
MCSClient::MessageSendStatus message_send_status_; MCSClient::MessageSendStatus message_send_status_;
gcm::GCMStatsRecorder recorder_; gcm::FakeGCMStatsRecorder recorder_;
}; };
MCSClientTest::MCSClientTest() MCSClientTest::MCSClientTest()
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h" #include "base/strings/string_tokenizer.h"
#include "google_apis/gcm/engine/registration_request.h" #include "google_apis/gcm/engine/registration_request.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
...@@ -82,7 +82,7 @@ class RegistrationRequestTest : public testing::Test { ...@@ -82,7 +82,7 @@ class RegistrationRequestTest : public testing::Test {
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
net::TestURLFetcherFactory url_fetcher_factory_; net::TestURLFetcherFactory url_fetcher_factory_;
scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
GCMStatsRecorder recorder_; FakeGCMStatsRecorder recorder_;
}; };
RegistrationRequestTest::RegistrationRequestTest() RegistrationRequestTest::RegistrationRequestTest()
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h" #include "base/strings/string_tokenizer.h"
#include "google_apis/gcm/engine/unregistration_request.h" #include "google_apis/gcm/engine/unregistration_request.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -73,7 +73,7 @@ class UnregistrationRequestTest : public testing::Test { ...@@ -73,7 +73,7 @@ class UnregistrationRequestTest : public testing::Test {
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
net::TestURLFetcherFactory url_fetcher_factory_; net::TestURLFetcherFactory url_fetcher_factory_;
scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
GCMStatsRecorder recorder_; FakeGCMStatsRecorder recorder_;
}; };
UnregistrationRequestTest::UnregistrationRequestTest() UnregistrationRequestTest::UnregistrationRequestTest()
......
...@@ -75,8 +75,9 @@ ...@@ -75,8 +75,9 @@
'gcm_client.h', 'gcm_client.h',
'gcm_client_impl.cc', 'gcm_client_impl.cc',
'gcm_client_impl.h', 'gcm_client_impl.h',
'monitoring/gcm_stats_recorder.cc',
'monitoring/gcm_stats_recorder.h', 'monitoring/gcm_stats_recorder.h',
'monitoring/gcm_stats_recorder_impl.cc',
'monitoring/gcm_stats_recorder_impl.h',
'protocol/android_checkin.proto', 'protocol/android_checkin.proto',
'protocol/checkin.proto', 'protocol/checkin.proto',
'protocol/mcs.proto', 'protocol/mcs.proto',
...@@ -86,6 +87,34 @@ ...@@ -86,6 +87,34 @@
], ],
}, },
# The test support library that is needed to test gcm.
{
'target_name': 'gcm_test_support',
'type': 'static_library',
'include_dirs': [
'..',
],
'export_dependent_settings': [
'../../third_party/protobuf/protobuf.gyp:protobuf_lite'
],
'dependencies': [
'../../base/base.gyp:base',
'../../testing/gtest.gyp:gtest',
'../../third_party/protobuf/protobuf.gyp:protobuf_lite',
'gcm',
],
'sources': [
'base/fake_encryptor.cc',
'base/fake_encryptor.h',
'engine/fake_connection_factory.cc',
'engine/fake_connection_factory.h',
'engine/fake_connection_handler.cc',
'engine/fake_connection_handler.h',
'monitoring/fake_gcm_stats_recorder.cc',
'monitoring/fake_gcm_stats_recorder.h',
],
},
# A standalone MCS (mobile connection server) client. # A standalone MCS (mobile connection server) client.
{ {
'target_name': 'mcs_probe', 'target_name': 'mcs_probe',
...@@ -99,11 +128,10 @@ ...@@ -99,11 +128,10 @@
'../../net/net.gyp:net', '../../net/net.gyp:net',
'../../net/net.gyp:net_test_support', '../../net/net.gyp:net_test_support',
'../../third_party/protobuf/protobuf.gyp:protobuf_lite', '../../third_party/protobuf/protobuf.gyp:protobuf_lite',
'gcm' 'gcm',
'gcm_test_support'
], ],
'sources': [ 'sources': [
'base/fake_encryptor.cc',
'base/fake_encryptor.h',
'tools/mcs_probe.cc', 'tools/mcs_probe.cc',
], ],
}, },
...@@ -127,21 +155,16 @@ ...@@ -127,21 +155,16 @@
'../../testing/gtest.gyp:gtest', '../../testing/gtest.gyp:gtest',
'../../third_party/protobuf/protobuf.gyp:protobuf_lite', '../../third_party/protobuf/protobuf.gyp:protobuf_lite',
'mcs_probe', 'mcs_probe',
'gcm' 'gcm',
'gcm_test_support'
], ],
'sources': [ 'sources': [
'base/fake_encryptor.cc',
'base/fake_encryptor.h',
'base/mcs_message_unittest.cc', 'base/mcs_message_unittest.cc',
'base/mcs_util_unittest.cc', 'base/mcs_util_unittest.cc',
'base/socket_stream_unittest.cc', 'base/socket_stream_unittest.cc',
'engine/checkin_request_unittest.cc', 'engine/checkin_request_unittest.cc',
'engine/connection_factory_impl_unittest.cc', 'engine/connection_factory_impl_unittest.cc',
'engine/connection_handler_impl_unittest.cc', 'engine/connection_handler_impl_unittest.cc',
'engine/fake_connection_factory.cc',
'engine/fake_connection_factory.h',
'engine/fake_connection_handler.cc',
'engine/fake_connection_handler.h',
'engine/gcm_store_impl_unittest.cc', 'engine/gcm_store_impl_unittest.cc',
'engine/gservices_settings_unittest.cc', 'engine/gservices_settings_unittest.cc',
'engine/heartbeat_manager_unittest.cc', 'engine/heartbeat_manager_unittest.cc',
...@@ -149,7 +172,7 @@ ...@@ -149,7 +172,7 @@
'engine/registration_request_unittest.cc', 'engine/registration_request_unittest.cc',
'engine/unregistration_request_unittest.cc', 'engine/unregistration_request_unittest.cc',
'gcm_client_impl_unittest.cc', 'gcm_client_impl_unittest.cc',
'monitoring/gcm_stats_recorder_unittest.cc' 'monitoring/gcm_stats_recorder_impl_unittest.cc'
] ]
}, },
], ],
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "google_apis/gcm/engine/registration_request.h" #include "google_apis/gcm/engine/registration_request.h"
#include "google_apis/gcm/engine/unregistration_request.h" #include "google_apis/gcm/engine/unregistration_request.h"
#include "google_apis/gcm/gcm_client.h" #include "google_apis/gcm/gcm_client.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/gcm_stats_recorder_impl.h"
#include "google_apis/gcm/protocol/android_checkin.pb.h" #include "google_apis/gcm/protocol/android_checkin.pb.h"
#include "google_apis/gcm/protocol/checkin.pb.h" #include "google_apis/gcm/protocol/checkin.pb.h"
#include "net/base/net_log.h" #include "net/base/net_log.h"
...@@ -233,7 +233,7 @@ class GCM_EXPORT GCMClientImpl ...@@ -233,7 +233,7 @@ class GCM_EXPORT GCMClientImpl
scoped_ptr<GCMInternalsBuilder> internals_builder_; scoped_ptr<GCMInternalsBuilder> internals_builder_;
// Recorder that logs GCM activities. // Recorder that logs GCM activities.
GCMStatsRecorder recorder_; GCMStatsRecorderImpl recorder_;
// State of the GCM Client Implementation. // State of the GCM Client Implementation.
State state_; State state_;
......
// 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
// 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_
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ #ifndef GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_
#define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ #define GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_
#include <deque>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -15,15 +14,11 @@ ...@@ -15,15 +14,11 @@
#include "google_apis/gcm/engine/mcs_client.h" #include "google_apis/gcm/engine/mcs_client.h"
#include "google_apis/gcm/engine/registration_request.h" #include "google_apis/gcm/engine/registration_request.h"
#include "google_apis/gcm/engine/unregistration_request.h" #include "google_apis/gcm/engine/unregistration_request.h"
#include "google_apis/gcm/gcm_activity.h"
namespace gcm { namespace gcm {
// Records GCM internal stats and activities for debugging purpose. Recording // Defines the interface to record GCM internal stats and activities for
// can be turned on/off by calling SetRecording(...) function. It is turned off // debugging purpose.
// by default.
// This class is not thread safe. It is meant to be owned by a gcm client
// instance.
class GCM_EXPORT GCMStatsRecorder { class GCM_EXPORT GCMStatsRecorder {
public: public:
// Type of a received message // Type of a received message
...@@ -34,181 +29,107 @@ class GCM_EXPORT GCMStatsRecorder { ...@@ -34,181 +29,107 @@ class GCM_EXPORT GCMStatsRecorder {
DELETED_MESSAGES, DELETED_MESSAGES,
}; };
// A delegate interface that allows the GCMStatsRecorder instance to interact // A delegate interface that allows the GCMStatsRecorderImpl instance to
// with its container. // interact with its container.
class Delegate { class Delegate {
public: public:
// Called when the GCMStatsRecorder is recording activities and a new // Called when the GCMStatsRecorderImpl is recording activities and a new
// activity has just been recorded. // activity has just been recorded.
virtual void OnActivityRecorded() = 0; virtual void OnActivityRecorded() = 0;
}; };
GCMStatsRecorder(); GCMStatsRecorder() {}
virtual ~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.
// Records that a check-in has been initiated. // 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. // 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. // 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 // Records that a check-in request has failed. If a retry will be tempted then
// will_retry should be true. // 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. // 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. // 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. // Records that connection has been successfully established.
void RecordConnectionSuccess(); virtual void RecordConnectionSuccess() = 0;
// Records that connection has failed with a network error code. // 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. // Records that connection reset has been signaled.
void RecordConnectionResetSignaled( virtual void RecordConnectionResetSignaled(
ConnectionFactory::ConnectionResetReason reason); ConnectionFactory::ConnectionResetReason reason) = 0;
// Records that a registration request has been sent. This could be initiated // Records that a registration request has been sent. This could be initiated
// directly from API, or from retry logic. // directly from API, or from retry logic.
void RecordRegistrationSent(const std::string& app_id, virtual void RecordRegistrationSent(const std::string& app_id,
const std::string& sender_ids); const std::string& sender_ids) = 0;
// Records that a registration response has been received from server. // Records that a registration response has been received from server.
void RecordRegistrationResponse(const std::string& app_id, virtual void RecordRegistrationResponse(
const std::string& app_id,
const std::vector<std::string>& sender_ids, const std::vector<std::string>& sender_ids,
RegistrationRequest::Status status); RegistrationRequest::Status status) = 0;
// Records that a registration retry has been requested. The actual retry // Records that a registration retry has been requested. The actual retry
// action may not occur until some time later according to backoff logic. // action may not occur until some time later according to backoff logic.
void RecordRegistrationRetryRequested( virtual void RecordRegistrationRetryRequested(
const std::string& app_id, const std::string& app_id,
const std::vector<std::string>& sender_ids, 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 // Records that an unregistration request has been sent. This could be
// initiated directly from API, or from retry logic. // 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. // Records that an unregistration response has been received from server.
void RecordUnregistrationResponse(const std::string& app_id, virtual void RecordUnregistrationResponse(
UnregistrationRequest::Status status); const std::string& app_id,
UnregistrationRequest::Status status) = 0;
// Records that an unregistration retry has been requested and delayed due to // Records that an unregistration retry has been requested and delayed due to
// backoff logic. // backoff logic.
void RecordUnregistrationRetryDelayed(const std::string& app_id, virtual void RecordUnregistrationRetryDelayed(const std::string& app_id,
int64 delay_msec); int64 delay_msec) = 0;
// Records that a data message has been received. If this message is not // 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 // 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 // indicates that a message has been dropped on the server, is_message_dropped
// should be true. // should be true.
void RecordDataMessageReceived(const std::string& app_id, virtual void RecordDataMessageReceived(const std::string& app_id,
const std::string& from, const std::string& from,
int message_byte_size, int message_byte_size,
bool to_registered_app, bool to_registered_app,
ReceivedMessageType message_type); ReceivedMessageType message_type) = 0;
// Records that an outgoing data message was sent over the wire. // Records that an outgoing data message was sent over the wire.
void RecordDataSentToWire(const std::string& app_id, virtual void RecordDataSentToWire(const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id, const std::string& message_id,
int queued); int queued) = 0;
// Records that the MCS client sent a 'send status' notification to callback. // Records that the MCS client sent a 'send status' notification to callback.
void RecordNotifySendStatus(const std::string& app_id, virtual void RecordNotifySendStatus(const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id, const std::string& message_id,
MCSClient::MessageSendStatus status, MCSClient::MessageSendStatus status,
int byte_size, int byte_size,
int ttl); int ttl) = 0;
// Records that a 'send error' message was received. // Records that a 'send error' message was received.
void RecordIncomingSendError(const std::string& app_id, virtual void RecordIncomingSendError(const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id); const std::string& message_id) = 0;
// 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);
}; };
} // namespace gcm } // namespace gcm
#endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ #endif // GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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 <deque>
#include <vector> #include <vector>
...@@ -140,21 +140,23 @@ std::string GetUnregistrationStatusString( ...@@ -140,21 +140,23 @@ std::string GetUnregistrationStatusString(
} // namespace } // 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; is_recording_ = recording;
} }
void GCMStatsRecorder::SetDelegate(Delegate* delegate) { void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
} }
void GCMStatsRecorder::Clear() { void GCMStatsRecorderImpl::Clear() {
checkin_activities_.clear(); checkin_activities_.clear();
connection_activities_.clear(); connection_activities_.clear();
registration_activities_.clear(); registration_activities_.clear();
...@@ -162,12 +164,12 @@ void GCMStatsRecorder::Clear() { ...@@ -162,12 +164,12 @@ void GCMStatsRecorder::Clear() {
sending_activities_.clear(); sending_activities_.clear();
} }
void GCMStatsRecorder::NotifyActivityRecorded() { void GCMStatsRecorderImpl::NotifyActivityRecorded() {
if (delegate_) if (delegate_)
delegate_->OnActivityRecorded(); delegate_->OnActivityRecorded();
} }
void GCMStatsRecorder::RecordCheckin( void GCMStatsRecorderImpl::RecordCheckin(
const std::string& event, const std::string& event,
const std::string& details) { const std::string& details) {
CheckinActivity data; CheckinActivity data;
...@@ -178,14 +180,14 @@ void GCMStatsRecorder::RecordCheckin( ...@@ -178,14 +180,14 @@ void GCMStatsRecorder::RecordCheckin(
NotifyActivityRecorded(); NotifyActivityRecorded();
} }
void GCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) { void GCMStatsRecorderImpl::RecordCheckinInitiated(uint64 android_id) {
if (!is_recording_) if (!is_recording_)
return; return;
RecordCheckin("Checkin initiated", RecordCheckin("Checkin initiated",
base::StringPrintf("Android Id: %" PRIu64, android_id)); base::StringPrintf("Android Id: %" PRIu64, android_id));
} }
void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { void GCMStatsRecorderImpl::RecordCheckinDelayedDueToBackoff(int64 delay_msec) {
if (!is_recording_) if (!is_recording_)
return; return;
RecordCheckin("Checkin backoff", RecordCheckin("Checkin backoff",
...@@ -193,13 +195,13 @@ void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { ...@@ -193,13 +195,13 @@ void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) {
delay_msec)); delay_msec));
} }
void GCMStatsRecorder::RecordCheckinSuccess() { void GCMStatsRecorderImpl::RecordCheckinSuccess() {
if (!is_recording_) if (!is_recording_)
return; return;
RecordCheckin("Checkin succeeded", std::string()); RecordCheckin("Checkin succeeded", std::string());
} }
void GCMStatsRecorder::RecordCheckinFailure(std::string status, void GCMStatsRecorderImpl::RecordCheckinFailure(std::string status,
bool will_retry) { bool will_retry) {
if (!is_recording_) if (!is_recording_)
return; return;
...@@ -209,7 +211,7 @@ void GCMStatsRecorder::RecordCheckinFailure(std::string status, ...@@ -209,7 +211,7 @@ void GCMStatsRecorder::RecordCheckinFailure(std::string status,
will_retry ? " Will retry." : "Will not retry.")); will_retry ? " Will retry." : "Will not retry."));
} }
void GCMStatsRecorder::RecordConnection( void GCMStatsRecorderImpl::RecordConnection(
const std::string& event, const std::string& event,
const std::string& details) { const std::string& details) {
ConnectionActivity data; ConnectionActivity data;
...@@ -220,13 +222,14 @@ void GCMStatsRecorder::RecordConnection( ...@@ -220,13 +222,14 @@ void GCMStatsRecorder::RecordConnection(
NotifyActivityRecorded(); NotifyActivityRecorded();
} }
void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) { void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) {
if (!is_recording_) if (!is_recording_)
return; return;
RecordConnection("Connection initiated", host); RecordConnection("Connection initiated", host);
} }
void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff(
int64 delay_msec) {
if (!is_recording_) if (!is_recording_)
return; return;
RecordConnection("Connection backoff", RecordConnection("Connection backoff",
...@@ -234,20 +237,20 @@ void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { ...@@ -234,20 +237,20 @@ void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) {
delay_msec)); delay_msec));
} }
void GCMStatsRecorder::RecordConnectionSuccess() { void GCMStatsRecorderImpl::RecordConnectionSuccess() {
if (!is_recording_) if (!is_recording_)
return; return;
RecordConnection("Connection succeeded", std::string()); RecordConnection("Connection succeeded", std::string());
} }
void GCMStatsRecorder::RecordConnectionFailure(int network_error) { void GCMStatsRecorderImpl::RecordConnectionFailure(int network_error) {
if (!is_recording_) if (!is_recording_)
return; return;
RecordConnection("Connection failed", RecordConnection("Connection failed",
base::StringPrintf("With network error %d", network_error)); base::StringPrintf("With network error %d", network_error));
} }
void GCMStatsRecorder::RecordConnectionResetSignaled( void GCMStatsRecorderImpl::RecordConnectionResetSignaled(
ConnectionFactory::ConnectionResetReason reason) { ConnectionFactory::ConnectionResetReason reason) {
if (!is_recording_) if (!is_recording_)
return; return;
...@@ -255,7 +258,7 @@ void GCMStatsRecorder::RecordConnectionResetSignaled( ...@@ -255,7 +258,7 @@ void GCMStatsRecorder::RecordConnectionResetSignaled(
GetConnectionResetReasonString(reason)); GetConnectionResetReasonString(reason));
} }
void GCMStatsRecorder::RecordRegistration( void GCMStatsRecorderImpl::RecordRegistration(
const std::string& app_id, const std::string& app_id,
const std::string& sender_ids, const std::string& sender_ids,
const std::string& event, const std::string& event,
...@@ -270,7 +273,7 @@ void GCMStatsRecorder::RecordRegistration( ...@@ -270,7 +273,7 @@ void GCMStatsRecorder::RecordRegistration(
NotifyActivityRecorded(); NotifyActivityRecorded();
} }
void GCMStatsRecorder::RecordRegistrationSent( void GCMStatsRecorderImpl::RecordRegistrationSent(
const std::string& app_id, const std::string& app_id,
const std::string& sender_ids) { const std::string& sender_ids) {
UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1);
...@@ -280,7 +283,7 @@ void GCMStatsRecorder::RecordRegistrationSent( ...@@ -280,7 +283,7 @@ void GCMStatsRecorder::RecordRegistrationSent(
"Registration request sent", std::string()); "Registration request sent", std::string());
} }
void GCMStatsRecorder::RecordRegistrationResponse( void GCMStatsRecorderImpl::RecordRegistrationResponse(
const std::string& app_id, const std::string& app_id,
const std::vector<std::string>& sender_ids, const std::vector<std::string>& sender_ids,
RegistrationRequest::Status status) { RegistrationRequest::Status status) {
...@@ -291,7 +294,7 @@ void GCMStatsRecorder::RecordRegistrationResponse( ...@@ -291,7 +294,7 @@ void GCMStatsRecorder::RecordRegistrationResponse(
GetRegistrationStatusString(status)); GetRegistrationStatusString(status));
} }
void GCMStatsRecorder::RecordRegistrationRetryRequested( void GCMStatsRecorderImpl::RecordRegistrationRetryRequested(
const std::string& app_id, const std::string& app_id,
const std::vector<std::string>& sender_ids, const std::vector<std::string>& sender_ids,
int retries_left) { int retries_left) {
...@@ -302,7 +305,7 @@ void GCMStatsRecorder::RecordRegistrationRetryRequested( ...@@ -302,7 +305,7 @@ void GCMStatsRecorder::RecordRegistrationRetryRequested(
base::StringPrintf("Retries left: %d", retries_left)); base::StringPrintf("Retries left: %d", retries_left));
} }
void GCMStatsRecorder::RecordUnregistrationSent( void GCMStatsRecorderImpl::RecordUnregistrationSent(
const std::string& app_id) { const std::string& app_id) {
UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1); UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1);
if (!is_recording_) if (!is_recording_)
...@@ -311,7 +314,7 @@ void GCMStatsRecorder::RecordUnregistrationSent( ...@@ -311,7 +314,7 @@ void GCMStatsRecorder::RecordUnregistrationSent(
std::string()); std::string());
} }
void GCMStatsRecorder::RecordUnregistrationResponse( void GCMStatsRecorderImpl::RecordUnregistrationResponse(
const std::string& app_id, const std::string& app_id,
UnregistrationRequest::Status status) { UnregistrationRequest::Status status) {
if (!is_recording_) if (!is_recording_)
...@@ -322,7 +325,7 @@ void GCMStatsRecorder::RecordUnregistrationResponse( ...@@ -322,7 +325,7 @@ void GCMStatsRecorder::RecordUnregistrationResponse(
GetUnregistrationStatusString(status)); GetUnregistrationStatusString(status));
} }
void GCMStatsRecorder::RecordUnregistrationRetryDelayed( void GCMStatsRecorderImpl::RecordUnregistrationRetryDelayed(
const std::string& app_id, const std::string& app_id,
int64 delay_msec) { int64 delay_msec) {
if (!is_recording_) if (!is_recording_)
...@@ -334,7 +337,7 @@ void GCMStatsRecorder::RecordUnregistrationRetryDelayed( ...@@ -334,7 +337,7 @@ void GCMStatsRecorder::RecordUnregistrationRetryDelayed(
delay_msec)); delay_msec));
} }
void GCMStatsRecorder::RecordReceiving( void GCMStatsRecorderImpl::RecordReceiving(
const std::string& app_id, const std::string& app_id,
const std::string& from, const std::string& from,
int message_byte_size, int message_byte_size,
...@@ -351,7 +354,7 @@ void GCMStatsRecorder::RecordReceiving( ...@@ -351,7 +354,7 @@ void GCMStatsRecorder::RecordReceiving(
NotifyActivityRecorded(); NotifyActivityRecorded();
} }
void GCMStatsRecorder::RecordDataMessageReceived( void GCMStatsRecorderImpl::RecordDataMessageReceived(
const std::string& app_id, const std::string& app_id,
const std::string& from, const std::string& from,
int message_byte_size, int message_byte_size,
...@@ -367,11 +370,11 @@ void GCMStatsRecorder::RecordDataMessageReceived( ...@@ -367,11 +370,11 @@ void GCMStatsRecorder::RecordDataMessageReceived(
"No such registered app found"); "No such registered app found");
} else { } else {
switch(message_type) { switch(message_type) {
case GCMStatsRecorder::DATA_MESSAGE: case GCMStatsRecorderImpl::DATA_MESSAGE:
RecordReceiving(app_id, from, message_byte_size, "Data msg received", RecordReceiving(app_id, from, message_byte_size, "Data msg received",
std::string()); std::string());
break; break;
case GCMStatsRecorder::DELETED_MESSAGES: case GCMStatsRecorderImpl::DELETED_MESSAGES:
RecordReceiving(app_id, from, message_byte_size, "Data msg received", RecordReceiving(app_id, from, message_byte_size, "Data msg received",
"Message has been deleted on server"); "Message has been deleted on server");
break; break;
...@@ -381,7 +384,7 @@ void GCMStatsRecorder::RecordDataMessageReceived( ...@@ -381,7 +384,7 @@ void GCMStatsRecorder::RecordDataMessageReceived(
} }
} }
void GCMStatsRecorder::CollectActivities( void GCMStatsRecorderImpl::CollectActivities(
RecordedActivities* recorder_activities) const { RecordedActivities* recorder_activities) const {
recorder_activities->checkin_activities.insert( recorder_activities->checkin_activities.insert(
recorder_activities->checkin_activities.begin(), recorder_activities->checkin_activities.begin(),
...@@ -405,7 +408,7 @@ void GCMStatsRecorder::CollectActivities( ...@@ -405,7 +408,7 @@ void GCMStatsRecorder::CollectActivities(
sending_activities_.end()); sending_activities_.end());
} }
void GCMStatsRecorder::RecordSending(const std::string& app_id, void GCMStatsRecorderImpl::RecordSending(const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id, const std::string& message_id,
const std::string& event, const std::string& event,
...@@ -421,7 +424,7 @@ void GCMStatsRecorder::RecordSending(const std::string& app_id, ...@@ -421,7 +424,7 @@ void GCMStatsRecorder::RecordSending(const std::string& app_id,
NotifyActivityRecorded(); NotifyActivityRecorded();
} }
void GCMStatsRecorder::RecordDataSentToWire( void GCMStatsRecorderImpl::RecordDataSentToWire(
const std::string& app_id, const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id, const std::string& message_id,
...@@ -432,7 +435,7 @@ void GCMStatsRecorder::RecordDataSentToWire( ...@@ -432,7 +435,7 @@ void GCMStatsRecorder::RecordDataSentToWire(
base::StringPrintf("Msg queued for %d seconds", queued)); base::StringPrintf("Msg queued for %d seconds", queued));
} }
void GCMStatsRecorder::RecordNotifySendStatus( void GCMStatsRecorderImpl::RecordNotifySendStatus(
const std::string& app_id, const std::string& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id, const std::string& message_id,
...@@ -452,7 +455,7 @@ void GCMStatsRecorder::RecordNotifySendStatus( ...@@ -452,7 +455,7 @@ void GCMStatsRecorder::RecordNotifySendStatus(
base::StringPrintf("Msg size: %d bytes, TTL: %d", byte_size, ttl)); 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& app_id,
const std::string& receiver_id, const std::string& receiver_id,
const std::string& message_id) { const std::string& message_id) {
......
// 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_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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 <deque>
#include <string> #include <string>
...@@ -97,10 +97,10 @@ static const char kIncomingSendErrorDetails[] = ""; ...@@ -97,10 +97,10 @@ static const char kIncomingSendErrorDetails[] = "";
} // namespace } // namespace
class GCMStatsRecorderTest : public testing::Test { class GCMStatsRecorderImplTest : public testing::Test {
public: public:
GCMStatsRecorderTest(); GCMStatsRecorderImplTest();
virtual ~GCMStatsRecorderTest(); virtual ~GCMStatsRecorderImplTest();
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
void VerifyRecordedCheckinCount(int expected_count) { void VerifyRecordedCheckinCount(int expected_count) {
...@@ -339,21 +339,21 @@ class GCMStatsRecorderTest : public testing::Test { ...@@ -339,21 +339,21 @@ class GCMStatsRecorderTest : public testing::Test {
} }
std::vector<std::string> sender_ids_; 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("s1");
sender_ids_.push_back("s2"); sender_ids_.push_back("s2");
recorder_.SetRecording(true); recorder_.SetRecording(true);
} }
TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) { TEST_F(GCMStatsRecorderImplTest, StartStopRecordingTest) {
EXPECT_TRUE(recorder_.is_recording()); EXPECT_TRUE(recorder_.is_recording());
recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
VerifyRecordedSendingCount(1); VerifyRecordedSendingCount(1);
...@@ -403,7 +403,7 @@ TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) { ...@@ -403,7 +403,7 @@ TEST_F(GCMStatsRecorderTest, StartStopRecordingTest) {
VerifyAllActivityQueueEmpty("no sending"); VerifyAllActivityQueueEmpty("no sending");
} }
TEST_F(GCMStatsRecorderTest, ClearLogTest) { TEST_F(GCMStatsRecorderImplTest, ClearLogTest) {
recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
VerifyRecordedSendingCount(1); VerifyRecordedSendingCount(1);
VerifyDataSentToWire("1st call"); VerifyDataSentToWire("1st call");
...@@ -417,7 +417,7 @@ TEST_F(GCMStatsRecorderTest, ClearLogTest) { ...@@ -417,7 +417,7 @@ TEST_F(GCMStatsRecorderTest, ClearLogTest) {
VerifyRecordedSendingCount(0); VerifyRecordedSendingCount(0);
} }
TEST_F(GCMStatsRecorderTest, CheckinTest) { TEST_F(GCMStatsRecorderImplTest, CheckinTest) {
recorder_.RecordCheckinInitiated(kAndroidId); recorder_.RecordCheckinInitiated(kAndroidId);
VerifyRecordedCheckinCount(1); VerifyRecordedCheckinCount(1);
VerifyCheckinInitiated("1st call"); VerifyCheckinInitiated("1st call");
...@@ -435,7 +435,7 @@ TEST_F(GCMStatsRecorderTest, CheckinTest) { ...@@ -435,7 +435,7 @@ TEST_F(GCMStatsRecorderTest, CheckinTest) {
VerifyCheckinFailure("4th call"); VerifyCheckinFailure("4th call");
} }
TEST_F(GCMStatsRecorderTest, ConnectionTest) { TEST_F(GCMStatsRecorderImplTest, ConnectionTest) {
recorder_.RecordConnectionInitiated(kHost); recorder_.RecordConnectionInitiated(kHost);
VerifyRecordedConnectionCount(1); VerifyRecordedConnectionCount(1);
VerifyConnectionInitiated("1st call"); VerifyConnectionInitiated("1st call");
...@@ -457,7 +457,7 @@ TEST_F(GCMStatsRecorderTest, ConnectionTest) { ...@@ -457,7 +457,7 @@ TEST_F(GCMStatsRecorderTest, ConnectionTest) {
VerifyConnectionResetSignaled("5th call"); VerifyConnectionResetSignaled("5th call");
} }
TEST_F(GCMStatsRecorderTest, RegistrationTest) { TEST_F(GCMStatsRecorderImplTest, RegistrationTest) {
recorder_.RecordRegistrationSent(kAppId, kSenderIds); recorder_.RecordRegistrationSent(kAppId, kSenderIds);
VerifyRecordedRegistrationCount(1); VerifyRecordedRegistrationCount(1);
VerifyRegistrationSent("1st call"); VerifyRegistrationSent("1st call");
...@@ -484,7 +484,7 @@ TEST_F(GCMStatsRecorderTest, RegistrationTest) { ...@@ -484,7 +484,7 @@ TEST_F(GCMStatsRecorderTest, RegistrationTest) {
VerifyUnregistrationRetryDelayed("6th call"); VerifyUnregistrationRetryDelayed("6th call");
} }
TEST_F(GCMStatsRecorderTest, RecordReceivingTest) { TEST_F(GCMStatsRecorderImplTest, RecordReceivingTest) {
recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true, recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true,
GCMStatsRecorder::DATA_MESSAGE); GCMStatsRecorder::DATA_MESSAGE);
VerifyRecordedReceivingCount(1); VerifyRecordedReceivingCount(1);
...@@ -501,7 +501,7 @@ TEST_F(GCMStatsRecorderTest, RecordReceivingTest) { ...@@ -501,7 +501,7 @@ TEST_F(GCMStatsRecorderTest, RecordReceivingTest) {
VerifyDataMessageReceivedNotRegistered("3rd call"); VerifyDataMessageReceivedNotRegistered("3rd call");
} }
TEST_F(GCMStatsRecorderTest, RecordSendingTest) { TEST_F(GCMStatsRecorderImplTest, RecordSendingTest) {
recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec); recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
VerifyRecordedSendingCount(1); VerifyRecordedSendingCount(1);
VerifyDataSentToWire("1st call"); VerifyDataSentToWire("1st call");
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "google_apis/gcm/engine/gcm_store_impl.h" #include "google_apis/gcm/engine/gcm_store_impl.h"
#include "google_apis/gcm/engine/gservices_settings.h" #include "google_apis/gcm/engine/gservices_settings.h"
#include "google_apis/gcm/engine/mcs_client.h" #include "google_apis/gcm/engine/mcs_client.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
#include "net/base/host_mapping_rules.h" #include "net/base/host_mapping_rules.h"
#include "net/base/net_log_logger.h" #include "net/base/net_log_logger.h"
#include "net/cert/cert_verifier.h" #include "net/cert/cert_verifier.h"
...@@ -243,7 +243,7 @@ class MCSProbe { ...@@ -243,7 +243,7 @@ class MCSProbe {
scoped_refptr<net::HttpNetworkSession> network_session_; scoped_refptr<net::HttpNetworkSession> network_session_;
scoped_ptr<net::ProxyService> proxy_service_; scoped_ptr<net::ProxyService> proxy_service_;
GCMStatsRecorder recorder_; FakeGCMStatsRecorder recorder_;
scoped_ptr<GCMStore> gcm_store_; scoped_ptr<GCMStore> gcm_store_;
scoped_ptr<MCSClient> mcs_client_; scoped_ptr<MCSClient> mcs_client_;
scoped_ptr<CheckinRequest> checkin_request_; scoped_ptr<CheckinRequest> checkin_request_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment