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"
13 FakeConnectionFactory::FakeConnectionFactory()
14 : reconnect_pending_(false),
15 delay_reconnect_(false) {
18 FakeConnectionFactory::~FakeConnectionFactory() {
21 void FakeConnectionFactory::Initialize(
22 const BuildLoginRequestCallback
& request_builder
,
23 const ConnectionHandler::ProtoReceivedCallback
& read_callback
,
24 const ConnectionHandler::ProtoSentCallback
& write_callback
) {
25 request_builder_
= request_builder
;
26 connection_handler_
.reset(new FakeConnectionHandler(read_callback
,
30 ConnectionHandler
* FakeConnectionFactory::GetConnectionHandler() const {
31 return connection_handler_
.get();
34 void FakeConnectionFactory::Connect() {
35 mcs_proto::LoginRequest login_request
;
36 request_builder_
.Run(&login_request
);
37 connection_handler_
->Init(login_request
, NULL
);
40 bool FakeConnectionFactory::IsEndpointReachable() const {
41 return connection_handler_
.get() && connection_handler_
->CanSendMessage();
44 base::TimeTicks
FakeConnectionFactory::NextRetryAttempt() const {
45 return base::TimeTicks();
48 void FakeConnectionFactory::SignalConnectionReset(
49 ConnectionResetReason reason
) {
50 if (!delay_reconnect_
)
53 reconnect_pending_
= true;