| 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/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "jingle/notifier/listener/talk_mediator.h" | 17 #include "jingle/notifier/listener/push_client.h" |
| 18 #include "sync/notifier/sync_notifier.h" | 18 #include "sync/notifier/sync_notifier.h" |
| 19 #include "sync/syncable/model_type.h" | 19 #include "sync/syncable/model_type.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class MessageLoopProxy; | 22 class MessageLoopProxy; |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 namespace sync_notifier { | 26 namespace sync_notifier { |
| 27 | 27 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // The unique ID of the client that sent the notification. | 74 // The unique ID of the client that sent the notification. |
| 75 std::string sender_id_; | 75 std::string sender_id_; |
| 76 // The intendent recipient(s) of the notification. | 76 // The intendent recipient(s) of the notification. |
| 77 P2PNotificationTarget target_; | 77 P2PNotificationTarget target_; |
| 78 // The types the notification is for. | 78 // The types the notification is for. |
| 79 syncable::ModelTypeSet changed_types_; | 79 syncable::ModelTypeSet changed_types_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class P2PNotifier | 82 class P2PNotifier |
| 83 : public SyncNotifier, | 83 : public SyncNotifier, |
| 84 public notifier::TalkMediator::Delegate { | 84 public notifier::PushClient::Observer { |
| 85 public: | 85 public: |
| 86 // Takes ownership of |talk_mediator|, but it is guaranteed that | 86 // Takes ownership of |push_client|, but it is guaranteed that |
| 87 // |talk_mediator| is destroyed only when this object is destroyed. | 87 // |push_client| is destroyed only when this object is destroyed. |
| 88 // | 88 // |
| 89 // The |send_notification_target| parameter was added to allow us to send | 89 // 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 | 90 // 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 | 91 // 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 | 92 // to send notificaitons to all clients except for the one that triggered the |
| 93 // notification. See crbug.com/97780. | 93 // notification. See crbug.com/97780. |
| 94 P2PNotifier(notifier::TalkMediator* talk_mediator, | 94 P2PNotifier(notifier::PushClient* push_client, |
| 95 P2PNotificationTarget send_notification_target); | 95 P2PNotificationTarget send_notification_target); |
| 96 | 96 |
| 97 virtual ~P2PNotifier(); | 97 virtual ~P2PNotifier(); |
| 98 | 98 |
| 99 // SyncNotifier implementation | 99 // SyncNotifier implementation |
| 100 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 100 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 101 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 101 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 102 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 102 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 103 virtual void SetState(const std::string& state) OVERRIDE; | 103 virtual void SetState(const std::string& state) OVERRIDE; |
| 104 virtual void UpdateCredentials( | 104 virtual void UpdateCredentials( |
| 105 const std::string& email, const std::string& token) OVERRIDE; | 105 const std::string& email, const std::string& token) OVERRIDE; |
| 106 virtual void UpdateEnabledTypes( | 106 virtual void UpdateEnabledTypes( |
| 107 syncable::ModelTypeSet enabled_types) OVERRIDE; | 107 syncable::ModelTypeSet enabled_types) OVERRIDE; |
| 108 virtual void SendNotification( | 108 virtual void SendNotification( |
| 109 syncable::ModelTypeSet changed_types) OVERRIDE; | 109 syncable::ModelTypeSet changed_types) OVERRIDE; |
| 110 | 110 |
| 111 // TalkMediator::Delegate implementation. | 111 // PushClient::Delegate implementation. |
| 112 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; | 112 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; |
| 113 virtual void OnIncomingNotification( | 113 virtual void OnIncomingNotification( |
| 114 const notifier::Notification& notification) OVERRIDE; | 114 const notifier::Notification& notification) OVERRIDE; |
| 115 virtual void OnOutgoingNotification() OVERRIDE; | |
| 116 | 115 |
| 117 // For testing. | 116 // For testing. |
| 118 void SendNotificationDataForTest( | 117 void SendNotificationDataForTest( |
| 119 const P2PNotificationData& notification_data); | 118 const P2PNotificationData& notification_data); |
| 120 | 119 |
| 121 private: | 120 private: |
| 122 void SendNotificationData(const P2PNotificationData& notification_data); | 121 void SendNotificationData(const P2PNotificationData& notification_data); |
| 123 | 122 |
| 124 ObserverList<SyncNotifierObserver> observer_list_; | 123 ObserverList<SyncNotifierObserver> observer_list_; |
| 125 | 124 |
| 126 // The actual notification listener. | 125 // The actual notification listener. |
| 127 scoped_ptr<notifier::TalkMediator> talk_mediator_; | 126 scoped_ptr<notifier::PushClient> push_client_; |
| 128 // Our unique ID. | 127 // Our unique ID. |
| 129 std::string unique_id_; | 128 std::string unique_id_; |
| 130 // Whether we called Login() on |talk_mediator_| yet. | 129 // Whether we have called UpdateCredentials() yet. |
| 131 bool logged_in_; | 130 bool logged_in_; |
| 132 // Whether |talk_mediator_| has notified us that notifications are | 131 // Whether |push_client_| has notified us that notifications are |
| 133 // enabled. | 132 // enabled. |
| 134 bool notifications_enabled_; | 133 bool notifications_enabled_; |
| 135 // Which set of clients should be sent notifications. | 134 // Which set of clients should be sent notifications. |
| 136 P2PNotificationTarget send_notification_target_; | 135 P2PNotificationTarget send_notification_target_; |
| 137 | 136 |
| 138 syncable::ModelTypeSet enabled_types_; | 137 syncable::ModelTypeSet enabled_types_; |
| 139 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; | 138 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; |
| 140 }; | 139 }; |
| 141 | 140 |
| 142 } // namespace sync_notifier | 141 } // namespace sync_notifier |
| 143 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 142 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| OLD | NEW |