Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: components/gcm_driver/gcm_stats_recorder_android.cc

Issue 1515153003: Enable chrome://gcm-internals on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/gcm_driver/gcm_stats_recorder_android.h"
6
7 namespace gcm {
8
9 namespace {
10
11 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100;
12
13 const char kSuccess[] = "SUCCESS";
14 const char kUnknownError[] = "UNKNOWN_ERROR";
15
16 } // namespace
17
18 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate)
19 : delegate_(delegate) {}
20
21 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {}
22
23 void GCMStatsRecorderAndroid::Clear() {
24 registration_activities_.clear();
25 receiving_activities_.clear();
26 }
27
28 void GCMStatsRecorderAndroid::CollectActivities(
29 RecordedActivities* recorded_activities) const {
30 DCHECK(recorded_activities);
31
32 recorded_activities->registration_activities.insert(
33 recorded_activities->registration_activities.begin(),
34 registration_activities_.begin(),
35 registration_activities_.end());
36 recorded_activities->receiving_activities.insert(
37 recorded_activities->receiving_activities.begin(),
38 receiving_activities_.begin(),
39 receiving_activities_.end());
40 }
41
42 void GCMStatsRecorderAndroid::RecordRegistrationSent(
43 const std::string& app_id) {
44 if (!is_recording_)
45 return;
46
47 RecordRegistration(app_id, "Registration request sent", "" /* details */);
48 }
49
50 void GCMStatsRecorderAndroid::RecordRegistrationResponse(
51 const std::string& app_id,
52 bool success) {
53 if (!is_recording_)
54 return;
55
56 RecordRegistration(
57 app_id, "Registration response received", success ? kSuccess
58 : kUnknownError);
59 }
60
61 void GCMStatsRecorderAndroid::RecordUnregistrationSent(
62 const std::string& app_id) {
63 if (!is_recording_)
64 return;
65
66 RecordRegistration(app_id, "Unregistration request sent", "" /* details */);
67 }
68
69 void GCMStatsRecorderAndroid::RecordUnregistrationResponse(
70 const std::string& app_id,
71 bool success) {
72 if (!is_recording_)
73 return;
74
75 RecordRegistration(
76 app_id, "Unregistration response received", success ? kSuccess
77 : kUnknownError);
78 }
79
80 void GCMStatsRecorderAndroid::RecordRegistration(const std::string& app_id,
81 const std::string& event,
82 const std::string& details) {
83 RegistrationActivity activity;
84 activity.app_id = app_id;
85 activity.event = event;
86 activity.details = details;
87
88 // TODO(peter): Include the |source| (sender id(s)) of the registrations.
89
90 registration_activities_.push_front(activity);
91 if (registration_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT)
92 registration_activities_.pop_back();
93
94 if (delegate_)
95 delegate_->OnActivityRecorded();
96 }
97
98 void GCMStatsRecorderAndroid::RecordDataMessageReceived(
99 const std::string& app_id,
100 int message_byte_size) {
101 if (!is_recording_)
102 return;
103
104 ReceivingActivity activity;
105 activity.app_id = app_id;
106 activity.message_byte_size = message_byte_size;
107 activity.event = "Data msg received";
108
109 receiving_activities_.push_front(activity);
110 if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT)
111 receiving_activities_.pop_back();
112
113 if (delegate_)
114 delegate_->OnActivityRecorded();
115 }
116
117 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_stats_recorder_android.h ('k') | components/gcm_driver/gcm_stats_recorder_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698