[GCM] Add heartbeat manager and reconnection logic due to heartbeat failure
[chromium-blink-merge.git] / google_apis / gcm / engine / fake_connection_factory.cc
blob084ff663591522092f504e0e25d1425c87821ba8
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
3 // found in the LICENSE file.
5 #include "google_apis/gcm/engine/fake_connection_factory.h"
7 #include "google_apis/gcm/engine/fake_connection_handler.h"
8 #include "google_apis/gcm/protocol/mcs.pb.h"
9 #include "net/socket/stream_socket.h"
11 namespace gcm {
13 FakeConnectionFactory::FakeConnectionFactory() {
16 FakeConnectionFactory::~FakeConnectionFactory() {
19 void FakeConnectionFactory::Initialize(
20 const BuildLoginRequestCallback& request_builder,
21 const ConnectionHandler::ProtoReceivedCallback& read_callback,
22 const ConnectionHandler::ProtoSentCallback& write_callback) {
23 request_builder_ = request_builder;
24 connection_handler_.reset(new FakeConnectionHandler(read_callback,
25 write_callback));
28 ConnectionHandler* FakeConnectionFactory::GetConnectionHandler() const {
29 return connection_handler_.get();
32 void FakeConnectionFactory::Connect() {
33 mcs_proto::LoginRequest login_request;
34 request_builder_.Run(&login_request);
35 connection_handler_->Init(login_request, NULL);
38 bool FakeConnectionFactory::IsEndpointReachable() const {
39 return connection_handler_.get() && connection_handler_->CanSendMessage();
42 base::TimeTicks FakeConnectionFactory::NextRetryAttempt() const {
43 return base::TimeTicks();
46 void FakeConnectionFactory::SignalConnectionReset() {
47 Connect();
50 } // namespace gcm