Chromium Code Reviews| 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/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "jingle/notifier/listener/push_client_observer.h" | 19 #include "jingle/notifier/listener/push_client_observer.h" |
| 20 #include "sync/internal_api/public/base/model_type.h" | 20 #include "sync/internal_api/public/base/model_type.h" |
| 21 #include "sync/notifier/invalidator.h" | |
| 22 #include "sync/notifier/invalidator_registrar.h" | |
| 21 #include "sync/notifier/notifications_disabled_reason.h" | 23 #include "sync/notifier/notifications_disabled_reason.h" |
| 22 #include "sync/notifier/sync_notifier.h" | |
| 23 #include "sync/notifier/sync_notifier_registrar.h" | |
| 24 | 24 |
| 25 namespace notifier { | 25 namespace notifier { |
| 26 class PushClient; | 26 class PushClient; |
| 27 } // namespace notifier | 27 } // namespace notifier |
| 28 | 28 |
| 29 namespace syncer { | 29 namespace syncer { |
| 30 | 30 |
| 31 // The channel to use for sync notifications. | 31 // The channel to use for sync notifications. |
| 32 extern const char* kSyncP2PNotificationChannel; | 32 extern const char* kSyncP2PNotificationChannel; |
| 33 | 33 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 // The unique ID of the client that sent the notification. | 77 // The unique ID of the client that sent the notification. |
| 78 std::string sender_id_; | 78 std::string sender_id_; |
| 79 // The intendent recipient(s) of the notification. | 79 // The intendent recipient(s) of the notification. |
| 80 P2PNotificationTarget target_; | 80 P2PNotificationTarget target_; |
| 81 // The types the notification is for. | 81 // The types the notification is for. |
| 82 ModelTypeSet changed_types_; | 82 ModelTypeSet changed_types_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class P2PNotifier : public SyncNotifier, | 85 class P2PNotifier : public Invalidator, |
|
akalin
2012/08/27 22:38:31
How about P2PInvalidator?
dcheng
2012/08/28 00:20:22
Done.
| |
| 86 public notifier::PushClientObserver { | 86 public notifier::PushClientObserver { |
| 87 public: | 87 public: |
| 88 // The |send_notification_target| parameter was added to allow us to send | 88 // The |send_notification_target| parameter was added to allow us to send |
| 89 // self-notifications in some cases, but not others. The value should be | 89 // self-notifications in some cases, but not others. The value should be |
| 90 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS | 90 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS |
| 91 // to send notifications to all clients except for the one that triggered the | 91 // to send notifications to all clients except for the one that triggered the |
| 92 // notification. See crbug.com/97780. | 92 // notification. See crbug.com/97780. |
| 93 P2PNotifier(scoped_ptr<notifier::PushClient> push_client, | 93 P2PNotifier(scoped_ptr<notifier::PushClient> push_client, |
| 94 P2PNotificationTarget send_notification_target); | 94 P2PNotificationTarget send_notification_target); |
| 95 | 95 |
| 96 virtual ~P2PNotifier(); | 96 virtual ~P2PNotifier(); |
| 97 | 97 |
| 98 // SyncNotifier implementation | 98 // Invalidator implementation |
| 99 virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; | 99 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 100 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | 100 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
| 101 const ObjectIdSet& ids) OVERRIDE; | 101 const ObjectIdSet& ids) OVERRIDE; |
| 102 virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; | 102 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 103 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 103 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 104 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 104 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
| 105 virtual void UpdateCredentials( | 105 virtual void UpdateCredentials( |
| 106 const std::string& email, const std::string& token) OVERRIDE; | 106 const std::string& email, const std::string& token) OVERRIDE; |
| 107 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; | 107 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; |
| 108 | 108 |
| 109 // PushClientObserver implementation. | 109 // PushClientObserver implementation. |
| 110 virtual void OnNotificationsEnabled() OVERRIDE; | 110 virtual void OnNotificationsEnabled() OVERRIDE; |
| 111 virtual void OnNotificationsDisabled( | 111 virtual void OnNotificationsDisabled( |
| 112 notifier::NotificationsDisabledReason reason) OVERRIDE; | 112 notifier::NotificationsDisabledReason reason) OVERRIDE; |
| 113 virtual void OnIncomingNotification( | 113 virtual void OnIncomingNotification( |
| 114 const notifier::Notification& notification) OVERRIDE; | 114 const notifier::Notification& notification) OVERRIDE; |
| 115 | 115 |
| 116 void SendNotificationDataForTest( | 116 void SendNotificationDataForTest( |
| 117 const P2PNotificationData& notification_data); | 117 const P2PNotificationData& notification_data); |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 void SendNotificationData(const P2PNotificationData& notification_data); | 120 void SendNotificationData(const P2PNotificationData& notification_data); |
| 121 | 121 |
| 122 base::ThreadChecker thread_checker_; | 122 base::ThreadChecker thread_checker_; |
| 123 | 123 |
| 124 SyncNotifierRegistrar registrar_; | 124 InvalidatorRegistrar registrar_; |
| 125 | 125 |
| 126 // The push client. | 126 // The push client. |
| 127 scoped_ptr<notifier::PushClient> push_client_; | 127 scoped_ptr<notifier::PushClient> push_client_; |
| 128 // Our unique ID. | 128 // Our unique ID. |
| 129 std::string unique_id_; | 129 std::string unique_id_; |
| 130 // Whether we have called UpdateCredentials() yet. | 130 // Whether we have called UpdateCredentials() yet. |
| 131 bool logged_in_; | 131 bool logged_in_; |
| 132 bool notifications_enabled_; | 132 bool notifications_enabled_; |
| 133 // Which set of clients should be sent notifications. | 133 // Which set of clients should be sent notifications. |
| 134 P2PNotificationTarget send_notification_target_; | 134 P2PNotificationTarget send_notification_target_; |
| 135 | 135 |
| 136 ModelTypeSet enabled_types_; | 136 ModelTypeSet enabled_types_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace syncer | 139 } // namespace syncer |
| 140 | 140 |
| 141 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 141 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| OLD | NEW |