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

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: Rebase and fix nits 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
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/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "net/base/network_change_notifier.h" 9 #include "net/base/network_change_notifier.h"
10 10
11 namespace { 11 namespace {
12 12
13 // The maxiumum number of events which are stored before deleting old ones. 13 // The maxiumum number of events which are stored before deleting old ones.
14 // This mirrors the behaviour of the GMS Core connection tracking. 14 // This mirrors the behaviour of the GMS Core connection tracking.
15 constexpr size_t kMaxClientEvents = 30; 15 constexpr size_t kMaxClientEvents = 30;
16 16
17 } // namespace 17 } // namespace
18 18
19 namespace gcm { 19 namespace gcm {
20 20
21 ConnectionEventTracker::ConnectionEventTracker() = default; 21 ConnectionEventTracker::ConnectionEventTracker() = default;
22 22
23 ConnectionEventTracker::~ConnectionEventTracker() { 23 ConnectionEventTracker::~ConnectionEventTracker() {
24 UMA_HISTOGRAM_ENUMERATION("GCM.PendingConnectionEventsAtShutdown", 24 UMA_HISTOGRAM_ENUMERATION("GCM.PendingConnectionEventsAtShutdown",
25 completed_events_.size(), kMaxClientEvents + 1); 25 completed_events_.size(), kMaxClientEvents + 1);
26 } 26 }
27 27
28 bool ConnectionEventTracker::IsEventInProgress() const {
29 return current_event_.has_time_connection_started_ms();
30 }
31
28 void ConnectionEventTracker::StartConnectionAttempt() { 32 void ConnectionEventTracker::StartConnectionAttempt() {
29 // TODO(harkness): Can we dcheck here that there is not an in progress 33 // TODO(harkness): Can we dcheck here that there is not an in progress
30 // connection? 34 // connection?
31 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime()); 35 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime());
32 // The connection type is passed to the server and stored there, so the 36 // The connection type is passed to the server and stored there, so the
33 // values should remain consistent. 37 // values should remain consistent.
34 current_event_.set_network_type( 38 current_event_.set_network_type(
35 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType())); 39 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType()));
36 } 40 }
37 41
38 void ConnectionEventTracker::EndConnectionAttempt() { 42 void ConnectionEventTracker::EndConnectionAttempt() {
39 // TODO(harkness): Modify tests so that we can put a DCHECK here. 43 DCHECK(IsEventInProgress());
44
40 if (completed_events_.size() == kMaxClientEvents) { 45 if (completed_events_.size() == kMaxClientEvents) {
41 // Don't let the completed events grow beyond the max. 46 // Don't let the completed events grow beyond the max.
42 completed_events_.pop_front(); 47 completed_events_.pop_front();
43 number_discarded_events_++; 48 number_discarded_events_++;
44 } 49 }
45 50
46 // Current event is now completed, so add it to our list of completed events. 51 // 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()); 52 current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime());
48 completed_events_.push_back(current_event_); 53 completed_events_.push_back(current_event_);
49 current_event_.Clear(); 54 current_event_.Clear();
50 } 55 }
51 56
52 void ConnectionEventTracker::ConnectionAttemptSucceeded() { 57 void ConnectionEventTracker::ConnectionAttemptSucceeded() {
53 // Record the successful connection so information about it can be sent in the 58 // Record the successful connection so information about it can be sent in the
54 // next login request. If there is a login failure, this will need to be 59 // next login request. If there is a login failure, this will need to be
55 // updated to a failed connection. 60 // updated to a failed connection.
56 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION); 61 current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 mcs_proto::ClientEvent* event = request->add_client_event(); 95 mcs_proto::ClientEvent* event = request->add_client_event();
91 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS); 96 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS);
92 event->set_number_discarded_events(number_discarded_events_); 97 event->set_number_discarded_events(number_discarded_events_);
93 } 98 }
94 99
95 for (const mcs_proto::ClientEvent& event : completed_events_) 100 for (const mcs_proto::ClientEvent& event : completed_events_)
96 request->add_client_event()->CopyFrom(event); 101 request->add_client_event()->CopyFrom(event);
97 } 102 }
98 103
99 } // namespace gcm 104 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/connection_event_tracker.h ('k') | google_apis/gcm/engine/connection_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698