summaryrefslogtreecommitdiffstats
path: root/google_apis/gcm
diff options
context:
space:
mode:
authorjuyik@chromium.org <juyik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 22:19:11 +0000
committerjuyik@chromium.org <juyik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 22:19:11 +0000
commit6d43ebd465f64e0d82f4b315bd96498025ca393e (patch)
tree441eedae57cd5fc4403111d6624b7581f5f77d48 /google_apis/gcm
parent39c542626ea30e9ae31eab5155b085ea45bf08c7 (diff)
downloadchromium_src-6d43ebd465f64e0d82f4b315bd96498025ca393e.zip
chromium_src-6d43ebd465f64e0d82f4b315bd96498025ca393e.tar.gz
chromium_src-6d43ebd465f64e0d82f4b315bd96498025ca393e.tar.bz2
Enable auto-refreshing of the gcm-internals page whenever a GCM activity is recorded.
BUG=341256 Review URL: https://codereview.chromium.org/266913015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268976 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gcm')
-rw-r--r--google_apis/gcm/gcm_client.h4
-rw-r--r--google_apis/gcm/gcm_client_impl.cc8
-rw-r--r--google_apis/gcm/gcm_client_impl.h8
-rw-r--r--google_apis/gcm/gcm_client_impl_unittest.cc1
-rw-r--r--google_apis/gcm/monitoring/gcm_stats_recorder.cc16
-rw-r--r--google_apis/gcm/monitoring/gcm_stats_recorder.h21
6 files changed, 53 insertions, 5 deletions
diff --git a/google_apis/gcm/gcm_client.h b/google_apis/gcm/gcm_client.h
index 28c9ef2..ff9eb41 100644
--- a/google_apis/gcm/gcm_client.h
+++ b/google_apis/gcm/gcm_client.h
@@ -156,6 +156,10 @@ class GCM_EXPORT GCMClient {
// finished loading from the GCM store and retrieved the device check-in
// from the server if it hadn't yet.
virtual void OnGCMReady() = 0;
+
+ // Called when activities are being recorded and a new activity has just
+ // been recorded.
+ virtual void OnActivityRecorded() = 0;
};
GCMClient();
diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc
index a0a2142..953baa9 100644
--- a/google_apis/gcm/gcm_client_impl.cc
+++ b/google_apis/gcm/gcm_client_impl.cc
@@ -176,7 +176,7 @@ void GCMClientImpl::Initialize(
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter,
- Delegate* delegate) {
+ GCMClient::Delegate* delegate) {
DCHECK_EQ(UNINITIALIZED, state_);
DCHECK(url_request_context_getter);
DCHECK(delegate);
@@ -195,6 +195,8 @@ void GCMClientImpl::Initialize(
delegate_ = delegate;
+ recorder_.SetDelegate(this);
+
state_ = INITIALIZED;
}
@@ -627,6 +629,10 @@ GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const {
return stats;
}
+void GCMClientImpl::OnActivityRecorded() {
+ delegate_->OnActivityRecorded();
+}
+
void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) {
switch (message.tag()) {
case kLoginResponseTag:
diff --git a/google_apis/gcm/gcm_client_impl.h b/google_apis/gcm/gcm_client_impl.h
index 85f206b..47ef48a 100644
--- a/google_apis/gcm/gcm_client_impl.h
+++ b/google_apis/gcm/gcm_client_impl.h
@@ -73,7 +73,8 @@ class GCM_EXPORT GCMInternalsBuilder {
// with MCS) and other pieces of GCM infrastructure like Registration and
// Checkins. It also allows for registering user delegates that host
// applications that send and receive messages.
-class GCM_EXPORT GCMClientImpl : public GCMClient {
+class GCM_EXPORT GCMClientImpl
+ : public GCMClient, public GCMStatsRecorder::Delegate {
public:
explicit GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder);
virtual ~GCMClientImpl();
@@ -86,7 +87,7 @@ class GCM_EXPORT GCMClientImpl : public GCMClient {
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter,
- Delegate* delegate) OVERRIDE;
+ GCMClient::Delegate* delegate) OVERRIDE;
virtual void Load() OVERRIDE;
virtual void Stop() OVERRIDE;
virtual void CheckOut() OVERRIDE;
@@ -99,6 +100,7 @@ class GCM_EXPORT GCMClientImpl : public GCMClient {
virtual void SetRecording(bool recording) OVERRIDE;
virtual void ClearActivityLogs() OVERRIDE;
virtual GCMStatistics GetStatistics() const OVERRIDE;
+ virtual void OnActivityRecorded() OVERRIDE;
private:
// State representation of the GCMClient.
@@ -235,7 +237,7 @@ class GCM_EXPORT GCMClientImpl : public GCMClient {
// State of the GCM Client Implementation.
State state_;
- Delegate* delegate_;
+ GCMClient::Delegate* delegate_;
// Device checkin info (android ID and security token used by device).
CheckinInfo device_checkin_info_;
diff --git a/google_apis/gcm/gcm_client_impl_unittest.cc b/google_apis/gcm/gcm_client_impl_unittest.cc
index ba49590..d0b278f 100644
--- a/google_apis/gcm/gcm_client_impl_unittest.cc
+++ b/google_apis/gcm/gcm_client_impl_unittest.cc
@@ -250,6 +250,7 @@ class GCMClientImplTest : public testing::Test,
const std::string& app_id,
const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
virtual void OnGCMReady() OVERRIDE;
+ virtual void OnActivityRecorded() OVERRIDE {}
GCMClientImpl* gcm_client() const { return gcm_client_.get(); }
FakeMCSClient* mcs_client() const {
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder.cc b/google_apis/gcm/monitoring/gcm_stats_recorder.cc
index 649720f..8d1d2aa 100644
--- a/google_apis/gcm/monitoring/gcm_stats_recorder.cc
+++ b/google_apis/gcm/monitoring/gcm_stats_recorder.cc
@@ -184,7 +184,7 @@ GCMStatsRecorder::RecordedActivities::RecordedActivities() {
GCMStatsRecorder::RecordedActivities::~RecordedActivities() {
}
-GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) {
+GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false), delegate_(NULL) {
}
GCMStatsRecorder::~GCMStatsRecorder() {
@@ -194,6 +194,10 @@ void GCMStatsRecorder::SetRecording(bool recording) {
is_recording_ = recording;
}
+void GCMStatsRecorder::SetDelegate(Delegate* delegate) {
+ delegate_ = delegate;
+}
+
void GCMStatsRecorder::Clear() {
checkin_activities_.clear();
connection_activities_.clear();
@@ -202,6 +206,11 @@ void GCMStatsRecorder::Clear() {
sending_activities_.clear();
}
+void GCMStatsRecorder::NotifyActivityRecorded() {
+ if (delegate_)
+ delegate_->OnActivityRecorded();
+}
+
void GCMStatsRecorder::RecordCheckin(
const std::string& event,
const std::string& details) {
@@ -210,6 +219,7 @@ void GCMStatsRecorder::RecordCheckin(
&checkin_activities_, data);
inserted_data->event = event;
inserted_data->details = details;
+ NotifyActivityRecorded();
}
void GCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) {
@@ -251,6 +261,7 @@ void GCMStatsRecorder::RecordConnection(
&connection_activities_, data);
inserted_data->event = event;
inserted_data->details = details;
+ NotifyActivityRecorded();
}
void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) {
@@ -300,6 +311,7 @@ void GCMStatsRecorder::RecordRegistration(
inserted_data->sender_ids = sender_ids;
inserted_data->event = event;
inserted_data->details = details;
+ NotifyActivityRecorded();
}
void GCMStatsRecorder::RecordRegistrationSent(
@@ -378,6 +390,7 @@ void GCMStatsRecorder::RecordReceiving(
inserted_data->message_byte_size = message_byte_size;
inserted_data->event = event;
inserted_data->details = details;
+ NotifyActivityRecorded();
}
void GCMStatsRecorder::RecordDataMessageReceived(
@@ -447,6 +460,7 @@ void GCMStatsRecorder::RecordSending(const std::string& app_id,
inserted_data->message_id = message_id;
inserted_data->event = event;
inserted_data->details = details;
+ NotifyActivityRecorded();
}
void GCMStatsRecorder::RecordDataSentToWire(
diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder.h b/google_apis/gcm/monitoring/gcm_stats_recorder.h
index ffee1ae..bc2afb2 100644
--- a/google_apis/gcm/monitoring/gcm_stats_recorder.h
+++ b/google_apis/gcm/monitoring/gcm_stats_recorder.h
@@ -95,6 +95,15 @@ class GCM_EXPORT GCMStatsRecorder {
std::vector<GCMStatsRecorder::SendingActivity> sending_activities;
};
+ // A delegate interface that allows the GCMStatsRecorder instance to interact
+ // with its container.
+ class Delegate {
+ public:
+ // Called when the GCMStatsRecorder is recording activities and a new
+ // activity has just been recorded.
+ virtual void OnActivityRecorded() = 0;
+ };
+
GCMStatsRecorder();
virtual ~GCMStatsRecorder();
@@ -106,6 +115,9 @@ class GCM_EXPORT GCMStatsRecorder {
// 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();
@@ -219,19 +231,27 @@ class GCM_EXPORT GCMStatsRecorder {
}
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,
@@ -239,6 +259,7 @@ class GCM_EXPORT GCMStatsRecorder {
const std::string& details);
bool is_recording_;
+ Delegate* delegate_;
std::deque<CheckinActivity> checkin_activities_;
std::deque<ConnectionActivity> connection_activities_;