Update V8 to version 4.5.32.
[chromium-blink-merge.git] / components / gcm_driver / fake_gcm_client.h
blob1f72f33628ac84a639d64354e1524789239ad196
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"
12 namespace base {
13 class SequencedTaskRunner;
16 namespace gcm {
18 class FakeGCMClient : public GCMClient {
19 public:
20 // For testing purpose.
21 enum StartModeOverridding {
22 // No change to how delay start is handled.
23 RESPECT_START_MODE,
24 // Force to delay start GCM until PerformDelayedStart is called.
25 FORCE_TO_ALWAYS_DELAY_START_GCM,
28 // Generate and return the registration ID/token based on parameters for
29 // testing verification.
30 static std::string GenerateGCMRegistrationID(
31 const std::vector<std::string>& sender_ids);
32 static std::string GenerateInstanceIDToken(
33 const std::string& authorized_entity, const std::string& scope);
35 FakeGCMClient(const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
36 const scoped_refptr<base::SequencedTaskRunner>& io_thread);
37 ~FakeGCMClient() override;
39 // Overridden from GCMClient:
40 // Called on IO thread.
41 void Initialize(
42 const ChromeBuildInfo& chrome_build_info,
43 const base::FilePath& store_path,
44 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
45 const scoped_refptr<net::URLRequestContextGetter>&
46 url_request_context_getter,
47 scoped_ptr<Encryptor> encryptor,
48 Delegate* delegate) override;
49 void Start(StartMode start_mode) override;
50 void Stop() override;
51 void Register(const linked_ptr<RegistrationInfo>& registration_info) override;
52 void Unregister(
53 const linked_ptr<RegistrationInfo>& registration_info) override;
54 void Send(const std::string& app_id,
55 const std::string& receiver_id,
56 const OutgoingMessage& message) override;
57 void SetRecording(bool recording) override;
58 void ClearActivityLogs() override;
59 GCMStatistics GetStatistics() const override;
60 void SetAccountTokens(
61 const std::vector<AccountTokenInfo>& account_tokens) override;
62 void UpdateAccountMapping(const AccountMapping& account_mapping) override;
63 void RemoveAccountMapping(const std::string& account_id) override;
64 void SetLastTokenFetchTime(const base::Time& time) override;
65 void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) override;
66 void AddInstanceIDData(const std::string& app_id,
67 const std::string& instance_id,
68 const std::string& extra_data) override;
69 void RemoveInstanceIDData(const std::string& app_id) override;
70 void GetInstanceIDData(const std::string& app_id,
71 std::string* instance_id,
72 std::string* extra_data) override;
73 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override;
74 void RemoveHeartbeatInterval(const std::string& scope) override;
76 // Initiate the start that has been delayed.
77 // Called on UI thread.
78 void PerformDelayedStart();
80 // Simulate receiving something from the server.
81 // Called on UI thread.
82 void ReceiveMessage(const std::string& app_id,
83 const IncomingMessage& message);
84 void DeleteMessages(const std::string& app_id);
86 void set_start_mode_overridding(StartModeOverridding overridding) {
87 start_mode_overridding_ = overridding;
90 private:
91 // Called on IO thread.
92 void DoStart();
93 void Started();
94 void RegisterFinished(
95 const linked_ptr<RegistrationInfo>& registration_info,
96 const std::string& registrion_id);
97 void UnregisterFinished(
98 const linked_ptr<RegistrationInfo>& registration_info);
99 void SendFinished(const std::string& app_id, const OutgoingMessage& message);
100 void MessageReceived(const std::string& app_id,
101 const IncomingMessage& message);
102 void MessagesDeleted(const std::string& app_id);
103 void MessageSendError(const std::string& app_id,
104 const SendErrorDetails& send_error_details);
105 void SendAcknowledgement(const std::string& app_id,
106 const std::string& message_id);
108 Delegate* delegate_;
109 bool started_;
110 StartMode start_mode_;
111 StartModeOverridding start_mode_overridding_;
112 scoped_refptr<base::SequencedTaskRunner> ui_thread_;
113 scoped_refptr<base::SequencedTaskRunner> io_thread_;
114 base::WeakPtrFactory<FakeGCMClient> weak_ptr_factory_;
116 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient);
119 } // namespace gcm
121 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_