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

Side by Side Diff: google_apis/gcm/engine/connection_factory.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_ 5 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_
6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_ 6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_
7 7
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "google_apis/gcm/base/gcm_export.h" 9 #include "google_apis/gcm/base/gcm_export.h"
10 #include "google_apis/gcm/engine/connection_handler.h" 10 #include "google_apis/gcm/engine/connection_handler.h"
11 11
12 class GURL;
13
14 namespace net {
15 class IPEndPoint;
16 }
17
12 namespace mcs_proto { 18 namespace mcs_proto {
13 class LoginRequest; 19 class LoginRequest;
14 } 20 }
15 21
16 namespace gcm { 22 namespace gcm {
17 23
18 // Factory for creating a ConnectionHandler and maintaining its connection. 24 // Factory for creating a ConnectionHandler and maintaining its connection.
19 // The factory retains ownership of the ConnectionHandler and will enforce 25 // The factory retains ownership of the ConnectionHandler and will enforce
20 // backoff policies when attempting connections. 26 // backoff policies when attempting connections.
21 class GCM_EXPORT ConnectionFactory { 27 class GCM_EXPORT ConnectionFactory {
22 public: 28 public:
23 typedef base::Callback<void(mcs_proto::LoginRequest* login_request)> 29 typedef base::Callback<void(mcs_proto::LoginRequest* login_request)>
24 BuildLoginRequestCallback; 30 BuildLoginRequestCallback;
25 31
26 // Reasons for triggering a connection reset. Note that these enums are 32 // Reasons for triggering a connection reset. Note that these enums are
27 // consumed by a histogram, so ordering should not be modified. 33 // consumed by a histogram, so ordering should not be modified.
28 enum ConnectionResetReason { 34 enum ConnectionResetReason {
29 LOGIN_FAILURE, // Login response included an error. 35 LOGIN_FAILURE, // Login response included an error.
30 CLOSE_COMMAND, // Received a close command. 36 CLOSE_COMMAND, // Received a close command.
31 HEARTBEAT_FAILURE, // Heartbeat was not acknowledged in time. 37 HEARTBEAT_FAILURE, // Heartbeat was not acknowledged in time.
32 SOCKET_FAILURE, // net::Socket error. 38 SOCKET_FAILURE, // net::Socket error.
33 NETWORK_CHANGE, // NetworkChangeNotifier notified of a network change. 39 NETWORK_CHANGE, // NetworkChangeNotifier notified of a network change.
34 // Count of total number of connection reset reasons. All new reset reasons 40 // Count of total number of connection reset reasons. All new reset reasons
35 // should be added above this line. 41 // should be added above this line.
36 CONNECTION_RESET_COUNT, 42 CONNECTION_RESET_COUNT,
37 }; 43 };
38 44
45 // Listener interface to be notified of endpoint connection events.
46 class ConnectionListener {
47 public:
48 ConnectionListener();
49 virtual ~ConnectionListener();
50
51 // Notifies the listener that GCM has performed a handshake with and is now
52 // actively connected to |current_endpoint|. |socket_ip| is the resolved
53 // ip address/port through which the connection is being made.
54 virtual void OnConnected(const GURL& current_endpoint,
55 const net::IPEndPoint& socket_ip) = 0;
56
57 // Notifies the listener that the connection has been interrupted.
58 virtual void OnDisconnected() = 0;
59 };
60
39 ConnectionFactory(); 61 ConnectionFactory();
40 virtual ~ConnectionFactory(); 62 virtual ~ConnectionFactory();
41 63
42 // Initialize the factory, creating a connection handler with a disconnected 64 // Initialize the factory, creating a connection handler with a disconnected
43 // socket. Should only be called once. 65 // socket. Should only be called once.
44 // Upon connection: 66 // Upon connection:
45 // |read_callback| will be invoked with the contents of any received protobuf 67 // |read_callback| will be invoked with the contents of any received protobuf
46 // message. 68 // message.
47 // |write_callback| will be invoked anytime a message has been successfully 69 // |write_callback| will be invoked anytime a message has been successfully
48 // sent. Note: this just means the data was sent to the wire, not that the 70 // sent. Note: this just means the data was sent to the wire, not that the
(...skipping 10 matching lines...) Expand all
59 // Opens a new connection and initiates login handshake. Upon completion of 81 // Opens a new connection and initiates login handshake. Upon completion of
60 // the handshake, |read_callback| will be invoked with a valid 82 // the handshake, |read_callback| will be invoked with a valid
61 // mcs_proto::LoginResponse. 83 // mcs_proto::LoginResponse.
62 // Note: Initialize must have already been invoked. 84 // Note: Initialize must have already been invoked.
63 virtual void Connect() = 0; 85 virtual void Connect() = 0;
64 86
65 // Whether or not the MCS endpoint is currently reachable with an active 87 // Whether or not the MCS endpoint is currently reachable with an active
66 // connection. 88 // connection.
67 virtual bool IsEndpointReachable() const = 0; 89 virtual bool IsEndpointReachable() const = 0;
68 90
91 // Returns a debug string describing the connection state.
92 virtual std::string GetConnectionStateString() const = 0;
93
69 // If in backoff, the time at which the next retry will be made. Otherwise, 94 // If in backoff, the time at which the next retry will be made. Otherwise,
70 // a null time, indicating either no attempt to connect has been made or no 95 // a null time, indicating either no attempt to connect has been made or no
71 // backoff is in progress. 96 // backoff is in progress.
72 virtual base::TimeTicks NextRetryAttempt() const = 0; 97 virtual base::TimeTicks NextRetryAttempt() const = 0;
73 98
74 // Manually reset the connection. This can occur if an application specific 99 // Manually reset the connection. This can occur if an application specific
75 // event forced a reset (e.g. server sends a close connection response). 100 // event forced a reset (e.g. server sends a close connection response).
76 // If the last connection was made within kConnectionResetWindowSecs, the old 101 // If the last connection was made within kConnectionResetWindowSecs, the old
77 // backoff is restored, else a new backoff kicks off. 102 // backoff is restored, else a new backoff kicks off.
78 virtual void SignalConnectionReset(ConnectionResetReason reason) = 0; 103 virtual void SignalConnectionReset(ConnectionResetReason reason) = 0;
104
105 // Sets the current connection listener. Only one listener is supported at a
106 // time, and the listener must either outlive the connection factory or
107 // call SetConnectionListener(NULL) upon destruction.
108 virtual void SetConnectionListener(ConnectionListener* listener) = 0;
79 }; 109 };
80 110
81 } // namespace gcm 111 } // namespace gcm
82 112
83 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_ 113 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/connection_factory.cc » ('j') | google_apis/gcm/engine/connection_factory_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698