OLD | NEW |
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/time/time.h" | 8 #include "base/time/time.h" |
8 #include "net/base/network_change_notifier.h" | 9 #include "net/base/network_change_notifier.h" |
9 | 10 |
10 namespace { | 11 namespace { |
11 | 12 |
12 // 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. |
13 // This mirrors the behaviour of the GMS Core connection tracking. | 14 // This mirrors the behaviour of the GMS Core connection tracking. |
14 constexpr size_t kMaxClientEvents = 30; | 15 constexpr size_t kMaxClientEvents = 30; |
15 | 16 |
16 } // namespace | 17 } // namespace |
17 | 18 |
18 namespace gcm { | 19 namespace gcm { |
19 | 20 |
20 ConnectionEventTracker::ConnectionEventTracker() = default; | 21 ConnectionEventTracker::ConnectionEventTracker() = default; |
21 | 22 |
22 ConnectionEventTracker::~ConnectionEventTracker() = default; | 23 ConnectionEventTracker::~ConnectionEventTracker() { |
| 24 UMA_HISTOGRAM_ENUMERATION("GCM.PendingConnectionEventsAtShutdown", |
| 25 completed_events_.size(), kMaxClientEvents + 1); |
| 26 } |
23 | 27 |
24 void ConnectionEventTracker::StartConnectionAttempt() { | 28 void ConnectionEventTracker::StartConnectionAttempt() { |
25 // TODO(harkness): Can we dcheck here that there is not an in progress | 29 // TODO(harkness): Can we dcheck here that there is not an in progress |
26 // connection? | 30 // connection? |
27 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime()); | 31 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 | 32 // The connection type is passed to the server and stored there, so the |
29 // values should remain consistent. | 33 // values should remain consistent. |
30 current_event_.set_network_type( | 34 current_event_.set_network_type( |
31 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType())); | 35 static_cast<int>(net::NetworkChangeNotifier::GetConnectionType())); |
32 } | 36 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 mcs_proto::ClientEvent* event = request->add_client_event(); | 90 mcs_proto::ClientEvent* event = request->add_client_event(); |
87 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS); | 91 event->set_type(mcs_proto::ClientEvent::DISCARDED_EVENTS); |
88 event->set_number_discarded_events(number_discarded_events_); | 92 event->set_number_discarded_events(number_discarded_events_); |
89 } | 93 } |
90 | 94 |
91 for (const mcs_proto::ClientEvent& event : completed_events_) | 95 for (const mcs_proto::ClientEvent& event : completed_events_) |
92 request->add_client_event()->CopyFrom(event); | 96 request->add_client_event()->CopyFrom(event); |
93 } | 97 } |
94 | 98 |
95 } // namespace gcm | 99 } // namespace gcm |
OLD | NEW |