Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / engine / connection_handler_impl.cc
index aea1683..be2c313 100644 (file)
@@ -27,8 +27,7 @@ const int kSizePacketLenMin = 1;
 const int kSizePacketLenMax = 2;
 
 // The current MCS protocol version.
-// TODO(zea): bump to 41 once the server supports it.
-const int kMCSVersion = 38;
+const int kMCSVersion = 41;
 
 }  // namespace
 
@@ -38,6 +37,7 @@ ConnectionHandlerImpl::ConnectionHandlerImpl(
     const ProtoSentCallback& write_callback,
     const ConnectionChangedCallback& connection_callback)
     : read_timeout_(read_timeout),
+      socket_(NULL),
       handshake_complete_(false),
       message_tag_(0),
       message_size_(0),
@@ -70,6 +70,10 @@ void ConnectionHandlerImpl::Init(
   Login(login_request);
 }
 
+void ConnectionHandlerImpl::Reset() {
+  CloseConnection();
+}
+
 bool ConnectionHandlerImpl::CanSendMessage() const {
   return handshake_complete_ && output_stream_.get() &&
       output_stream_->GetState() == SocketOutputStream::EMPTY;
@@ -258,7 +262,8 @@ void ConnectionHandlerImpl::OnGotVersion() {
     CodedInputStream coded_input_stream(input_stream_.get());
     coded_input_stream.ReadRaw(&version, 1);
   }
-  if (version < kMCSVersion) {
+  // TODO(zea): remove this when the server is ready.
+  if (version < kMCSVersion && version != 38) {
     LOG(ERROR) << "Invalid GCM version response: " << static_cast<int>(version);
     connection_callback_.Run(net::ERR_FAILED);
     return;
@@ -394,7 +399,9 @@ void ConnectionHandlerImpl::OnTimeout() {
 void ConnectionHandlerImpl::CloseConnection() {
   DVLOG(1) << "Closing connection.";
   read_timeout_timer_.Stop();
-  socket_->Disconnect();
+  if (socket_)
+    socket_->Disconnect();
+  socket_ = NULL;
   input_stream_.reset();
   output_stream_.reset();
   weak_ptr_factory_.InvalidateWeakPtrs();