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

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

Issue 10388227: Revert 138216 - [Sync] Turn notifier::PushClient into an interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 "base/threading/non_thread_safe.h" 18 #include "jingle/notifier/base/notifier_options.h"
19 #include "jingle/notifier/listener/push_client_observer.h" 19 #include "jingle/notifier/listener/push_client.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 notifier { 23 namespace base {
24 class PushClient; 24 class MessageLoopProxy;
25 } // namespace notifier 25 }
26
27 namespace buzz {
28 class XmppTaskParentInterface;
29 } // namespace buzz
26 30
27 namespace sync_notifier { 31 namespace sync_notifier {
28 32
29 // The channel to use for sync notifications. 33 // The channel to use for sync notifications.
30 extern const char* kSyncP2PNotificationChannel; 34 extern const char* kSyncP2PNotificationChannel;
31 35
32 // The intended recipient(s) of a P2P notification. 36 // The intended recipient(s) of a P2P notification.
33 enum P2PNotificationTarget { 37 enum P2PNotificationTarget {
34 NOTIFY_SELF, 38 NOTIFY_SELF,
35 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF, 39 FIRST_NOTIFICATION_TARGET = NOTIFY_SELF,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // The unique ID of the client that sent the notification. 79 // The unique ID of the client that sent the notification.
76 std::string sender_id_; 80 std::string sender_id_;
77 // The intendent recipient(s) of the notification. 81 // The intendent recipient(s) of the notification.
78 P2PNotificationTarget target_; 82 P2PNotificationTarget target_;
79 // The types the notification is for. 83 // The types the notification is for.
80 syncable::ModelTypeSet changed_types_; 84 syncable::ModelTypeSet changed_types_;
81 }; 85 };
82 86
83 class P2PNotifier 87 class P2PNotifier
84 : public SyncNotifier, 88 : public SyncNotifier,
85 public notifier::PushClientObserver { 89 public notifier::PushClient::Observer {
86 public: 90 public:
87 // 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
88 // 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
89 // 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
90 // to send notifications to all clients except for the one that triggered the 94 // to send notifications to all clients except for the one that triggered the
91 // notification. See crbug.com/97780. 95 // notification. See crbug.com/97780.
92 P2PNotifier(scoped_ptr<notifier::PushClient> push_client, 96 P2PNotifier(const notifier::NotifierOptions& notifier_options,
93 P2PNotificationTarget send_notification_target); 97 P2PNotificationTarget send_notification_target);
94 98
95 virtual ~P2PNotifier(); 99 virtual ~P2PNotifier();
96 100
97 // SyncNotifier implementation 101 // SyncNotifier implementation
98 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; 102 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE;
99 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; 103 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE;
100 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; 104 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
101 virtual void SetState(const std::string& state) OVERRIDE; 105 virtual void SetState(const std::string& state) OVERRIDE;
102 virtual void UpdateCredentials( 106 virtual void UpdateCredentials(
103 const std::string& email, const std::string& token) OVERRIDE; 107 const std::string& email, const std::string& token) OVERRIDE;
104 virtual void UpdateEnabledTypes( 108 virtual void UpdateEnabledTypes(
105 syncable::ModelTypeSet enabled_types) OVERRIDE; 109 syncable::ModelTypeSet enabled_types) OVERRIDE;
106 virtual void SendNotification( 110 virtual void SendNotification(
107 syncable::ModelTypeSet changed_types) OVERRIDE; 111 syncable::ModelTypeSet changed_types) OVERRIDE;
108 112
109 // PushClientObserver implementation. 113 // PushClient::Delegate implementation.
110 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; 114 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE;
111 virtual void OnIncomingNotification( 115 virtual void OnIncomingNotification(
112 const notifier::Notification& notification) OVERRIDE; 116 const notifier::Notification& notification) OVERRIDE;
113 117
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
114 void SendNotificationDataForTest( 127 void SendNotificationDataForTest(
115 const P2PNotificationData& notification_data); 128 const P2PNotificationData& notification_data);
116 129
117 private: 130 private:
118 void SendNotificationData(const P2PNotificationData& notification_data); 131 void SendNotificationData(const P2PNotificationData& notification_data);
119 132
120 base::NonThreadSafe non_thread_safe_;
121
122 ObserverList<SyncNotifierObserver> observer_list_; 133 ObserverList<SyncNotifierObserver> observer_list_;
123 134
124 // The push client. 135 // The XMPP push client.
125 scoped_ptr<notifier::PushClient> push_client_; 136 notifier::PushClient push_client_;
126 // Our unique ID. 137 // Our unique ID.
127 std::string unique_id_; 138 std::string unique_id_;
128 // Whether we have called UpdateCredentials() yet. 139 // Whether we have called UpdateCredentials() yet.
129 bool logged_in_; 140 bool logged_in_;
130 // Whether |push_client_| has notified us that notifications are 141 // Whether |push_client_| has notified us that notifications are
131 // enabled. 142 // enabled.
132 bool notifications_enabled_; 143 bool notifications_enabled_;
133 // Which set of clients should be sent notifications. 144 // Which set of clients should be sent notifications.
134 P2PNotificationTarget send_notification_target_; 145 P2PNotificationTarget send_notification_target_;
135 146
136 syncable::ModelTypeSet enabled_types_; 147 syncable::ModelTypeSet enabled_types_;
148 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
137 }; 149 };
138 150
139 } // namespace sync_notifier 151 } // namespace sync_notifier
140
141 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ 152 #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