Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: sync/notifier/p2p_notifier.h

Issue 10413014: [Sync] Turn notifier::PushClient into an interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « jingle/notifier/listener/xmpp_push_client_unittest.cc ('k') | sync/notifier/p2p_notifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "jingle/notifier/base/notifier_options.h" 18 #include "base/threading/non_thread_safe.h"
19 #include "jingle/notifier/listener/push_client.h" 19 #include "jingle/notifier/listener/push_client_observer.h"
20 #include "sync/notifier/sync_notifier.h" 20 #include "sync/notifier/sync_notifier.h"
21 #include "sync/syncable/model_type.h" 21 #include "sync/syncable/model_type.h"
22 22
23 namespace base { 23 namespace notifier {
24 class MessageLoopProxy; 24 class PushClient;
25 } 25 } // namespace notifier
26
27 namespace buzz {
28 class XmppTaskParentInterface;
29 } // namespace buzz
30 26
31 namespace sync_notifier { 27 namespace sync_notifier {
32 28
33 // The channel to use for sync notifications. 29 // The channel to use for sync notifications.
34 extern const char* kSyncP2PNotificationChannel; 30 extern const char* kSyncP2PNotificationChannel;
35 31
36 // The intended recipient(s) of a P2P notification. 32 // The intended recipient(s) of a P2P notification.
37 enum P2PNotificationTarget { 33 enum P2PNotificationTarget {
38 NOTIFY_SELF, 34 NOTIFY_SELF,
39 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF, 35 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // The unique ID of the client that sent the notification. 75 // The unique ID of the client that sent the notification.
80 std::string sender_id_; 76 std::string sender_id_;
81 // The intendent recipient(s) of the notification. 77 // The intendent recipient(s) of the notification.
82 P2PNotificationTarget target_; 78 P2PNotificationTarget target_;
83 // The types the notification is for. 79 // The types the notification is for.
84 syncable::ModelTypeSet changed_types_; 80 syncable::ModelTypeSet changed_types_;
85 }; 81 };
86 82
87 class P2PNotifier 83 class P2PNotifier
88 : public SyncNotifier, 84 : public SyncNotifier,
89 public notifier::PushClient::Observer { 85 public notifier::PushClientObserver {
90 public: 86 public:
91 // The |send_notification_target| parameter was added to allow us to send 87 // The |send_notification_target| parameter was added to allow us to send
92 // self-notifications in some cases, but not others. The value should be 88 // self-notifications in some cases, but not others. The value should be
93 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS 89 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS
94 // to send notifications to all clients except for the one that triggered the 90 // to send notifications to all clients except for the one that triggered the
95 // notification. See crbug.com/97780. 91 // notification. See crbug.com/97780.
96 P2PNotifier(const notifier::NotifierOptions& notifier_options, 92 P2PNotifier(scoped_ptr<notifier::PushClient> push_client,
97 P2PNotificationTarget send_notification_target); 93 P2PNotificationTarget send_notification_target);
98 94
99 virtual ~P2PNotifier(); 95 virtual ~P2PNotifier();
100 96
101 // SyncNotifier implementation 97 // SyncNotifier implementation
102 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; 98 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE;
103 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; 99 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE;
104 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; 100 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
105 virtual void SetState(const std::string& state) OVERRIDE; 101 virtual void SetState(const std::string& state) OVERRIDE;
106 virtual void UpdateCredentials( 102 virtual void UpdateCredentials(
107 const std::string& email, const std::string& token) OVERRIDE; 103 const std::string& email, const std::string& token) OVERRIDE;
108 virtual void UpdateEnabledTypes( 104 virtual void UpdateEnabledTypes(
109 syncable::ModelTypeSet enabled_types) OVERRIDE; 105 syncable::ModelTypeSet enabled_types) OVERRIDE;
110 virtual void SendNotification( 106 virtual void SendNotification(
111 syncable::ModelTypeSet changed_types) OVERRIDE; 107 syncable::ModelTypeSet changed_types) OVERRIDE;
112 108
113 // PushClient::Delegate implementation. 109 // PushClientObserver implementation.
114 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; 110 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE;
115 virtual void OnIncomingNotification( 111 virtual void OnIncomingNotification(
116 const notifier::Notification& notification) OVERRIDE; 112 const notifier::Notification& notification) OVERRIDE;
117 113
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
127 void SendNotificationDataForTest( 114 void SendNotificationDataForTest(
128 const P2PNotificationData& notification_data); 115 const P2PNotificationData& notification_data);
129 116
130 private: 117 private:
131 void SendNotificationData(const P2PNotificationData& notification_data); 118 void SendNotificationData(const P2PNotificationData& notification_data);
132 119
120 base::NonThreadSafe non_thread_safe_;
121
133 ObserverList<SyncNotifierObserver> observer_list_; 122 ObserverList<SyncNotifierObserver> observer_list_;
134 123
135 // The XMPP push client. 124 // The push client.
136 notifier::PushClient push_client_; 125 scoped_ptr<notifier::PushClient> push_client_;
137 // Our unique ID. 126 // Our unique ID.
138 std::string unique_id_; 127 std::string unique_id_;
139 // Whether we have called UpdateCredentials() yet. 128 // Whether we have called UpdateCredentials() yet.
140 bool logged_in_; 129 bool logged_in_;
141 // Whether |push_client_| has notified us that notifications are 130 // Whether |push_client_| has notified us that notifications are
142 // enabled. 131 // enabled.
143 bool notifications_enabled_; 132 bool notifications_enabled_;
144 // Which set of clients should be sent notifications. 133 // Which set of clients should be sent notifications.
145 P2PNotificationTarget send_notification_target_; 134 P2PNotificationTarget send_notification_target_;
146 135
147 syncable::ModelTypeSet enabled_types_; 136 syncable::ModelTypeSet enabled_types_;
148 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
149 }; 137 };
150 138
151 } // namespace sync_notifier 139 } // namespace sync_notifier
140
152 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ 141 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_
OLDNEW
« no previous file with comments | « jingle/notifier/listener/xmpp_push_client_unittest.cc ('k') | sync/notifier/p2p_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698