[GCM] Add ConnectionListener support, and hook up to debug page
[chromium-blink-merge.git] / google_apis / gcm / engine / fake_connection_factory.cc
blob51447b9e5a8abaf4210d9ff8872bc726f31c7123
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) {
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,
27 write_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 std::string FakeConnectionFactory::GetConnectionStateString() const {
45 return "";
48 base::TimeTicks FakeConnectionFactory::NextRetryAttempt() const {
49 return base::TimeTicks();
52 void FakeConnectionFactory::SignalConnectionReset(
53 ConnectionResetReason reason) {
54 if (!delay_reconnect_)
55 Connect();
56 else
57 reconnect_pending_ = true;
60 void FakeConnectionFactory::SetConnectionListener(
61 ConnectionListener* listener) {
64 } // namespace gcm