summaryrefslogtreecommitdiffstats
path: root/google_apis/gcm/monitoring
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-09 17:13:06 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-09 17:13:06 +0000
commitcd57f378f4658d100bee327fc2152815a0a0e178 (patch)
treeb3d6811257f05368c787a252dedeac6e866cab91 /google_apis/gcm/monitoring
parent7d3c069e49e2cd35eea5cc6f94ba889ecb29d878 (diff)
downloadchromium_src-cd57f378f4658d100bee327fc2152815a0a0e178.zip
chromium_src-cd57f378f4658d100bee327fc2152815a0a0e178.tar.gz
chromium_src-cd57f378f4658d100bee327fc2152815a0a0e178.tar.bz2
Move GCMClient related files to gcm_driver component
GCMActivity, GCMClient, GCMClientImpl and GCMStatsRecorderImpl have been moved to gcm_driver component. This allows us to remove the dependency on google_apis/gcm for Android GCM support. BUG=353786,356716 TEST=existing tests due to no functionality change R=fgorski@chromium.org, zea@chromium.org TBR=arv@chromium.org, kalman@chromium.org, pavely@chromium.org Review URL: https://codereview.chromium.org/310973002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gcm/monitoring')
-rw-r--r--google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc469
-rw-r--r--google_apis/gcm/monitoring/gcm_stats_recorder_impl.h156
-rw-r--r--google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc523
3 files changed, 0 insertions, 1148 deletions
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc
deleted file mode 100644
index 8786d51..0000000
--- a/google_apis/gcm/monitoring/gcm_stats_recorder_impl.cc
+++ /dev/null
@@ -1,469 +0,0 @@
-// 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/gcm_stats_recorder_impl.h"
-
-#include <deque>
-#include <vector>
-
-#include "base/format_macros.h"
-#include "base/logging.h"
-#include "base/metrics/histogram.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-
-namespace gcm {
-
-const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100;
-
-namespace {
-
-// Insert an item to the front of deque while maintaining the size of the deque.
-// Overflow item is discarded.
-template <typename T>
-T* InsertCircularBuffer(std::deque<T>* q, const T& item) {
- DCHECK(q);
- q->push_front(item);
- if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) {
- q->pop_back();
- }
- return &q->front();
-}
-
-// Helper for getting string representation of the MessageSendStatus enum.
-std::string GetMessageSendStatusString(
- gcm::MCSClient::MessageSendStatus status) {
- switch (status) {
- case gcm::MCSClient::QUEUED:
- return "QUEUED";
- case gcm::MCSClient::SENT:
- return "SENT";
- case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED:
- return "QUEUE_SIZE_LIMIT_REACHED";
- case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
- return "APP_QUEUE_SIZE_LIMIT_REACHED";
- case gcm::MCSClient::MESSAGE_TOO_LARGE:
- return "MESSAGE_TOO_LARGE";
- case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL:
- return "NO_CONNECTION_ON_ZERO_TTL";
- case gcm::MCSClient::TTL_EXCEEDED:
- return "TTL_EXCEEDED";
- default:
- NOTREACHED();
- return "UNKNOWN";
- }
-}
-
-// Helper for getting string representation of the
-// ConnectionFactory::ConnectionResetReason enum.
-std::string GetConnectionResetReasonString(
- gcm::ConnectionFactory::ConnectionResetReason reason) {
- switch (reason) {
- case gcm::ConnectionFactory::LOGIN_FAILURE:
- return "LOGIN_FAILURE";
- case gcm::ConnectionFactory::CLOSE_COMMAND:
- return "CLOSE_COMMAND";
- case gcm::ConnectionFactory::HEARTBEAT_FAILURE:
- return "HEARTBEAT_FAILURE";
- case gcm::ConnectionFactory::SOCKET_FAILURE:
- return "SOCKET_FAILURE";
- case gcm::ConnectionFactory::NETWORK_CHANGE:
- return "NETWORK_CHANGE";
- default:
- NOTREACHED();
- return "UNKNOWN_REASON";
- }
-}
-
-// Helper for getting string representation of the RegistrationRequest::Status
-// enum.
-std::string GetRegistrationStatusString(
- gcm::RegistrationRequest::Status status) {
- switch (status) {
- case gcm::RegistrationRequest::SUCCESS:
- return "SUCCESS";
- case gcm::RegistrationRequest::INVALID_PARAMETERS:
- return "INVALID_PARAMETERS";
- case gcm::RegistrationRequest::INVALID_SENDER:
- return "INVALID_SENDER";
- case gcm::RegistrationRequest::AUTHENTICATION_FAILED:
- return "AUTHENTICATION_FAILED";
- case gcm::RegistrationRequest::DEVICE_REGISTRATION_ERROR:
- return "DEVICE_REGISTRATION_ERROR";
- case gcm::RegistrationRequest::UNKNOWN_ERROR:
- return "UNKNOWN_ERROR";
- case gcm::RegistrationRequest::URL_FETCHING_FAILED:
- return "URL_FETCHING_FAILED";
- case gcm::RegistrationRequest::HTTP_NOT_OK:
- return "HTTP_NOT_OK";
- case gcm::RegistrationRequest::RESPONSE_PARSING_FAILED:
- return "RESPONSE_PARSING_FAILED";
- case gcm::RegistrationRequest::REACHED_MAX_RETRIES:
- return "REACHED_MAX_RETRIES";
- default:
- NOTREACHED();
- return "UNKNOWN_STATUS";
- }
-}
-
-// Helper for getting string representation of the RegistrationRequest::Status
-// enum.
-std::string GetUnregistrationStatusString(
- gcm::UnregistrationRequest::Status status) {
- switch (status) {
- case gcm::UnregistrationRequest::SUCCESS:
- return "SUCCESS";
- case gcm::UnregistrationRequest::URL_FETCHING_FAILED:
- return "URL_FETCHING_FAILED";
- case gcm::UnregistrationRequest::NO_RESPONSE_BODY:
- return "NO_RESPONSE_BODY";
- case gcm::UnregistrationRequest::RESPONSE_PARSING_FAILED:
- return "RESPONSE_PARSING_FAILED";
- case gcm::UnregistrationRequest::INCORRECT_APP_ID:
- return "INCORRECT_APP_ID";
- case gcm::UnregistrationRequest::INVALID_PARAMETERS:
- return "INVALID_PARAMETERS";
- case gcm::UnregistrationRequest::SERVICE_UNAVAILABLE:
- return "SERVICE_UNAVAILABLE";
- case gcm::UnregistrationRequest::INTERNAL_SERVER_ERROR:
- return "INTERNAL_SERVER_ERROR";
- case gcm::UnregistrationRequest::HTTP_NOT_OK:
- return "HTTP_NOT_OK";
- case gcm::UnregistrationRequest::UNKNOWN_ERROR:
- return "UNKNOWN_ERROR";
- default:
- NOTREACHED();
- return "UNKNOWN_STATUS";
- }
-}
-
-} // namespace
-
-GCMStatsRecorderImpl::GCMStatsRecorderImpl()
- : is_recording_(false),
- delegate_(NULL) {
-}
-
-GCMStatsRecorderImpl::~GCMStatsRecorderImpl() {
-}
-
-void GCMStatsRecorderImpl::SetRecording(bool recording) {
- is_recording_ = recording;
-}
-
-void GCMStatsRecorderImpl::SetDelegate(Delegate* delegate) {
- delegate_ = delegate;
-}
-
-void GCMStatsRecorderImpl::Clear() {
- checkin_activities_.clear();
- connection_activities_.clear();
- registration_activities_.clear();
- receiving_activities_.clear();
- sending_activities_.clear();
-}
-
-void GCMStatsRecorderImpl::NotifyActivityRecorded() {
- if (delegate_)
- delegate_->OnActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordCheckin(
- const std::string& event,
- const std::string& details) {
- CheckinActivity data;
- CheckinActivity* inserted_data = InsertCircularBuffer(
- &checkin_activities_, data);
- inserted_data->event = event;
- inserted_data->details = details;
- NotifyActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordCheckinInitiated(uint64 android_id) {
- if (!is_recording_)
- return;
- RecordCheckin("Checkin initiated",
- base::StringPrintf("Android Id: %" PRIu64, android_id));
-}
-
-void GCMStatsRecorderImpl::RecordCheckinDelayedDueToBackoff(int64 delay_msec) {
- if (!is_recording_)
- return;
- RecordCheckin("Checkin backoff",
- base::StringPrintf("Delayed for %" PRId64 " msec",
- delay_msec));
-}
-
-void GCMStatsRecorderImpl::RecordCheckinSuccess() {
- if (!is_recording_)
- return;
- RecordCheckin("Checkin succeeded", std::string());
-}
-
-void GCMStatsRecorderImpl::RecordCheckinFailure(std::string status,
- bool will_retry) {
- if (!is_recording_)
- return;
- RecordCheckin("Checkin failed", base::StringPrintf(
- "%s.%s",
- status.c_str(),
- will_retry ? " Will retry." : "Will not retry."));
-}
-
-void GCMStatsRecorderImpl::RecordConnection(
- const std::string& event,
- const std::string& details) {
- ConnectionActivity data;
- ConnectionActivity* inserted_data = InsertCircularBuffer(
- &connection_activities_, data);
- inserted_data->event = event;
- inserted_data->details = details;
- NotifyActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) {
- if (!is_recording_)
- return;
- RecordConnection("Connection initiated", host);
-}
-
-void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff(
- int64 delay_msec) {
- if (!is_recording_)
- return;
- RecordConnection("Connection backoff",
- base::StringPrintf("Delayed for %" PRId64 " msec",
- delay_msec));
-}
-
-void GCMStatsRecorderImpl::RecordConnectionSuccess() {
- if (!is_recording_)
- return;
- RecordConnection("Connection succeeded", std::string());
-}
-
-void GCMStatsRecorderImpl::RecordConnectionFailure(int network_error) {
- if (!is_recording_)
- return;
- RecordConnection("Connection failed",
- base::StringPrintf("With network error %d", network_error));
-}
-
-void GCMStatsRecorderImpl::RecordConnectionResetSignaled(
- ConnectionFactory::ConnectionResetReason reason) {
- if (!is_recording_)
- return;
- RecordConnection("Connection reset",
- GetConnectionResetReasonString(reason));
-}
-
-void GCMStatsRecorderImpl::RecordRegistration(
- const std::string& app_id,
- const std::string& sender_ids,
- const std::string& event,
- const std::string& details) {
- RegistrationActivity data;
- RegistrationActivity* inserted_data = InsertCircularBuffer(
- &registration_activities_, data);
- inserted_data->app_id = app_id;
- inserted_data->sender_ids = sender_ids;
- inserted_data->event = event;
- inserted_data->details = details;
- NotifyActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordRegistrationSent(
- const std::string& app_id,
- const std::string& sender_ids) {
- UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1);
- if (!is_recording_)
- return;
- RecordRegistration(app_id, sender_ids,
- "Registration request sent", std::string());
-}
-
-void GCMStatsRecorderImpl::RecordRegistrationResponse(
- const std::string& app_id,
- const std::vector<std::string>& sender_ids,
- RegistrationRequest::Status status) {
- if (!is_recording_)
- return;
- RecordRegistration(app_id, JoinString(sender_ids, ","),
- "Registration response received",
- GetRegistrationStatusString(status));
-}
-
-void GCMStatsRecorderImpl::RecordRegistrationRetryRequested(
- const std::string& app_id,
- const std::vector<std::string>& sender_ids,
- int retries_left) {
- if (!is_recording_)
- return;
- RecordRegistration(app_id, JoinString(sender_ids, ","),
- "Registration retry requested",
- base::StringPrintf("Retries left: %d", retries_left));
-}
-
-void GCMStatsRecorderImpl::RecordUnregistrationSent(
- const std::string& app_id) {
- UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1);
- if (!is_recording_)
- return;
- RecordRegistration(app_id, std::string(), "Unregistration request sent",
- std::string());
-}
-
-void GCMStatsRecorderImpl::RecordUnregistrationResponse(
- const std::string& app_id,
- UnregistrationRequest::Status status) {
- if (!is_recording_)
- return;
- RecordRegistration(app_id,
- std::string(),
- "Unregistration response received",
- GetUnregistrationStatusString(status));
-}
-
-void GCMStatsRecorderImpl::RecordUnregistrationRetryDelayed(
- const std::string& app_id,
- int64 delay_msec) {
- if (!is_recording_)
- return;
- RecordRegistration(app_id,
- std::string(),
- "Unregistration retry delayed",
- base::StringPrintf("Delayed for %" PRId64 " msec",
- delay_msec));
-}
-
-void GCMStatsRecorderImpl::RecordReceiving(
- const std::string& app_id,
- const std::string& from,
- int message_byte_size,
- const std::string& event,
- const std::string& details) {
- ReceivingActivity data;
- ReceivingActivity* inserted_data = InsertCircularBuffer(
- &receiving_activities_, data);
- inserted_data->app_id = app_id;
- inserted_data->from = from;
- inserted_data->message_byte_size = message_byte_size;
- inserted_data->event = event;
- inserted_data->details = details;
- NotifyActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordDataMessageReceived(
- const std::string& app_id,
- const std::string& from,
- int message_byte_size,
- bool to_registered_app,
- ReceivedMessageType message_type) {
- if (to_registered_app)
- UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1);
- if (!is_recording_)
- return;
- if (!to_registered_app) {
- RecordReceiving(app_id, from, message_byte_size, "Data msg received",
- to_registered_app ? std::string() :
- "No such registered app found");
- } else {
- switch(message_type) {
- case GCMStatsRecorderImpl::DATA_MESSAGE:
- RecordReceiving(app_id, from, message_byte_size, "Data msg received",
- std::string());
- break;
- case GCMStatsRecorderImpl::DELETED_MESSAGES:
- RecordReceiving(app_id, from, message_byte_size, "Data msg received",
- "Message has been deleted on server");
- break;
- default:
- NOTREACHED();
- }
- }
-}
-
-void GCMStatsRecorderImpl::CollectActivities(
- RecordedActivities* recorder_activities) const {
- recorder_activities->checkin_activities.insert(
- recorder_activities->checkin_activities.begin(),
- checkin_activities_.begin(),
- checkin_activities_.end());
- recorder_activities->connection_activities.insert(
- recorder_activities->connection_activities.begin(),
- connection_activities_.begin(),
- connection_activities_.end());
- recorder_activities->registration_activities.insert(
- recorder_activities->registration_activities.begin(),
- registration_activities_.begin(),
- registration_activities_.end());
- recorder_activities->receiving_activities.insert(
- recorder_activities->receiving_activities.begin(),
- receiving_activities_.begin(),
- receiving_activities_.end());
- recorder_activities->sending_activities.insert(
- recorder_activities->sending_activities.begin(),
- sending_activities_.begin(),
- sending_activities_.end());
-}
-
-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);
- inserted_data->app_id = app_id;
- inserted_data->receiver_id = receiver_id;
- inserted_data->message_id = message_id;
- inserted_data->event = event;
- inserted_data->details = details;
- NotifyActivityRecorded();
-}
-
-void GCMStatsRecorderImpl::RecordDataSentToWire(
- const std::string& app_id,
- const std::string& receiver_id,
- const std::string& message_id,
- int queued) {
- if (!is_recording_)
- return;
- RecordSending(app_id, receiver_id, message_id, "Data msg sent to wire",
- base::StringPrintf("Msg queued for %d seconds", queued));
-}
-
-void GCMStatsRecorderImpl::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) {
- UMA_HISTOGRAM_ENUMERATION("GCM.SendMessageStatus", status,
- gcm::MCSClient::SEND_STATUS_COUNT);
- if (!is_recording_)
- return;
- RecordSending(
- app_id,
- receiver_id,
- message_id,
- base::StringPrintf("SEND status: %s",
- GetMessageSendStatusString(status).c_str()),
- base::StringPrintf("Msg size: %d bytes, TTL: %d", byte_size, ttl));
-}
-
-void GCMStatsRecorderImpl::RecordIncomingSendError(
- const std::string& app_id,
- const std::string& receiver_id,
- const std::string& message_id) {
- UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1);
- if (!is_recording_)
- return;
- RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg",
- std::string());
-}
-
-} // namespace gcm
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h b/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h
deleted file mode 100644
index 434cb67..0000000
--- a/google_apis/gcm/monitoring/gcm_stats_recorder_impl.h
+++ /dev/null
@@ -1,156 +0,0 @@
-// 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_impl_unittest.cc b/google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc
deleted file mode 100644
index e870a60c..0000000
--- a/google_apis/gcm/monitoring/gcm_stats_recorder_impl_unittest.cc
+++ /dev/null
@@ -1,523 +0,0 @@
-// 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/gcm_stats_recorder_impl.h"
-
-#include <deque>
-#include <string>
-#include <vector>
-
-#include "google_apis/gcm/engine/mcs_client.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace gcm {
-
-namespace {
-
-static uint64 kAndroidId = 4U;
-static const char kCheckinStatus[] = "URL_FETCHING_FAILED";
-static const char kHost[] = "www.example.com";
-static const char kAppId[] = "app id 1";
-static const char kFrom[] = "from";
-static const char kSenderIds[] = "s1,s2";
-static const char kReceiverId[] = "receiver 1";
-static const char kMessageId[] = "message id 1";
-static const int kQueuedSec = 5;
-static const gcm::MCSClient::MessageSendStatus kMessageSendStatus =
- gcm::MCSClient::QUEUED;
-static const int kByteSize = 99;
-static const int kTTL = 7;
-static const int kRetries = 3;
-static const int64 kDelay = 15000;
-static const ConnectionFactory::ConnectionResetReason kReason =
- ConnectionFactory::NETWORK_CHANGE;
-static const int kNetworkError = 1;
-
-static const RegistrationRequest::Status kRegistrationStatus =
- RegistrationRequest::SUCCESS;
-static const UnregistrationRequest::Status kUnregistrationStatus =
- UnregistrationRequest::SUCCESS;
-
-static const char kCheckinInitiatedEvent[] = "Checkin initiated";
-static const char kCheckinInitiatedDetails[] = "Android Id: 4";
-static const char kCheckinDelayedDueToBackoffEvent[] = "Checkin backoff";
-static const char kCheckinDelayedDueToBackoffDetails[] =
- "Delayed for 15000 msec";
-static const char kCheckinSuccessEvent[] = "Checkin succeeded";
-static const char kCheckinSuccessDetails[] = "";
-static const char kCheckinFailureEvent[] = "Checkin failed";
-static const char kCheckinFailureDetails[] = "URL_FETCHING_FAILED. Will retry.";
-
-static const char kConnectionInitiatedEvent[] = "Connection initiated";
-static const char kConnectionInitiatedDetails[] = "www.example.com";
-static const char kConnectionDelayedDueToBackoffEvent[] = "Connection backoff";
-static const char kConnectionDelayedDueToBackoffDetails[] =
- "Delayed for 15000 msec";
-static const char kConnectionSuccessEvent[] = "Connection succeeded";
-static const char kConnectionSuccessDetails[] = "";
-static const char kConnectionFailureEvent[] = "Connection failed";
-static const char kConnectionFailureDetails[] = "With network error 1";
-static const char kConnectionResetSignaledEvent[] = "Connection reset";
-static const char kConnectionResetSignaledDetails[] = "NETWORK_CHANGE";
-
-static const char kRegistrationSentEvent[] = "Registration request sent";
-static const char kRegistrationSentDetails[] = "";
-static const char kRegistrationResponseEvent[] =
- "Registration response received";
-static const char kRegistrationResponseDetails[] = "SUCCESS";
-static const char kRegistrationRetryRequestedEvent[] =
- "Registration retry requested";
-static const char kRegistrationRetryRequestedDetails[] = "Retries left: 3";
-static const char kUnregistrationSentEvent[] = "Unregistration request sent";
-static const char kUnregistrationSentDetails[] = "";
-static const char kUnregistrationResponseEvent[] =
- "Unregistration response received";
-static const char kUnregistrationResponseDetails[] = "SUCCESS";
-static const char kUnregistrationRetryDelayedEvent[] =
- "Unregistration retry delayed";
-static const char kUnregistrationRetryDelayedDetails[] =
- "Delayed for 15000 msec";
-
-static const char kDataReceivedEvent[] = "Data msg received";
-static const char kDataReceivedDetails[] = "";
-static const char kDataReceivedNotRegisteredEvent[] = "Data msg received";
-static const char kDataReceivedNotRegisteredDetails[] =
- "No such registered app found";
-static const char kDataDeletedMessageEvent[] = "Data msg received";
-static const char kDataDeletedMessageDetails[] =
- "Message has been deleted on server";
-
-static const char kDataSentToWireEvent[] = "Data msg sent to wire";
-static const char kSentToWireDetails[] = "Msg queued for 5 seconds";
-static const char kNotifySendStatusEvent[] = "SEND status: QUEUED";
-static const char kNotifySendStatusDetails[] = "Msg size: 99 bytes, TTL: 7";
-static const char kIncomingSendErrorEvent[] = "Received 'send error' msg";
-static const char kIncomingSendErrorDetails[] = "";
-
-} // namespace
-
-class GCMStatsRecorderImplTest : public testing::Test {
- public:
- GCMStatsRecorderImplTest();
- virtual ~GCMStatsRecorderImplTest();
- virtual void SetUp() OVERRIDE;
-
- void VerifyRecordedCheckinCount(int expected_count) {
- EXPECT_EQ(expected_count,
- static_cast<int>(recorder_.checkin_activities().size()));
- }
- void VerifyRecordedConnectionCount(int expected_count) {
- EXPECT_EQ(expected_count,
- static_cast<int>(recorder_.connection_activities().size()));
- }
- void VerifyRecordedRegistrationCount(int expected_count) {
- EXPECT_EQ(expected_count,
- static_cast<int>(recorder_.registration_activities().size()));
- }
- void VerifyRecordedReceivingCount(int expected_count) {
- EXPECT_EQ(expected_count,
- static_cast<int>(recorder_.receiving_activities().size()));
- }
- void VerifyRecordedSendingCount(int expected_count) {
- EXPECT_EQ(expected_count,
- static_cast<int>(recorder_.sending_activities().size()));
- }
- void VerifyAllActivityQueueEmpty(const std::string& remark) {
- EXPECT_TRUE(recorder_.checkin_activities().empty()) << remark;
- EXPECT_TRUE(recorder_.connection_activities().empty()) << remark;
- EXPECT_TRUE(recorder_.registration_activities().empty()) << remark;
- EXPECT_TRUE(recorder_.receiving_activities().empty()) << remark;
- EXPECT_TRUE(recorder_.sending_activities().empty()) << remark;
- }
-
- void VerifyCheckinInitiated(const std::string& remark) {
- VerifyCheckin(recorder_.checkin_activities(),
- kCheckinInitiatedEvent,
- kCheckinInitiatedDetails,
- remark);
- }
-
- void VerifyCheckinDelayedDueToBackoff(const std::string& remark) {
- VerifyCheckin(recorder_.checkin_activities(),
- kCheckinDelayedDueToBackoffEvent,
- kCheckinDelayedDueToBackoffDetails,
- remark);
- }
-
- void VerifyCheckinSuccess(const std::string& remark) {
- VerifyCheckin(recorder_.checkin_activities(),
- kCheckinSuccessEvent,
- kCheckinSuccessDetails,
- remark);
- }
-
- void VerifyCheckinFailure(const std::string& remark) {
- VerifyCheckin(recorder_.checkin_activities(),
- kCheckinFailureEvent,
- kCheckinFailureDetails,
- remark);
- }
-
- void VerifyConnectionInitiated(const std::string& remark) {
- VerifyConnection(recorder_.connection_activities(),
- kConnectionInitiatedEvent,
- kConnectionInitiatedDetails,
- remark);
- }
-
- void VerifyConnectionDelayedDueToBackoff(const std::string& remark) {
- VerifyConnection(recorder_.connection_activities(),
- kConnectionDelayedDueToBackoffEvent,
- kConnectionDelayedDueToBackoffDetails,
- remark);
- }
-
- void VerifyConnectionSuccess(const std::string& remark) {
- VerifyConnection(recorder_.connection_activities(),
- kConnectionSuccessEvent,
- kConnectionSuccessDetails,
- remark);
- }
-
- void VerifyConnectionFailure(const std::string& remark) {
- VerifyConnection(recorder_.connection_activities(),
- kConnectionFailureEvent,
- kConnectionFailureDetails,
- remark);
- }
-
- void VerifyConnectionResetSignaled(const std::string& remark) {
- VerifyConnection(recorder_.connection_activities(),
- kConnectionResetSignaledEvent,
- kConnectionResetSignaledDetails,
- remark);
- }
-
- void VerifyRegistrationSent(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- kSenderIds,
- kRegistrationSentEvent,
- kRegistrationSentDetails,
- remark);
- }
-
- void VerifyRegistrationResponse(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- kSenderIds,
- kRegistrationResponseEvent,
- kRegistrationResponseDetails,
- remark);
- }
-
- void VerifyRegistrationRetryRequested(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- kSenderIds,
- kRegistrationRetryRequestedEvent,
- kRegistrationRetryRequestedDetails,
- remark);
- }
-
- void VerifyUnregistrationSent(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- std::string(),
- kUnregistrationSentEvent,
- kUnregistrationSentDetails,
- remark);
- }
-
- void VerifyUnregistrationResponse(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- std::string(),
- kUnregistrationResponseEvent,
- kUnregistrationResponseDetails,
- remark);
- }
-
- void VerifyUnregistrationRetryDelayed(const std::string& remark) {
- VerifyRegistration(recorder_.registration_activities(),
- std::string(),
- kUnregistrationRetryDelayedEvent,
- kUnregistrationRetryDelayedDetails,
- remark);
- }
-
- void VerifyDataMessageReceived(const std::string& remark) {
- VerifyReceivingData(recorder_.receiving_activities(),
- kDataReceivedEvent,
- kDataReceivedDetails,
- remark);
- }
-
- void VerifyDataDeletedMessage(const std::string& remark) {
- VerifyReceivingData(recorder_.receiving_activities(),
- kDataDeletedMessageEvent,
- kDataDeletedMessageDetails,
- remark);
- }
-
- void VerifyDataMessageReceivedNotRegistered(const std::string& remark) {
- VerifyReceivingData(recorder_.receiving_activities(),
- kDataReceivedNotRegisteredEvent,
- kDataReceivedNotRegisteredDetails,
- remark);
- }
-
- void VerifyDataSentToWire(const std::string& remark) {
- VerifySendingData(recorder_.sending_activities(),
- kDataSentToWireEvent,
- kSentToWireDetails,
- remark);
- }
-
- void VerifyNotifySendStatus(const std::string& remark) {
- VerifySendingData(recorder_.sending_activities(),
- kNotifySendStatusEvent,
- kNotifySendStatusDetails,
- remark);
- }
-
- void VerifyIncomingSendError(const std::string& remark) {
- VerifySendingData(recorder_.sending_activities(),
- kIncomingSendErrorEvent,
- kIncomingSendErrorDetails,
- remark);
- }
-
- protected:
- void VerifyCheckin(
- const std::deque<CheckinActivity>& queue,
- const std::string& event,
- const std::string& details,
- const std::string& remark) {
- EXPECT_EQ(event, queue.front().event) << remark;
- EXPECT_EQ(details, queue.front().details) << remark;
- }
-
- void VerifyConnection(
- const std::deque<ConnectionActivity>& queue,
- const std::string& event,
- const std::string& details,
- const std::string& remark) {
- EXPECT_EQ(event, queue.front().event) << remark;
- EXPECT_EQ(details, queue.front().details) << remark;
- }
-
- void VerifyRegistration(
- const std::deque<RegistrationActivity>& queue,
- const std::string& sender_ids,
- const std::string& event,
- const std::string& details,
- const std::string& remark) {
- EXPECT_EQ(kAppId, queue.front().app_id) << remark;
- EXPECT_EQ(sender_ids, queue.front().sender_ids) << remark;
- EXPECT_EQ(event, queue.front().event) << remark;
- EXPECT_EQ(details, queue.front().details) << remark;
- }
-
- void VerifyReceivingData(
- const std::deque<ReceivingActivity>& queue,
- const std::string& event,
- const std::string& details,
- const std::string& remark) {
- EXPECT_EQ(kAppId, queue.front().app_id) << remark;
- EXPECT_EQ(kFrom, queue.front().from) << remark;
- EXPECT_EQ(kByteSize, queue.front().message_byte_size) << remark;
- EXPECT_EQ(event, queue.front().event) << remark;
- EXPECT_EQ(details, queue.front().details) << remark;
- }
-
- void VerifySendingData(
- const std::deque<SendingActivity>& queue,
- const std::string& event, const std::string& details,
- const std::string& remark) {
- EXPECT_EQ(kAppId, queue.front().app_id) << remark;
- EXPECT_EQ(kReceiverId, queue.front().receiver_id) << remark;
- EXPECT_EQ(kMessageId, queue.front().message_id) << remark;
- EXPECT_EQ(event, queue.front().event) << remark;
- EXPECT_EQ(details, queue.front().details) << remark;
- }
-
- std::vector<std::string> sender_ids_;
- GCMStatsRecorderImpl recorder_;
-};
-
-GCMStatsRecorderImplTest::GCMStatsRecorderImplTest(){
-}
-
-GCMStatsRecorderImplTest::~GCMStatsRecorderImplTest() {}
-
-void GCMStatsRecorderImplTest::SetUp(){
- sender_ids_.push_back("s1");
- sender_ids_.push_back("s2");
- recorder_.SetRecording(true);
-}
-
-TEST_F(GCMStatsRecorderImplTest, StartStopRecordingTest) {
- EXPECT_TRUE(recorder_.is_recording());
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- VerifyRecordedSendingCount(1);
- VerifyDataSentToWire("1st call");
-
- recorder_.SetRecording(false);
- EXPECT_FALSE(recorder_.is_recording());
- recorder_.Clear();
- VerifyAllActivityQueueEmpty("all cleared");
-
- // Exercise every recording method below and verify that nothing is recorded.
- recorder_.RecordCheckinInitiated(kAndroidId);
- recorder_.RecordCheckinDelayedDueToBackoff(kDelay);
- recorder_.RecordCheckinSuccess();
- recorder_.RecordCheckinFailure(kCheckinStatus, true);
- VerifyAllActivityQueueEmpty("no checkin");
-
- recorder_.RecordConnectionInitiated(kHost);
- recorder_.RecordConnectionDelayedDueToBackoff(kDelay);
- recorder_.RecordConnectionSuccess();
- recorder_.RecordConnectionFailure(kNetworkError);
- recorder_.RecordConnectionResetSignaled(kReason);
- VerifyAllActivityQueueEmpty("no registration");
-
- recorder_.RecordRegistrationSent(kAppId, kSenderIds);
- recorder_.RecordRegistrationResponse(kAppId, sender_ids_,
- kRegistrationStatus);
- recorder_.RecordRegistrationRetryRequested(kAppId, sender_ids_, kRetries);
- recorder_.RecordUnregistrationSent(kAppId);
- recorder_.RecordUnregistrationResponse(kAppId, kUnregistrationStatus);
- recorder_.RecordUnregistrationRetryDelayed(kAppId, kDelay);
- VerifyAllActivityQueueEmpty("no unregistration");
-
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true,
- GCMStatsRecorder::DATA_MESSAGE);
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true,
- GCMStatsRecorder::DELETED_MESSAGES);
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, false,
- GCMStatsRecorder::DATA_MESSAGE);
- VerifyAllActivityQueueEmpty("no receiving");
-
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
- kMessageSendStatus, kByteSize, kTTL);
- recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId);
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- VerifyAllActivityQueueEmpty("no sending");
-}
-
-TEST_F(GCMStatsRecorderImplTest, ClearLogTest) {
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- VerifyRecordedSendingCount(1);
- VerifyDataSentToWire("1st call");
-
- recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
- kMessageSendStatus, kByteSize, kTTL);
- VerifyRecordedSendingCount(2);
- VerifyNotifySendStatus("2nd call");
-
- recorder_.Clear();
- VerifyRecordedSendingCount(0);
-}
-
-TEST_F(GCMStatsRecorderImplTest, CheckinTest) {
- recorder_.RecordCheckinInitiated(kAndroidId);
- VerifyRecordedCheckinCount(1);
- VerifyCheckinInitiated("1st call");
-
- recorder_.RecordCheckinDelayedDueToBackoff(kDelay);
- VerifyRecordedCheckinCount(2);
- VerifyCheckinDelayedDueToBackoff("2nd call");
-
- recorder_.RecordCheckinSuccess();
- VerifyRecordedCheckinCount(3);
- VerifyCheckinSuccess("3rd call");
-
- recorder_.RecordCheckinFailure(kCheckinStatus, true);
- VerifyRecordedCheckinCount(4);
- VerifyCheckinFailure("4th call");
-}
-
-TEST_F(GCMStatsRecorderImplTest, ConnectionTest) {
- recorder_.RecordConnectionInitiated(kHost);
- VerifyRecordedConnectionCount(1);
- VerifyConnectionInitiated("1st call");
-
- recorder_.RecordConnectionDelayedDueToBackoff(kDelay);
- VerifyRecordedConnectionCount(2);
- VerifyConnectionDelayedDueToBackoff("2nd call");
-
- recorder_.RecordConnectionSuccess();
- VerifyRecordedConnectionCount(3);
- VerifyConnectionSuccess("3rd call");
-
- recorder_.RecordConnectionFailure(kNetworkError);
- VerifyRecordedConnectionCount(4);
- VerifyConnectionFailure("4th call");
-
- recorder_.RecordConnectionResetSignaled(kReason);
- VerifyRecordedConnectionCount(5);
- VerifyConnectionResetSignaled("5th call");
-}
-
-TEST_F(GCMStatsRecorderImplTest, RegistrationTest) {
- recorder_.RecordRegistrationSent(kAppId, kSenderIds);
- VerifyRecordedRegistrationCount(1);
- VerifyRegistrationSent("1st call");
-
- recorder_.RecordRegistrationResponse(kAppId, sender_ids_,
- kRegistrationStatus);
- VerifyRecordedRegistrationCount(2);
- VerifyRegistrationResponse("2nd call");
-
- recorder_.RecordRegistrationRetryRequested(kAppId, sender_ids_, kRetries);
- VerifyRecordedRegistrationCount(3);
- VerifyRegistrationRetryRequested("3rd call");
-
- recorder_.RecordUnregistrationSent(kAppId);
- VerifyRecordedRegistrationCount(4);
- VerifyUnregistrationSent("4th call");
-
- recorder_.RecordUnregistrationResponse(kAppId, kUnregistrationStatus);
- VerifyRecordedRegistrationCount(5);
- VerifyUnregistrationResponse("5th call");
-
- recorder_.RecordUnregistrationRetryDelayed(kAppId, kDelay);
- VerifyRecordedRegistrationCount(6);
- VerifyUnregistrationRetryDelayed("6th call");
-}
-
-TEST_F(GCMStatsRecorderImplTest, RecordReceivingTest) {
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true,
- GCMStatsRecorder::DATA_MESSAGE);
- VerifyRecordedReceivingCount(1);
- VerifyDataMessageReceived("1st call");
-
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, true,
- GCMStatsRecorder::DELETED_MESSAGES);
- VerifyRecordedReceivingCount(2);
- VerifyDataDeletedMessage("2nd call");
-
- recorder_.RecordDataMessageReceived(kAppId, kFrom, kByteSize, false,
- GCMStatsRecorder::DATA_MESSAGE);
- VerifyRecordedReceivingCount(3);
- VerifyDataMessageReceivedNotRegistered("3rd call");
-}
-
-TEST_F(GCMStatsRecorderImplTest, RecordSendingTest) {
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- VerifyRecordedSendingCount(1);
- VerifyDataSentToWire("1st call");
-
- recorder_.RecordNotifySendStatus(kAppId, kReceiverId, kMessageId,
- kMessageSendStatus, kByteSize, kTTL);
- VerifyRecordedSendingCount(2);
- VerifyNotifySendStatus("2nd call");
-
- recorder_.RecordIncomingSendError(kAppId, kReceiverId, kMessageId);
- VerifyRecordedSendingCount(3);
- VerifyIncomingSendError("3rd call");
-
- recorder_.RecordDataSentToWire(kAppId, kReceiverId, kMessageId, kQueuedSec);
- VerifyRecordedSendingCount(4);
- VerifyDataSentToWire("4th call");
-}
-
-} // namespace gcm