Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / engine / fake_connection_factory.cc
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.
4
5 #include "google_apis/gcm/engine/fake_connection_factory.h"
6
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"
10
11 namespace gcm {
12
13 FakeConnectionFactory::FakeConnectionFactory()
14     : reconnect_pending_(false),
15       delay_reconnect_(false) {
16 }
17
18 FakeConnectionFactory::~FakeConnectionFactory() {
19 }
20
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,
27                                                       write_callback));
28 }
29
30 ConnectionHandler* FakeConnectionFactory::GetConnectionHandler() const {
31   return connection_handler_.get();
32 }
33
34 void FakeConnectionFactory::Connect() {
35   mcs_proto::LoginRequest login_request;
36   request_builder_.Run(&login_request);
37   connection_handler_->Init(login_request, NULL);
38 }
39
40 bool FakeConnectionFactory::IsEndpointReachable() const {
41   return connection_handler_.get() && connection_handler_->CanSendMessage();
42 }
43
44 base::TimeTicks FakeConnectionFactory::NextRetryAttempt() const {
45   return base::TimeTicks();
46 }
47
48 void FakeConnectionFactory::SignalConnectionReset(
49     ConnectionResetReason reason) {
50   if (!delay_reconnect_)
51     Connect();
52   else
53     reconnect_pending_ = true;
54 }
55
56 }  // namespace gcm