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

Side by Side Diff: jingle/notifier/listener/non_blocking_push_client.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps, win compile error Created 8 years, 6 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
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 #include "jingle/notifier/listener/non_blocking_push_client.h" 5 #include "jingle/notifier/listener/non_blocking_push_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h"
9 #include "base/location.h" 8 #include "base/location.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop_proxy.h"
11 #include "jingle/notifier/listener/push_client_observer.h" 11 #include "jingle/notifier/listener/push_client_observer.h"
12 12
13 namespace notifier { 13 namespace notifier {
14 14
15 // All methods are called on the delegate thread unless specified 15 // All methods are called on the delegate thread unless specified
16 // otherwise. 16 // otherwise.
17 class NonBlockingPushClient::Core 17 class NonBlockingPushClient::Core
18 : public base::RefCountedThreadSafe<NonBlockingPushClient::Core>, 18 : public base::RefCountedThreadSafe<NonBlockingPushClient::Core>,
19 public PushClientObserver { 19 public PushClientObserver {
20 public: 20 public:
(...skipping 11 matching lines...) Expand all
32 const CreateBlockingPushClientCallback& 32 const CreateBlockingPushClientCallback&
33 create_blocking_push_client_callback); 33 create_blocking_push_client_callback);
34 34
35 // Must be called before being destroyed. 35 // Must be called before being destroyed.
36 void DestroyOnDelegateThread(); 36 void DestroyOnDelegateThread();
37 37
38 void UpdateSubscriptions(const SubscriptionList& subscriptions); 38 void UpdateSubscriptions(const SubscriptionList& subscriptions);
39 void UpdateCredentials(const std::string& email, const std::string& token); 39 void UpdateCredentials(const std::string& email, const std::string& token);
40 void SendNotification(const Notification& data); 40 void SendNotification(const Notification& data);
41 41
42 virtual void OnNotificationStateChange( 42 virtual void OnNotificationsEnabled() OVERRIDE;
43 bool notifications_enabled) OVERRIDE; 43 virtual void OnNotificationsDisabled(
44 NotificationsDisabledReason reason) OVERRIDE;
44 virtual void OnIncomingNotification( 45 virtual void OnIncomingNotification(
45 const Notification& notification) OVERRIDE; 46 const Notification& notification) OVERRIDE;
46 47
47 private: 48 private:
48 friend class base::RefCountedThreadSafe<NonBlockingPushClient::Core>; 49 friend class base::RefCountedThreadSafe<NonBlockingPushClient::Core>;
49 50
50 // Called on either the parent thread or the delegate thread. 51 // Called on either the parent thread or the delegate thread.
51 virtual ~Core(); 52 virtual ~Core();
52 53
53 const scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; 54 const scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 delegate_push_client_->UpdateCredentials(email, token); 103 delegate_push_client_->UpdateCredentials(email, token);
103 } 104 }
104 105
105 void NonBlockingPushClient::Core::SendNotification( 106 void NonBlockingPushClient::Core::SendNotification(
106 const Notification& notification) { 107 const Notification& notification) {
107 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 108 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
108 DCHECK(delegate_push_client_.get()); 109 DCHECK(delegate_push_client_.get());
109 delegate_push_client_->SendNotification(notification); 110 delegate_push_client_->SendNotification(notification);
110 } 111 }
111 112
112 void NonBlockingPushClient::Core::OnNotificationStateChange( 113 void NonBlockingPushClient::Core::OnNotificationsEnabled() {
113 bool notifications_enabled) {
114 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 114 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
115 parent_task_runner_->PostTask( 115 parent_task_runner_->PostTask(
116 FROM_HERE, 116 FROM_HERE,
117 base::Bind(&NonBlockingPushClient::OnNotificationStateChange, 117 base::Bind(&NonBlockingPushClient::OnNotificationsEnabled,
118 parent_push_client_, notifications_enabled)); 118 parent_push_client_));
119 }
120
121 void NonBlockingPushClient::Core::OnNotificationsDisabled(
122 NotificationsDisabledReason reason) {
123 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
124 parent_task_runner_->PostTask(
125 FROM_HERE,
126 base::Bind(&NonBlockingPushClient::OnNotificationsDisabled,
127 parent_push_client_, reason));
119 } 128 }
120 129
121 void NonBlockingPushClient::Core::OnIncomingNotification( 130 void NonBlockingPushClient::Core::OnIncomingNotification(
122 const Notification& notification) { 131 const Notification& notification) {
123 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 132 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
124 parent_task_runner_->PostTask( 133 parent_task_runner_->PostTask(
125 FROM_HERE, 134 FROM_HERE,
126 base::Bind(&NonBlockingPushClient::OnIncomingNotification, 135 base::Bind(&NonBlockingPushClient::OnIncomingNotification,
127 parent_push_client_, notification)); 136 parent_push_client_, notification));
128 } 137 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 188
180 void NonBlockingPushClient::SendNotification( 189 void NonBlockingPushClient::SendNotification(
181 const Notification& notification) { 190 const Notification& notification) {
182 DCHECK(non_thread_safe_.CalledOnValidThread()); 191 DCHECK(non_thread_safe_.CalledOnValidThread());
183 delegate_task_runner_->PostTask( 192 delegate_task_runner_->PostTask(
184 FROM_HERE, 193 FROM_HERE,
185 base::Bind(&NonBlockingPushClient::Core::SendNotification, core_.get(), 194 base::Bind(&NonBlockingPushClient::Core::SendNotification, core_.get(),
186 notification)); 195 notification));
187 } 196 }
188 197
189 void NonBlockingPushClient::OnNotificationStateChange( 198 void NonBlockingPushClient::OnNotificationsEnabled() {
190 bool notifications_enabled) {
191 DCHECK(non_thread_safe_.CalledOnValidThread()); 199 DCHECK(non_thread_safe_.CalledOnValidThread());
192 FOR_EACH_OBSERVER(PushClientObserver, observers_, 200 FOR_EACH_OBSERVER(PushClientObserver, observers_,
193 OnNotificationStateChange(notifications_enabled)); 201 OnNotificationsEnabled());
202 }
203
204 void NonBlockingPushClient::OnNotificationsDisabled(
205 NotificationsDisabledReason reason) {
206 DCHECK(non_thread_safe_.CalledOnValidThread());
207 FOR_EACH_OBSERVER(PushClientObserver, observers_,
208 OnNotificationsDisabled(reason));
194 } 209 }
195 210
196 void NonBlockingPushClient::OnIncomingNotification( 211 void NonBlockingPushClient::OnIncomingNotification(
197 const Notification& notification) { 212 const Notification& notification) {
198 DCHECK(non_thread_safe_.CalledOnValidThread()); 213 DCHECK(non_thread_safe_.CalledOnValidThread());
199 FOR_EACH_OBSERVER(PushClientObserver, observers_, 214 FOR_EACH_OBSERVER(PushClientObserver, observers_,
200 OnIncomingNotification(notification)); 215 OnIncomingNotification(notification));
201 } 216 }
202 217
203 } // namespace notifier 218 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698