| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A notifier that uses p2p notifications based on XMPP push | 5 // A notifier that uses p2p notifications based on XMPP push |
| 6 // notifications. Used only for sync integration tests. | 6 // notifications. Used only for sync integration tests. |
| 7 | 7 |
| 8 #ifndef SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 8 #ifndef SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| 9 #define SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 9 #define SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "jingle/notifier/listener/talk_mediator.h" | 18 #include "jingle/notifier/base/notifier_options.h" |
| 19 #include "jingle/notifier/listener/push_client.h" |
| 18 #include "sync/notifier/sync_notifier.h" | 20 #include "sync/notifier/sync_notifier.h" |
| 19 #include "sync/syncable/model_type.h" | 21 #include "sync/syncable/model_type.h" |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| 22 class MessageLoopProxy; | 24 class MessageLoopProxy; |
| 23 } | 25 } |
| 24 | 26 |
| 27 namespace buzz { |
| 28 class XmppTaskParentInterface; |
| 29 } // namespace buzz |
| 25 | 30 |
| 26 namespace sync_notifier { | 31 namespace sync_notifier { |
| 27 | 32 |
| 28 // The channel to use for sync notifications. | 33 // The channel to use for sync notifications. |
| 29 extern const char* kSyncP2PNotificationChannel; | 34 extern const char* kSyncP2PNotificationChannel; |
| 30 | 35 |
| 31 // The intended recipient(s) of a P2P notification. | 36 // The intended recipient(s) of a P2P notification. |
| 32 enum P2PNotificationTarget { | 37 enum P2PNotificationTarget { |
| 33 NOTIFY_SELF, | 38 NOTIFY_SELF, |
| 34 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF, | 39 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // The unique ID of the client that sent the notification. | 79 // The unique ID of the client that sent the notification. |
| 75 std::string sender_id_; | 80 std::string sender_id_; |
| 76 // The intendent recipient(s) of the notification. | 81 // The intendent recipient(s) of the notification. |
| 77 P2PNotificationTarget target_; | 82 P2PNotificationTarget target_; |
| 78 // The types the notification is for. | 83 // The types the notification is for. |
| 79 syncable::ModelTypeSet changed_types_; | 84 syncable::ModelTypeSet changed_types_; |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 class P2PNotifier | 87 class P2PNotifier |
| 83 : public SyncNotifier, | 88 : public SyncNotifier, |
| 84 public notifier::TalkMediator::Delegate { | 89 public notifier::PushClient::Observer { |
| 85 public: | 90 public: |
| 86 // Takes ownership of |talk_mediator|, but it is guaranteed that | |
| 87 // |talk_mediator| is destroyed only when this object is destroyed. | |
| 88 // | |
| 89 // The |send_notification_target| parameter was added to allow us to send | 91 // The |send_notification_target| parameter was added to allow us to send |
| 90 // self-notifications in some cases, but not others. The value should be | 92 // self-notifications in some cases, but not others. The value should be |
| 91 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS | 93 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS |
| 92 // to send notificaitons to all clients except for the one that triggered the | 94 // to send notifications to all clients except for the one that triggered the |
| 93 // notification. See crbug.com/97780. | 95 // notification. See crbug.com/97780. |
| 94 P2PNotifier(notifier::TalkMediator* talk_mediator, | 96 P2PNotifier(const notifier::NotifierOptions& notifier_options, |
| 95 P2PNotificationTarget send_notification_target); | 97 P2PNotificationTarget send_notification_target); |
| 96 | 98 |
| 97 virtual ~P2PNotifier(); | 99 virtual ~P2PNotifier(); |
| 98 | 100 |
| 99 // SyncNotifier implementation | 101 // SyncNotifier implementation |
| 100 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 102 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 101 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 103 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 102 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 104 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 103 virtual void SetState(const std::string& state) OVERRIDE; | 105 virtual void SetState(const std::string& state) OVERRIDE; |
| 104 virtual void UpdateCredentials( | 106 virtual void UpdateCredentials( |
| 105 const std::string& email, const std::string& token) OVERRIDE; | 107 const std::string& email, const std::string& token) OVERRIDE; |
| 106 virtual void UpdateEnabledTypes( | 108 virtual void UpdateEnabledTypes( |
| 107 syncable::ModelTypeSet enabled_types) OVERRIDE; | 109 syncable::ModelTypeSet enabled_types) OVERRIDE; |
| 108 virtual void SendNotification( | 110 virtual void SendNotification( |
| 109 syncable::ModelTypeSet changed_types) OVERRIDE; | 111 syncable::ModelTypeSet changed_types) OVERRIDE; |
| 110 | 112 |
| 111 // TalkMediator::Delegate implementation. | 113 // PushClient::Delegate implementation. |
| 112 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; | 114 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; |
| 113 virtual void OnIncomingNotification( | 115 virtual void OnIncomingNotification( |
| 114 const notifier::Notification& notification) OVERRIDE; | 116 const notifier::Notification& notification) OVERRIDE; |
| 115 virtual void OnOutgoingNotification() OVERRIDE; | |
| 116 | 117 |
| 117 // For testing. | 118 // For testing. |
| 119 |
| 120 void SimulateConnectForTest( |
| 121 base::WeakPtr<buzz::XmppTaskParentInterface> base_task); |
| 122 |
| 123 // Any notifications sent after this is called will be reflected, |
| 124 // i.e. will be treated as an incoming notification also. |
| 125 void ReflectSentNotificationsForTest(); |
| 126 |
| 118 void SendNotificationDataForTest( | 127 void SendNotificationDataForTest( |
| 119 const P2PNotificationData& notification_data); | 128 const P2PNotificationData& notification_data); |
| 120 | 129 |
| 121 private: | 130 private: |
| 122 void SendNotificationData(const P2PNotificationData& notification_data); | 131 void SendNotificationData(const P2PNotificationData& notification_data); |
| 123 | 132 |
| 124 ObserverList<SyncNotifierObserver> observer_list_; | 133 ObserverList<SyncNotifierObserver> observer_list_; |
| 125 | 134 |
| 126 // The actual notification listener. | 135 // The XMPP push client. |
| 127 scoped_ptr<notifier::TalkMediator> talk_mediator_; | 136 notifier::PushClient push_client_; |
| 128 // Our unique ID. | 137 // Our unique ID. |
| 129 std::string unique_id_; | 138 std::string unique_id_; |
| 130 // Whether we called Login() on |talk_mediator_| yet. | 139 // Whether we have called UpdateCredentials() yet. |
| 131 bool logged_in_; | 140 bool logged_in_; |
| 132 // Whether |talk_mediator_| has notified us that notifications are | 141 // Whether |push_client_| has notified us that notifications are |
| 133 // enabled. | 142 // enabled. |
| 134 bool notifications_enabled_; | 143 bool notifications_enabled_; |
| 135 // Which set of clients should be sent notifications. | 144 // Which set of clients should be sent notifications. |
| 136 P2PNotificationTarget send_notification_target_; | 145 P2PNotificationTarget send_notification_target_; |
| 137 | 146 |
| 138 syncable::ModelTypeSet enabled_types_; | 147 syncable::ModelTypeSet enabled_types_; |
| 139 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; | 148 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; |
| 140 }; | 149 }; |
| 141 | 150 |
| 142 } // namespace sync_notifier | 151 } // namespace sync_notifier |
| 143 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 152 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| OLD | NEW |