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

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

Issue 2628733004: Update ConnectionEventTracker to check if there is an in progress attempt. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « no previous file | google_apis/gcm/engine/connection_factory_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gcm/engine/connection_event_tracker.h" 5 #include "google_apis/gcm/engine/connection_event_tracker.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "net/base/network_change_notifier.h" 8 #include "net/base/network_change_notifier.h"
9 9
10 namespace { 10 namespace {
(...skipping 14 matching lines...) Expand all
25 // TODO(harkness): Can we dcheck here that there is not an in progress 25 // TODO(harkness): Can we dcheck here that there is not an in progress
26 // connection? 26 // connection?
27 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime()); 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 28 // The connection type is passed to the server and stored there, so the
29 // values should remain consistent. 29 // values should remain consistent.
30 current_event_.set_network_type( 30 current_event_.set_network_type(
31 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType())); 31 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType()));
32 } 32 }
33 33
34 void ConnectionEventTracker::EndConnectionAttempt() { 34 void ConnectionEventTracker::EndConnectionAttempt() {
35 // TODO(harkness): Modify tests so that we can put a DCHECK here. 35 // It is possible to get EndConnectionAttempt when there is not an in progress
Peter Beverloo 2017/01/11 14:31:48 Why isn't the TODO relevant anymore?
36 if (completed_events_.size() == kMaxClientEvents) { 36 // event, because EndConnectionAttempt is called from SignalConnectionReset,
37 // Don't let the completed events grow beyond the max. 37 // which will be called any time the network changes state. Only save the
38 completed_events_.pop_front(); 38 // current_event_ if it has data.
39 number_discarded_events_++; 39 if (current_event_.has_time_connection_started_ms()) {
Peter Beverloo 2017/01/11 14:31:48 style nit: prefer early return over nesting. if
harkness 2017/01/12 11:04:48 No longer applicable.
40 if (completed_events_.size() == kMaxClientEvents) {
41 // Don't let the completed events grow beyond the max.
42 completed_events_.pop_front();
43 number_discarded_events_++;
44 }
45
46 // Current event is finished, so add it to our list of completed events.
47 current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime());
48 completed_events_.push_back(current_event_);
49 current_event_.Clear();
40 } 50 }
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 } 51 }
47 52
48 void ConnectionEventTracker::ConnectionAttemptSucceeded() { 53 void ConnectionEventTracker::ConnectionAttemptSucceeded() {
49 // Record the successful connection so information about it can be sent in the 54 // 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 55 // next login request. If there is a login failure, this will need to be
51 // updated to a failed connection. 56 // updated to a failed connection.
52 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION); 57 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
53 current_event_.set_time_connection_established_ms( 58 current_event_.set_time_connection_established_ms(
54 base::Time::Now().ToJavaTime()); 59 base::Time::Now().ToJavaTime());
55 60
(...skipping 30 matching lines...) Expand all
86 mcs_proto::ClientEvent* event = request->add_client_event(); 91 mcs_proto::ClientEvent* event = request->add_client_event();
87 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS); 92 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS);
88 event->set_number_discarded_events(number_discarded_events_); 93 event->set_number_discarded_events(number_discarded_events_);
89 } 94 }
90 95
91 for (const mcs_proto::ClientEvent& event : completed_events_) 96 for (const mcs_proto::ClientEvent& event : completed_events_)
92 request->add_client_event()->CopyFrom(event); 97 request->add_client_event()->CopyFrom(event);
93 } 98 }
94 99
95 } // namespace gcm 100 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/connection_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698