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

Side by Side Diff: google_apis/gcm/engine/connection_event_tracker.cc

Issue 2481873002: Added ClientEvent proto and structure for storing events in the factory. (Closed)
Patch Set: Rebase and address code review comments. Created 4 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 2016 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 "google_apis/gcm/engine/connection_event_tracker.h"
6
7 #include "base/time/time.h"
8 #include "google_apis/gcm/protocol/mcs.pb.h"
Peter Beverloo 2016/12/05 16:29:34 nit: unused (already included in the header)
harkness 2016/12/06 12:53:35 Done.
9
10 namespace {
11
12 // The maxiumum number of events which are stored before deleting old ones.
13 // This mirrors the behaviour of the GMS Core connection tracking.
14 constexpr size_t kMaxClientEvents = 30;
15
16 } // namespace
17
18 namespace gcm {
19
20 ConnectionEventTracker::ConnectionEventTracker() = default;
21
22 ConnectionEventTracker::~ConnectionEventTracker() = default;
23
24 void ConnectionEventTracker::StartConnectionAttempt() {
25 // TODO(harkness): Can we dcheck here that there is not an in progress
Nicolas Zea 2016/12/05 18:36:15 I think you should be able to (the connection fact
harkness 2016/12/06 12:53:35 I'll experiment with that in a follow-up patch, an
26 // connection?
27 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime());
28 current_event_.set_network_type(
29 net::NetworkChangeNotifier::GetConnectionType());
Peter Beverloo 2016/12/05 16:29:34 two thoughts: (1) maybe add a static_cast<int> f
harkness 2016/12/06 12:53:35 Done.
30 }
31
32 void ConnectionEventTracker::EndConnectionAttempt() {
Peter Beverloo 2016/12/05 16:29:34 nit: DCHECK(current_event_.has_type()); (The ty
harkness 2016/12/06 12:53:35 It should have been set, however, the test code do
33 if (completed_events_.size() == kMaxClientEvents) {
34 // Don't let the completed events grow beyond the max.
35 completed_events_.pop_front();
36 // TODO(harkness): Keep track of deleted events.
37 }
38
39 // Current event is now completed, so add it to our list of completed events.
40 current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime());
41 completed_events_.push_back(current_event_);
42 current_event_.Clear();
43 }
44
45 void ConnectionEventTracker::ConnectionAttemptSucceeded() {
46 // Record the successful connection so information about it can be sent in the
47 // next login request. If there is a login failure, this will need to be
48 // updated to a failed connection.
49 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
50 current_event_.set_time_connection_established_ms(
51 base::Time::Now().ToJavaTime());
52
53 // A completed connection means that the old client event data has now been
54 // sent to GCM. Delete old data.
55 completed_events_.clear();
56 }
57
58 void ConnectionEventTracker::ConnectionLoginFailed() {
59 // A login failure would have originally been marked as a successful
60 // connection, so now that it failed, that needs to be updated.
61 DCHECK_EQ(current_event_.type(),
62 mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
63
64 current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
65 current_event_.clear_time_connection_established_ms();
66 current_event_.set_error_code(net::ERR_CONNECTION_RESET);
67 }
68
69 void ConnectionEventTracker::ConnectionAttemptFailed(int error) {
70 DCHECK_NE(error, net::OK);
71
72 current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
73 current_event_.set_error_code(error);
74 }
75
76 void ConnectionEventTracker::WriteToLoginRequest(
77 mcs_proto::LoginRequest* request) {
78 DCHECK(request);
79 for (const mcs_proto::ClientEvent& event : completed_events_)
80 request->add_client_event()->CopyFrom(event);
81 }
82
83 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698