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

Side by Side Diff: google_apis/gcm/engine/connection_handler_impl.cc

Issue 118133003: [GCM] Add heartbeat manager and reconnection logic due to heartbeat failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unrevert fixes Created 6 years, 11 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 #include "google_apis/gcm/engine/connection_handler_impl.h" 5 #include "google_apis/gcm/engine/connection_handler_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "google/protobuf/io/coded_stream.h" 8 #include "google/protobuf/io/coded_stream.h"
9 #include "google_apis/gcm/base/mcs_util.h" 9 #include "google_apis/gcm/base/mcs_util.h"
10 #include "google_apis/gcm/base/socket_stream.h" 10 #include "google_apis/gcm/base/socket_stream.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 write_callback_(write_callback), 45 write_callback_(write_callback),
46 connection_callback_(connection_callback), 46 connection_callback_(connection_callback),
47 weak_ptr_factory_(this) { 47 weak_ptr_factory_(this) {
48 } 48 }
49 49
50 ConnectionHandlerImpl::~ConnectionHandlerImpl() { 50 ConnectionHandlerImpl::~ConnectionHandlerImpl() {
51 } 51 }
52 52
53 void ConnectionHandlerImpl::Init( 53 void ConnectionHandlerImpl::Init(
54 const mcs_proto::LoginRequest& login_request, 54 const mcs_proto::LoginRequest& login_request,
55 scoped_ptr<net::StreamSocket> socket) { 55 net::StreamSocket* socket) {
56 DCHECK(!read_callback_.is_null()); 56 DCHECK(!read_callback_.is_null());
57 DCHECK(!write_callback_.is_null()); 57 DCHECK(!write_callback_.is_null());
58 DCHECK(!connection_callback_.is_null()); 58 DCHECK(!connection_callback_.is_null());
59 59
60 // Invalidate any previously outstanding reads. 60 // Invalidate any previously outstanding reads.
61 weak_ptr_factory_.InvalidateWeakPtrs(); 61 weak_ptr_factory_.InvalidateWeakPtrs();
62 62
63 handshake_complete_ = false; 63 handshake_complete_ = false;
64 message_tag_ = 0; 64 message_tag_ = 0;
65 message_size_ = 0; 65 message_size_ = 0;
66 socket_ = socket.Pass(); 66 socket_ = socket;
67 input_stream_.reset(new SocketInputStream(socket_.get())); 67 input_stream_.reset(new SocketInputStream(socket_));
68 output_stream_.reset(new SocketOutputStream(socket_.get())); 68 output_stream_.reset(new SocketOutputStream(socket_));
69 69
70 Login(login_request); 70 Login(login_request);
71 } 71 }
72 72
73 bool ConnectionHandlerImpl::CanSendMessage() const { 73 bool ConnectionHandlerImpl::CanSendMessage() const {
74 return handshake_complete_ && output_stream_.get() && 74 return handshake_complete_ && output_stream_.get() &&
75 output_stream_->GetState() == SocketOutputStream::EMPTY; 75 output_stream_->GetState() == SocketOutputStream::EMPTY;
76 } 76 }
77 77
78 void ConnectionHandlerImpl::SendMessage( 78 void ConnectionHandlerImpl::SendMessage(
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 386 }
387 387
388 void ConnectionHandlerImpl::OnTimeout() { 388 void ConnectionHandlerImpl::OnTimeout() {
389 LOG(ERROR) << "Timed out waiting for GCM Protocol buffer."; 389 LOG(ERROR) << "Timed out waiting for GCM Protocol buffer.";
390 CloseConnection(); 390 CloseConnection();
391 connection_callback_.Run(net::ERR_TIMED_OUT); 391 connection_callback_.Run(net::ERR_TIMED_OUT);
392 } 392 }
393 393
394 void ConnectionHandlerImpl::CloseConnection() { 394 void ConnectionHandlerImpl::CloseConnection() {
395 DVLOG(1) << "Closing connection."; 395 DVLOG(1) << "Closing connection.";
396 read_callback_.Reset();
397 write_callback_.Reset();
398 read_timeout_timer_.Stop(); 396 read_timeout_timer_.Stop();
399 socket_->Disconnect(); 397 socket_->Disconnect();
400 input_stream_.reset(); 398 input_stream_.reset();
401 output_stream_.reset(); 399 output_stream_.reset();
402 weak_ptr_factory_.InvalidateWeakPtrs(); 400 weak_ptr_factory_.InvalidateWeakPtrs();
403 } 401 }
404 402
405 } // namespace gcm 403 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/connection_handler_impl.h ('k') | google_apis/gcm/engine/connection_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698