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

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 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100;
10
11 const char kSuccess[] = "SUCCESS";
Alexei Svitkine (slow) 2015/12/21 15:43:54 Nit: Add an anonymous namespace around these.
Peter Beverloo 2015/12/21 16:18:58 I have added an anonymous namespace per your reque
12 const char kUnknownError[] = "UNKNOWN_ERROR";
13
14 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate)
15 : delegate_(delegate) {}
16
17 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {}
18
19 void GCMStatsRecorderAndroid::Clear() {
20 registration_activities_.clear();
21 receiving_activities_.clear();
22 }
23
24 void GCMStatsRecorderAndroid::CollectActivities(
25 RecordedActivities* recorded_activities) const {
26 DCHECK(recorded_activities);
27
28 recorded_activities->registration_activities.insert(
29 recorded_activities->registration_activities.begin(),
30 registration_activities_.begin(),
31 registration_activities_.end());
32 recorded_activities->receiving_activities.insert(
33 recorded_activities->receiving_activities.begin(),
34 receiving_activities_.begin(),
35 receiving_activities_.end());
36 }
37
38 void GCMStatsRecorderAndroid::RecordRegistrationSent(
39 const std::string& app_id) {
40 if (!is_recording_)
41 return;
42
43 RecordRegistration(app_id, "Registration request sent", "" /* details */);
44 }
45
46 void GCMStatsRecorderAndroid::RecordRegistrationResponse(
47 const std::string& app_id,
48 bool success) {
49 if (!is_recording_)
50 return;
51
52 RecordRegistration(
53 app_id, "Registration response received", success ? kSuccess
54 : kUnknownError);
55 }
56
57 void GCMStatsRecorderAndroid::RecordUnregistrationSent(
58 const std::string& app_id) {
59 if (!is_recording_)
60 return;
61
62 RecordRegistration(app_id, "Unregistration request sent", "" /* details */);
63 }
64
65 void GCMStatsRecorderAndroid::RecordUnregistrationResponse(
66 const std::string& app_id,
67 bool success) {
68 if (!is_recording_)
69 return;
70
71 RecordRegistration(
72 app_id, "Unregistration response received", success ? kSuccess
73 : kUnknownError);
74 }
75
76 void GCMStatsRecorderAndroid::RecordRegistration(const std::string& app_id,
77 const std::string& event,
78 const std::string& details) {
79 RegistrationActivity activity;
80 activity.app_id = app_id;
81 activity.event = event;
82 activity.details = details;
83
84 // TODO(peter): Include the |source| (sender id(s)) of the registrations.
85
86 registration_activities_.push_front(activity);
87 if (registration_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT)
88 registration_activities_.pop_back();
89
90 if (delegate_)
91 delegate_->OnActivityRecorded();
92 }
93
94 void GCMStatsRecorderAndroid::RecordDataMessageReceived(
95 const std::string& app_id,
96 int message_byte_size) {
97 if (!is_recording_)
98 return;
99
100 ReceivingActivity activity;
101 activity.app_id = app_id;
102 activity.message_byte_size = message_byte_size;
103 activity.event = "Data msg received";
104
105 receiving_activities_.push_front(activity);
106 if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT)
107 receiving_activities_.pop_back();
108
109 if (delegate_)
110 delegate_->OnActivityRecorded();
111 }
112
113 } // 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