| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ | 6 #define COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/gcm_driver/gcm_client.h" | 13 #include "components/gcm_driver/gcm_client.h" |
| 14 #include "components/gcm_driver/gcm_message_status.h" |
| 14 #include "components/gcm_driver/gcm_stats_recorder_impl.h" | 15 #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class SequencedTaskRunner; | 18 class SequencedTaskRunner; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace gcm { | 21 namespace gcm { |
| 21 | 22 |
| 22 class FakeGCMClient : public GCMClient { | 23 class FakeGCMClient : public GCMClient { |
| 23 public: | 24 public: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 51 std::unique_ptr<Encryptor> encryptor, | 52 std::unique_ptr<Encryptor> encryptor, |
| 52 Delegate* delegate) override; | 53 Delegate* delegate) override; |
| 53 void Start(StartMode start_mode) override; | 54 void Start(StartMode start_mode) override; |
| 54 void Stop() override; | 55 void Stop() override; |
| 55 void Register(const linked_ptr<RegistrationInfo>& registration_info) override; | 56 void Register(const linked_ptr<RegistrationInfo>& registration_info) override; |
| 56 void Unregister( | 57 void Unregister( |
| 57 const linked_ptr<RegistrationInfo>& registration_info) override; | 58 const linked_ptr<RegistrationInfo>& registration_info) override; |
| 58 void Send(const std::string& app_id, | 59 void Send(const std::string& app_id, |
| 59 const std::string& receiver_id, | 60 const std::string& receiver_id, |
| 60 const OutgoingMessage& message) override; | 61 const OutgoingMessage& message) override; |
| 62 void SendMessageReceipt(const std::string& message_id, |
| 63 const std::string& app_id, |
| 64 GCMMessageStatus status) override; |
| 61 void RecordDecryptionFailure(const std::string& app_id, | 65 void RecordDecryptionFailure(const std::string& app_id, |
| 62 GCMEncryptionProvider::DecryptionResult result) | 66 GCMEncryptionProvider::DecryptionResult result) |
| 63 override; | 67 override; |
| 64 void SetRecording(bool recording) override; | 68 void SetRecording(bool recording) override; |
| 65 void ClearActivityLogs() override; | 69 void ClearActivityLogs() override; |
| 66 GCMStatistics GetStatistics() const override; | 70 GCMStatistics GetStatistics() const override; |
| 67 void SetAccountTokens( | 71 void SetAccountTokens( |
| 68 const std::vector<AccountTokenInfo>& account_tokens) override; | 72 const std::vector<AccountTokenInfo>& account_tokens) override; |
| 69 void UpdateAccountMapping(const AccountMapping& account_mapping) override; | 73 void UpdateAccountMapping(const AccountMapping& account_mapping) override; |
| 70 void RemoveAccountMapping(const std::string& account_id) override; | 74 void RemoveAccountMapping(const std::string& account_id) override; |
| 71 void SetLastTokenFetchTime(const base::Time& time) override; | 75 void SetLastTokenFetchTime(const base::Time& time) override; |
| 72 void UpdateHeartbeatTimer(std::unique_ptr<base::Timer> timer) override; | 76 void UpdateHeartbeatTimer(std::unique_ptr<base::Timer> timer) override; |
| 73 void AddInstanceIDData(const std::string& app_id, | 77 void AddInstanceIDData(const std::string& app_id, |
| 74 const std::string& instance_id, | 78 const std::string& instance_id, |
| 75 const std::string& extra_data) override; | 79 const std::string& extra_data) override; |
| 76 void RemoveInstanceIDData(const std::string& app_id) override; | 80 void RemoveInstanceIDData(const std::string& app_id) override; |
| 77 void GetInstanceIDData(const std::string& app_id, | 81 void GetInstanceIDData(const std::string& app_id, |
| 78 std::string* instance_id, | 82 std::string* instance_id, |
| 79 std::string* extra_data) override; | 83 std::string* extra_data) override; |
| 80 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; | 84 void AddHeartbeatInterval(const std::string& scope, int interval_ms) override; |
| 81 void RemoveHeartbeatInterval(const std::string& scope) override; | 85 void RemoveHeartbeatInterval(const std::string& scope) override; |
| 82 | 86 |
| 83 // Initiate the start that has been delayed. | 87 // Initiate the start that has been delayed. |
| 84 // Called on UI thread. | 88 // Called on UI thread. |
| 85 void PerformDelayedStart(); | 89 void PerformDelayedStart(); |
| 86 | 90 |
| 87 // Simulate receiving something from the server. | 91 // Simulate receiving something from the server. |
| 88 // Called on UI thread. | 92 // Called on UI thread. |
| 89 void ReceiveMessage(const std::string& app_id, | 93 void ReceiveMessage(const std::string& app_id, |
| 94 const std::string& message_id, |
| 90 const IncomingMessage& message); | 95 const IncomingMessage& message); |
| 91 void DeleteMessages(const std::string& app_id); | 96 void DeleteMessages(const std::string& app_id); |
| 92 | 97 |
| 93 void set_start_mode_overridding(StartModeOverridding overridding) { | 98 void set_start_mode_overridding(StartModeOverridding overridding) { |
| 94 start_mode_overridding_ = overridding; | 99 start_mode_overridding_ = overridding; |
| 95 } | 100 } |
| 96 | 101 |
| 102 const std::string& receipt_app_id() { return receipt_app_id_; } |
| 103 const std::string& receipt_message_id() { return receipt_message_id_; } |
| 104 GCMMessageStatus receipt_status() { return receipt_status_; } |
| 105 |
| 97 private: | 106 private: |
| 98 // Called on IO thread. | 107 // Called on IO thread. |
| 99 void DoStart(); | 108 void DoStart(); |
| 100 void Started(); | 109 void Started(); |
| 101 void RegisterFinished( | 110 void RegisterFinished( |
| 102 const linked_ptr<RegistrationInfo>& registration_info, | 111 const linked_ptr<RegistrationInfo>& registration_info, |
| 103 const std::string& registrion_id); | 112 const std::string& registrion_id); |
| 104 void UnregisterFinished( | 113 void UnregisterFinished( |
| 105 const linked_ptr<RegistrationInfo>& registration_info); | 114 const linked_ptr<RegistrationInfo>& registration_info); |
| 106 void SendFinished(const std::string& app_id, const OutgoingMessage& message); | 115 void SendFinished(const std::string& app_id, const OutgoingMessage& message); |
| 107 void MessageReceived(const std::string& app_id, | 116 void MessageReceived(const std::string& app_id, |
| 108 const IncomingMessage& message); | 117 const IncomingMessage& message, |
| 118 const GCMClient::MessageReceiptCallback& callback); |
| 109 void MessagesDeleted(const std::string& app_id); | 119 void MessagesDeleted(const std::string& app_id); |
| 110 void MessageSendError(const std::string& app_id, | 120 void MessageSendError(const std::string& app_id, |
| 111 const SendErrorDetails& send_error_details); | 121 const SendErrorDetails& send_error_details); |
| 112 void SendAcknowledgement(const std::string& app_id, | 122 void SendAcknowledgement(const std::string& app_id, |
| 113 const std::string& message_id); | 123 const std::string& message_id); |
| 114 | 124 |
| 115 Delegate* delegate_; | 125 Delegate* delegate_; |
| 116 std::string product_category_for_subtypes_; | 126 std::string product_category_for_subtypes_; |
| 117 bool started_; | 127 bool started_; |
| 118 StartMode start_mode_; | 128 StartMode start_mode_; |
| 119 StartModeOverridding start_mode_overridding_; | 129 StartModeOverridding start_mode_overridding_; |
| 120 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 130 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
| 121 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 131 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
| 122 std::map<std::string, std::pair<std::string, std::string>> instance_id_data_; | 132 std::map<std::string, std::pair<std::string, std::string>> instance_id_data_; |
| 123 GCMStatsRecorderImpl recorder_; | 133 GCMStatsRecorderImpl recorder_; |
| 134 std::string receipt_app_id_; |
| 135 std::string receipt_message_id_; |
| 136 GCMMessageStatus receipt_status_; |
| 124 base::WeakPtrFactory<FakeGCMClient> weak_ptr_factory_; | 137 base::WeakPtrFactory<FakeGCMClient> weak_ptr_factory_; |
| 125 | 138 |
| 126 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient); | 139 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient); |
| 127 }; | 140 }; |
| 128 | 141 |
| 129 } // namespace gcm | 142 } // namespace gcm |
| 130 | 143 |
| 131 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ | 144 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_ |
| OLD | NEW |