[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / google_apis / gcm / engine / fake_connection_factory.cc
blob88bbc51be530031a84eef0b0fb5d5aaf5ba54d2e
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 base::TimeTicks FakeConnectionFactory::NextRetryAttempt() const {
45 return base::TimeTicks();
48 void FakeConnectionFactory::SignalConnectionReset(
49 ConnectionResetReason reason) {
50 if (!delay_reconnect_)
51 Connect();
52 else
53 reconnect_pending_ = true;
56 } // namespace gcm