OLD | NEW |
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 namespace mcs_proto { | 12 namespace mcs_proto { |
13 class LoginRequest; | 13 class LoginRequest; |
14 } | 14 } |
15 | 15 |
16 namespace gcm { | 16 namespace gcm { |
17 | 17 |
18 // Factory for creating a ConnectionHandler and maintaining its connection. | 18 // Factory for creating a ConnectionHandler and maintaining its connection. |
19 // The factory retains ownership of the ConnectionHandler and will enforce | 19 // The factory retains ownership of the ConnectionHandler and will enforce |
20 // backoff policies when attempting connections. | 20 // backoff policies when attempting connections. |
21 class GCM_EXPORT ConnectionFactory { | 21 class GCM_EXPORT ConnectionFactory { |
22 public: | 22 public: |
23 typedef base::Callback<void(mcs_proto::LoginRequest* login_request)> | 23 typedef base::Callback<void(mcs_proto::LoginRequest* login_request)> |
24 BuildLoginRequestCallback; | 24 BuildLoginRequestCallback; |
25 | 25 |
| 26 // Reasons for triggering a connection reset. Note that these enums are |
| 27 // consumed by a histogram, so ordering should not be modified. |
| 28 enum ConnectionResetReason { |
| 29 LOGIN_FAILURE, // Login response included an error. |
| 30 CLOSE_COMMAND, // Received a close command. |
| 31 HEARTBEAT_FAILURE, // Heartbeat was not acknowledged in time. |
| 32 SOCKET_FAILURE, // net::Socket error. |
| 33 // Count of total number of connection reset reasons. All new reset reasons |
| 34 // should be added above this line. |
| 35 CONNECTION_RESET_COUNT, |
| 36 }; |
| 37 |
26 ConnectionFactory(); | 38 ConnectionFactory(); |
27 virtual ~ConnectionFactory(); | 39 virtual ~ConnectionFactory(); |
28 | 40 |
29 // Initialize the factory, creating a connection handler with a disconnected | 41 // Initialize the factory, creating a connection handler with a disconnected |
30 // socket. Should only be called once. | 42 // socket. Should only be called once. |
31 // Upon connection: | 43 // Upon connection: |
32 // |read_callback| will be invoked with the contents of any received protobuf | 44 // |read_callback| will be invoked with the contents of any received protobuf |
33 // message. | 45 // message. |
34 // |write_callback| will be invoked anytime a message has been successfully | 46 // |write_callback| will be invoked anytime a message has been successfully |
35 // sent. Note: this just means the data was sent to the wire, not that the | 47 // sent. Note: this just means the data was sent to the wire, not that the |
(...skipping 19 matching lines...) Expand all Loading... |
55 | 67 |
56 // If in backoff, the time at which the next retry will be made. Otherwise, | 68 // If in backoff, the time at which the next retry will be made. Otherwise, |
57 // a null time, indicating either no attempt to connect has been made or no | 69 // a null time, indicating either no attempt to connect has been made or no |
58 // backoff is in progress. | 70 // backoff is in progress. |
59 virtual base::TimeTicks NextRetryAttempt() const = 0; | 71 virtual base::TimeTicks NextRetryAttempt() const = 0; |
60 | 72 |
61 // Manually reset the connection. This can occur if an application specific | 73 // Manually reset the connection. This can occur if an application specific |
62 // event forced a reset (e.g. server sends a close connection response). | 74 // event forced a reset (e.g. server sends a close connection response). |
63 // If the last connection was made within kConnectionResetWindowSecs, the old | 75 // If the last connection was made within kConnectionResetWindowSecs, the old |
64 // backoff is restored, else a new backoff kicks off. | 76 // backoff is restored, else a new backoff kicks off. |
65 virtual void SignalConnectionReset() = 0; | 77 virtual void SignalConnectionReset(ConnectionResetReason reason) = 0; |
66 }; | 78 }; |
67 | 79 |
68 } // namespace gcm | 80 } // namespace gcm |
69 | 81 |
70 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_ | 82 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_H_ |
OLD | NEW |