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

Unified Diff: google_apis/gcm/engine/connection_factory_impl.cc

Issue 317723004: [GCM] Add ConnectionListener support, and hook up to debug page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gcm/engine/connection_factory_impl.cc
diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc
index bab0a95d90e656c73a81057a263b685f015991ce..92186c8d97c1a4448443d761d0bb5a03739d59e1 100644
--- a/google_apis/gcm/engine/connection_factory_impl.cc
+++ b/google_apis/gcm/engine/connection_factory_impl.cc
@@ -59,6 +59,7 @@ ConnectionFactoryImpl::ConnectionFactoryImpl(
waiting_for_backoff_(false),
logging_in_(false),
recorder_(recorder),
+ listener_(NULL),
weak_ptr_factory_(this) {
DCHECK_GE(mcs_endpoints_.size(), 1U);
}
@@ -140,6 +141,18 @@ bool ConnectionFactoryImpl::IsEndpointReachable() const {
return connection_handler_ && connection_handler_->CanSendMessage();
}
+std::string ConnectionFactoryImpl::GetConnectionStateString() const {
+ if (IsEndpointReachable())
+ return "CONNECTED";
fgorski 2014/06/05 00:03:11 the list of bool variables begs for a state enum..
Nicolas Zea 2014/06/05 20:17:27 The problem is that they are not mutually exclusiv
+ if (logging_in_)
+ return "LOGGING IN";
+ if (connecting_)
+ return "CONNECTING";
+ if (waiting_for_backoff_)
+ return "WAITING FOR BACKOFF";
+ return "NOT CONNECTED";
+}
+
void ConnectionFactoryImpl::SignalConnectionReset(
ConnectionResetReason reason) {
// A failure can trigger multiple resets, so no need to do anything if a
@@ -149,6 +162,9 @@ void ConnectionFactoryImpl::SignalConnectionReset(
return;
}
+ if (listener_)
+ listener_->OnDisconnected();
+
UMA_HISTOGRAM_ENUMERATION("GCM.ConnectionResetReason",
reason,
CONNECTION_RESET_COUNT);
@@ -202,6 +218,11 @@ void ConnectionFactoryImpl::SignalConnectionReset(
Connect();
}
+void ConnectionFactoryImpl::SetConnectionListener(
+ ConnectionListener* listener) {
+ listener_ = listener;
+}
+
base::TimeTicks ConnectionFactoryImpl::NextRetryAttempt() const {
if (!backoff_entry_)
return base::TimeTicks();
@@ -234,6 +255,18 @@ GURL ConnectionFactoryImpl::GetCurrentEndpoint() const {
return mcs_endpoints_[next_endpoint_];
}
+net::IPEndPoint ConnectionFactoryImpl::GetCurrentIP() {
+ if (!socket_handle_.socket())
+ return net::IPEndPoint();
+
+ net::IPEndPoint ip_endpoint;
+ int result = socket_handle_.socket()->GetPeerAddress(&ip_endpoint);
+ if (result != net::OK)
+ return net::IPEndPoint();
+
+ return ip_endpoint;
+}
+
void ConnectionFactoryImpl::ConnectImpl() {
DCHECK(!IsEndpointReachable());
DCHECK(!socket_handle_.socket());
@@ -348,6 +381,9 @@ void ConnectionFactoryImpl::ConnectionHandlerCallback(int result) {
previous_backoff_.swap(backoff_entry_);
backoff_entry_->Reset();
logging_in_ = false;
+
+ if (listener_)
+ listener_->OnConnected(GetCurrentEndpoint(), GetCurrentIP());
}
// This has largely been copied from

Powered by Google App Engine
This is Rietveld 408576698