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 #ifndef GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_FACTORY_H_
6 #define GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_FACTORY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "google_apis/gcm/engine/connection_factory.h"
13 class FakeConnectionHandler
;
15 // A connection factory that mocks out real connections, using a fake connection
17 class FakeConnectionFactory
: public ConnectionFactory
{
19 FakeConnectionFactory();
20 ~FakeConnectionFactory() override
;
22 // ConnectionFactory implementation.
24 const BuildLoginRequestCallback
& request_builder
,
25 const ConnectionHandler::ProtoReceivedCallback
& read_callback
,
26 const ConnectionHandler::ProtoSentCallback
& write_callback
) override
;
27 ConnectionHandler
* GetConnectionHandler() const override
;
28 void Connect() override
;
29 bool IsEndpointReachable() const override
;
30 std::string
GetConnectionStateString() const override
;
31 base::TimeTicks
NextRetryAttempt() const override
;
32 void SignalConnectionReset(ConnectionResetReason reason
) override
;
33 void SetConnectionListener(ConnectionListener
* listener
) override
;
35 // Whether a connection reset has been triggered and is yet to run.
36 bool reconnect_pending() const { return reconnect_pending_
; }
38 // Whether connection resets should be handled immediately or delayed until
40 void set_delay_reconnect(bool should_delay
) {
41 delay_reconnect_
= should_delay
;
45 scoped_ptr
<FakeConnectionHandler
> connection_handler_
;
47 BuildLoginRequestCallback request_builder_
;
49 // Logic for handling connection resets.
50 bool reconnect_pending_
;
51 bool delay_reconnect_
;
53 ConnectionListener
* connection_listener_
;
55 DISALLOW_COPY_AND_ASSIGN(FakeConnectionFactory
);
60 #endif // GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_FACTORY_H_