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

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 #include "base/metrics/histogram_macros.h"
8
9 namespace gcm {
10
11 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100;
Nicolas Zea 2015/12/16 22:24:32 nit: put this in an anonymous namespace?
Peter Beverloo 2015/12/17 17:08:24 No need, constants have internal linkage by defaul
12
13 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate)
14 : delegate_(delegate) {}
15
16 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {}
17
18 void GCMStatsRecorderAndroid::Clear() {
19 registration_activities_.clear();
20 receiving_activities_.clear();
21 }
22
23 void GCMStatsRecorderAndroid::CollectActivities(
24 RecordedActivities* recorder_activities) const {
25 DCHECK(recorder_activities);
26
27 recorder_activities->registration_activities.insert(
28 recorder_activities->registration_activities.begin(),
29 registration_activities_.begin(),
30 registration_activities_.end());
31 recorder_activities->receiving_activities.insert(
32 recorder_activities->receiving_activities.begin(),
33 receiving_activities_.begin(),
34 receiving_activities_.end());
35 }
36
37 void GCMStatsRecorderAndroid::RecordRegistrationSent(
38 const std::string& app_id) {
39 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1);
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 ? "SUCCESS"
Nicolas Zea 2015/12/16 22:24:32 nit: consider defining these as const char[] in an
Peter Beverloo 2015/12/17 17:08:24 Moved them to constants, but same reply re: the na
54 : "UNKNOWN_ERROR");
55 }
56
57 void GCMStatsRecorderAndroid::RecordUnregistrationSent(
58 const std::string& app_id) {
59 UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1);
60 if (!is_recording_)
61 return;
62
63 RecordRegistration(app_id, "Unregistration request sent", "" /* details */);
64 }
65
66 void GCMStatsRecorderAndroid::RecordUnregistrationResponse(
67 const std::string& app_id,
68 bool success) {
69 if (!is_recording_)
70 return;
71
72 RecordRegistration(
73 app_id, "Unregistration response received", success ? "SUCCESS"
74 : "UNKNOWN_ERROR");
75 }
76
77 void GCMStatsRecorderAndroid::RecordRegistration(const std::string& app_id,
78 const std::string& event,
79 const std::string& details) {
80 RegistrationActivity activity;
81 activity.app_id = app_id;
82 activity.event = event;
83 activity.details = details;
84
85 // TODO(peter): Include the |source| (sender id(s)) of the registrations.
86
87 registration_activities_.push_front(activity);
88 if (registration_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT)
89 registration_activities_.pop_back();
90
91 if (delegate_)
92 delegate_->OnActivityRecorded();
93 }
94
95 void GCMStatsRecorderAndroid::RecordDataMessageReceived(
96 const std::string& app_id,
97 int message_byte_size) {
98 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1);
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

Powered by Google App Engine
This is Rietveld 408576698