Index: extensions/browser/api/cast_channel/cast_socket.h |
diff --git a/extensions/browser/api/cast_channel/cast_socket.h b/extensions/browser/api/cast_channel/cast_socket.h |
index 7bcd513bba76ea7554084dc3512c29ebf87d0ffa..14c558cb09fa6481c159ccbad02a9715f42785c8 100644 |
--- a/extensions/browser/api/cast_channel/cast_socket.h |
+++ b/extensions/browser/api/cast_channel/cast_socket.h |
@@ -9,11 +9,9 @@ |
#include <string> |
#include "base/basictypes.h" |
-#include "base/callback.h" |
#include "base/cancelable_callback.h" |
#include "base/gtest_prod_util.h" |
#include "base/memory/ref_counted.h" |
-#include "base/memory/weak_ptr.h" |
#include "base/threading/thread_checker.h" |
#include "base/timer/timer.h" |
#include "extensions/browser/api/api_resource.h" |
@@ -45,17 +43,14 @@ class CastMessage; |
// |
// NOTE: Not called "CastChannel" to reduce confusion with the generated API |
// code. |
-class CastSocket : public ApiResource, |
- public base::SupportsWeakPtr<CastSocket> { |
+class CastSocket : public ApiResource { |
public: |
// Object to be informed of incoming messages and errors. |
class Delegate { |
public: |
// An error occurred on the channel. |
- // It is fine to delete the socket in this callback. |
virtual void OnError(const CastSocket* socket, ChannelError error) = 0; |
// A message was received on the channel. |
- // Do NOT delete the socket in this callback. |
virtual void OnMessage(const CastSocket* socket, |
const MessageInfo& message) = 0; |
@@ -72,6 +67,8 @@ class CastSocket : public ApiResource, |
CastSocket::Delegate* delegate, |
net::NetLog* net_log, |
const base::TimeDelta& connect_timeout); |
+ |
+ // Ensures that the socket is closed. |
virtual ~CastSocket(); |
// The IP endpoint for the destination of the channel. |
@@ -221,6 +218,7 @@ class CastSocket : public ApiResource, |
int DoSslConnectComplete(int result); |
int DoAuthChallengeSend(); |
int DoAuthChallengeSendComplete(int result); |
+ void DoAuthChallengeSendWriteComplete(int result); |
int DoAuthChallengeReplyComplete(int result); |
///////////////////////////////////////////////////////////////////////////// |
@@ -266,9 +264,14 @@ class CastSocket : public ApiResource, |
// Parses the contents of body_read_buffer_ and sets current_message_ to |
// the message received. |
bool ProcessBody(); |
- // Closes socket, updating the error state and signaling the delegate that |
- // |error| has occurred. |
+ // Closes the socket, sets |error_state_| to |error| and signals the |
+ // delegate that |error| has occurred. |
void CloseWithError(ChannelError error); |
+ // Frees resources and cancels pending callbacks. |ready_state_| will be set |
+ // READY_STATE_CLOSED on completion. A no-op if |ready_state_| is already |
+ // READY_STATE_CLOSED. |
+ void CloseInternal(); |
+ |
// Serializes the content of message_proto (with a header) to |message_data|. |
static bool Serialize(const CastMessage& message_proto, |
std::string* message_data); |
@@ -324,6 +327,8 @@ class CastSocket : public ApiResource, |
// Callback invoked when the socket is connected or fails to connect. |
net::CompletionCallback connect_callback_; |
+ // Callback invoked by |connect_timeout_timer_| to cancel the connection. |
+ base::CancelableClosure connect_timeout_callback_; |
// Duration to wait before timing out. |
base::TimeDelta connect_timeout_; |
// Timer invoked when the connection has timed out. |
@@ -343,6 +348,16 @@ class CastSocket : public ApiResource, |
// The current status of the channel. |
ReadyState ready_state_; |
+ // Task invoked to (re)start the connect loop. Canceled on entry to the |
+ // connect loop. |
+ base::CancelableClosure connect_loop_callback_; |
+ // Task invoked to send the auth challenge. Canceled when the auth challenge |
+ // has been sent. |
+ base::CancelableClosure send_auth_challenge_callback_; |
+ // Callback invoked to (re)start the read loop. Canceled on entry to the read |
+ // loop. |
+ base::CancelableClosure read_loop_callback_; |
+ |
// Holds a message to be written to the socket. |callback| is invoked when the |
// message is fully written or an error occurrs. |
struct WriteRequest { |