Roll src/third_party/WebKit 3529d49:06e8485 (svn 202554:202555)
[chromium-blink-merge.git] / google_apis / gcm / engine / fake_connection_factory.cc
blobeaec86156986e829d61e9a6265ace3a851725f7f
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()
14 : reconnect_pending_(false),
15 delay_reconnect_(false),
16 connection_listener_(nullptr) {
19 FakeConnectionFactory::~FakeConnectionFactory() {
22 void FakeConnectionFactory::Initialize(
23 const BuildLoginRequestCallback& request_builder,
24 const ConnectionHandler::ProtoReceivedCallback& read_callback,
25 const ConnectionHandler::ProtoSentCallback& write_callback) {
26 request_builder_ = request_builder;
27 connection_handler_.reset(new FakeConnectionHandler(read_callback,
28 write_callback));
31 ConnectionHandler* FakeConnectionFactory::GetConnectionHandler() const {
32 return connection_handler_.get();
35 void FakeConnectionFactory::Connect() {
36 mcs_proto::LoginRequest login_request;
37 request_builder_.Run(&login_request);
38 connection_handler_->Init(login_request, NULL);
41 bool FakeConnectionFactory::IsEndpointReachable() const {
42 return connection_handler_.get() && connection_handler_->CanSendMessage();
45 std::string FakeConnectionFactory::GetConnectionStateString() const {
46 return "";
49 base::TimeTicks FakeConnectionFactory::NextRetryAttempt() const {
50 return base::TimeTicks();
53 void FakeConnectionFactory::SignalConnectionReset(
54 ConnectionResetReason reason) {
55 if (!delay_reconnect_)
56 Connect();
57 else
58 reconnect_pending_ = true;
59 if (connection_listener_)
60 connection_listener_->OnDisconnected();
63 void FakeConnectionFactory::SetConnectionListener(
64 ConnectionListener* listener) {
65 connection_listener_ = listener;
68 } // namespace gcm