Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
| 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 const int kMaxClientEvents = 30; | |
|
Nicolas Zea
2016/12/01 18:51:49
nit: newline after
Peter Beverloo
2016/12/02 15:19:13
nit: constexpr size_t kMaxClientEvents
(std::dequ
harkness
2016/12/05 15:39:00
Done.
harkness
2016/12/05 15:39:00
Done.
| |
| 15 } | |
|
Nicolas Zea
2016/12/01 18:51:49
nit:
} // namespace
harkness
2016/12/05 15:39:00
Done.
| |
| 16 | |
| 17 namespace gcm { | |
| 18 | |
| 19 ConnectionEventTracker::ConnectionEventTracker() {} | |
|
Peter Beverloo
2016/12/02 15:19:13
{} --> = default;
harkness
2016/12/05 15:39:00
Done.
| |
| 20 | |
| 21 ConnectionEventTracker::~ConnectionEventTracker() { | |
| 22 // If there is currently a successful connection that is being closed as a | |
| 23 // result of the shutdown, mark the connection as completed. | |
| 24 if (current_event_.type() == mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION) | |
| 25 EndConnectionAttempt(); | |
|
Peter Beverloo
2016/12/02 15:19:13
Delete this and just have the default destructor.
harkness
2016/12/05 15:39:00
My original plan was to queue this for writing (on
| |
| 26 } | |
| 27 | |
| 28 void ConnectionEventTracker::StartConnectionAttempt() { | |
| 29 // TODO(harkness): Can we dcheck here that there is not an in progress | |
| 30 // connection? | |
|
Peter Beverloo
2016/12/02 15:19:13
I suppose this question relates to the rest of the
harkness
2016/12/05 15:39:00
It's mostly a TODO for me to follow up with zea. I
| |
| 31 current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime()); | |
| 32 current_event_.set_network_type(network_type_); | |
| 33 } | |
| 34 | |
| 35 void ConnectionEventTracker::EndConnectionAttempt() { | |
| 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_.resize(0); | |
|
Peter Beverloo
2016/12/02 15:19:13
nit: why not clear()?
harkness
2016/12/05 15:39:00
I was aiming for a method that would deallocate th
| |
| 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(current_event_.type() == | |
| 65 mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION); | |
|
Peter Beverloo
2016/12/02 15:19:13
nit: I think we should be able to use DCHECK_EQ()
harkness
2016/12/05 15:39:00
Done.
| |
| 66 | |
| 67 current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION); | |
| 68 current_event_.clear_time_connection_established_ms(); | |
| 69 // TODO(harkness): What error code should be used here? | |
|
harkness
2016/12/01 10:34:34
Options I'm considering are ERR_ACCESS_DENIED and
Nicolas Zea
2016/12/01 18:51:49
You're currently only calling this from SignalConn
harkness
2016/12/05 15:39:00
That sounds good, thanks!
| |
| 70 } | |
| 71 | |
| 72 void ConnectionEventTracker::ConnectionAttemptFailed(int error) { | |
| 73 DCHECK(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) { | |
|
Peter Beverloo
2016/12/02 15:19:13
pedantic nit: DCHECK(request)?
harkness
2016/12/05 15:39:00
Done.
| |
| 81 for (const mcs_proto::ClientEvent& event : completed_events_) | |
| 82 request->add_client_event()->CopyFrom(event); | |
| 83 } | |
| 84 | |
| 85 } // namespace gcm | |
| OLD | NEW |