1 // Copyright 2014 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 COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_
6 #define COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "components/gcm_driver/gcm_client.h"
13 class SequencedTaskRunner
;
18 class FakeGCMClient
: public GCMClient
{
20 // For testing purpose.
21 enum StartModeOverridding
{
22 // No change to how delay start is handled.
24 // Force to delay start GCM until PerformDelayedStart is called.
25 FORCE_TO_ALWAYS_DELAY_START_GCM
,
28 FakeGCMClient(const scoped_refptr
<base::SequencedTaskRunner
>& ui_thread
,
29 const scoped_refptr
<base::SequencedTaskRunner
>& io_thread
);
30 ~FakeGCMClient() override
;
32 // Overridden from GCMClient:
33 // Called on IO thread.
35 const ChromeBuildInfo
& chrome_build_info
,
36 const base::FilePath
& store_path
,
37 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
,
38 const scoped_refptr
<net::URLRequestContextGetter
>&
39 url_request_context_getter
,
40 scoped_ptr
<Encryptor
> encryptor
,
41 Delegate
* delegate
) override
;
42 void Start(StartMode start_mode
) override
;
44 void Register(const std::string
& app_id
,
45 const std::vector
<std::string
>& sender_ids
) override
;
46 void Unregister(const std::string
& app_id
) override
;
47 void Send(const std::string
& app_id
,
48 const std::string
& receiver_id
,
49 const OutgoingMessage
& message
) override
;
50 void SetRecording(bool recording
) override
;
51 void ClearActivityLogs() override
;
52 GCMStatistics
GetStatistics() const override
;
53 void SetAccountTokens(
54 const std::vector
<AccountTokenInfo
>& account_tokens
) override
;
55 void UpdateAccountMapping(const AccountMapping
& account_mapping
) override
;
56 void RemoveAccountMapping(const std::string
& account_id
) override
;
57 void SetLastTokenFetchTime(const base::Time
& time
) override
;
58 void UpdateHeartbeatTimer(scoped_ptr
<base::Timer
> timer
) override
;
60 // Initiate the start that has been delayed.
61 // Called on UI thread.
62 void PerformDelayedStart();
64 // Simulate receiving something from the server.
65 // Called on UI thread.
66 void ReceiveMessage(const std::string
& app_id
,
67 const IncomingMessage
& message
);
68 void DeleteMessages(const std::string
& app_id
);
70 std::string
GetRegistrationIdFromSenderIds(
71 const std::vector
<std::string
>& sender_ids
) const;
73 void set_start_mode_overridding(StartModeOverridding overridding
) {
74 start_mode_overridding_
= overridding
;
78 // Called on IO thread.
81 void RegisterFinished(const std::string
& app_id
,
82 const std::string
& registrion_id
);
83 void UnregisterFinished(const std::string
& app_id
);
84 void SendFinished(const std::string
& app_id
, const OutgoingMessage
& message
);
85 void MessageReceived(const std::string
& app_id
,
86 const IncomingMessage
& message
);
87 void MessagesDeleted(const std::string
& app_id
);
88 void MessageSendError(const std::string
& app_id
,
89 const SendErrorDetails
& send_error_details
);
90 void SendAcknowledgement(const std::string
& app_id
,
91 const std::string
& message_id
);
95 StartMode start_mode_
;
96 StartModeOverridding start_mode_overridding_
;
97 scoped_refptr
<base::SequencedTaskRunner
> ui_thread_
;
98 scoped_refptr
<base::SequencedTaskRunner
> io_thread_
;
99 base::WeakPtrFactory
<FakeGCMClient
> weak_ptr_factory_
;
101 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient
);
106 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_