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 "google_apis/gcm/gcm_client.h"
13 class SequencedTaskRunner
;
18 class FakeGCMClient
: public GCMClient
{
32 FakeGCMClient(StartMode start_mode
,
33 const scoped_refptr
<base::SequencedTaskRunner
>& ui_thread
,
34 const scoped_refptr
<base::SequencedTaskRunner
>& io_thread
);
35 virtual ~FakeGCMClient();
37 // Overridden from GCMClient:
38 // Called on IO thread.
39 virtual void Initialize(
40 const ChromeBuildInfo
& chrome_build_info
,
41 const base::FilePath
& store_path
,
42 const std::vector
<std::string
>& account_ids
,
43 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
,
44 const scoped_refptr
<net::URLRequestContextGetter
>&
45 url_request_context_getter
,
46 scoped_ptr
<Encryptor
> encryptor
,
47 Delegate
* delegate
) OVERRIDE
;
48 virtual void Start() OVERRIDE
;
49 virtual void Stop() OVERRIDE
;
50 virtual void CheckOut() OVERRIDE
;
51 virtual void Register(const std::string
& app_id
,
52 const std::vector
<std::string
>& sender_ids
) OVERRIDE
;
53 virtual void Unregister(const std::string
& app_id
) OVERRIDE
;
54 virtual void Send(const std::string
& app_id
,
55 const std::string
& receiver_id
,
56 const OutgoingMessage
& message
) OVERRIDE
;
57 virtual void SetRecording(bool recording
) OVERRIDE
;
58 virtual void ClearActivityLogs() OVERRIDE
;
59 virtual GCMStatistics
GetStatistics() const OVERRIDE
;
61 // Initiate the loading that has been delayed.
62 // Called on UI thread.
63 void PerformDelayedLoading();
65 // Simulate receiving something from the server.
66 // Called on UI thread.
67 void ReceiveMessage(const std::string
& app_id
,
68 const IncomingMessage
& message
);
69 void DeleteMessages(const std::string
& app_id
);
71 static std::string
GetRegistrationIdFromSenderIds(
72 const std::vector
<std::string
>& sender_ids
);
74 Status
status() const { return status_
; }
77 // Called on IO thread.
79 void CheckinFinished();
80 void RegisterFinished(const std::string
& app_id
,
81 const std::string
& registrion_id
);
82 void UnregisterFinished(const std::string
& app_id
);
83 void SendFinished(const std::string
& app_id
, const OutgoingMessage
& message
);
84 void MessageReceived(const std::string
& app_id
,
85 const IncomingMessage
& message
);
86 void MessagesDeleted(const std::string
& app_id
);
87 void MessageSendError(const std::string
& app_id
,
88 const SendErrorDetails
& send_error_details
);
92 StartMode start_mode_
;
93 scoped_refptr
<base::SequencedTaskRunner
> ui_thread_
;
94 scoped_refptr
<base::SequencedTaskRunner
> io_thread_
;
95 base::WeakPtrFactory
<FakeGCMClient
> weak_ptr_factory_
;
97 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient
);
102 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_