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

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: Integrated 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 "net/base/network_change_notifier.h"
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
26 // connection?
27 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime());
28 // The connection type is passed to the server and stored there, so the
29 // values should remain consistent.
30 current_event_.set_network_type(
31 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType()));
32 }
33
34 void ConnectionEventTracker::EndConnectionAttempt() {
35 // TODO(harkness): Modify tests so that we can put a DCHECK here.
36 if (completed_events_.size() == kMaxClientEvents) {
37 // Don't let the completed events grow beyond the max.
38 completed_events_.pop_front();
39 // TODO(harkness): Keep track of deleted events.
40 }
41
42 // Current event is now completed, so add it to our list of completed events.
43 current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime());
44 completed_events_.push_back(current_event_);
45 current_event_.Clear();
46 }
47
48 void ConnectionEventTracker::ConnectionAttemptSucceeded() {
49 // Record the successful connection so information about it can be sent in the
50 // next login request. If there is a login failure, this will need to be
51 // updated to a failed connection.
52 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
53 current_event_.set_time_connection_established_ms(
54 base::Time::Now().ToJavaTime());
55
56 // A completed connection means that the old client event data has now been
57 // sent to GCM. Delete old data.
58 completed_events_.clear();
59 }
60
61 void ConnectionEventTracker::ConnectionLoginFailed() {
62 // A login failure would have originally been marked as a successful
63 // connection, so now that it failed, that needs to be updated.
64 DCHECK_EQ(current_event_.type(),
65 mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
66
67 current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
68 current_event_.clear_time_connection_established_ms();
69 current_event_.set_error_code(net::ERR_CONNECTION_RESET);
70 }
71
72 void ConnectionEventTracker::ConnectionAttemptFailed(int error) {
73 DCHECK_NE(error, net::OK);
74
75 current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
76 current_event_.set_error_code(error);
77 }
78
79 void ConnectionEventTracker::WriteToLoginRequest(
80 mcs_proto::LoginRequest* request) {
81 DCHECK(request);
82 for (const mcs_proto::ClientEvent& event : completed_events_)
83 request->add_client_event()->CopyFrom(event);
84 }
85
86 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/connection_event_tracker.h ('k') | google_apis/gcm/engine/connection_event_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698