| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/talk_mediator_impl.h" | 5 #include "jingle/notifier/listener/talk_mediator_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "jingle/notifier/base/notifier_options_util.h" | 9 #include "jingle/notifier/base/notifier_options_util.h" |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 return false; | 39 return false; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool TalkMediatorImpl::Logout() { | 42 bool TalkMediatorImpl::Logout() { |
| 43 CheckOrSetValidThread(); | 43 CheckOrSetValidThread(); |
| 44 if (state_.started) { | 44 if (state_.started) { |
| 45 state_.started = 0; | 45 state_.started = 0; |
| 46 state_.logging_in = 0; | 46 state_.logging_in = 0; |
| 47 state_.logged_in = 0; | 47 state_.logged_in = 0; |
| 48 state_.subscribed = 0; | |
| 49 // We do not want to be called back during logout since we may be | 48 // We do not want to be called back during logout since we may be |
| 50 // closing. | 49 // closing. |
| 51 mediator_thread_->RemoveObserver(this); | 50 mediator_thread_->RemoveObserver(this); |
| 52 mediator_thread_->Logout(); | 51 mediator_thread_->Logout(); |
| 53 return true; | 52 return true; |
| 54 } | 53 } |
| 55 return false; | 54 return false; |
| 56 } | 55 } |
| 57 | 56 |
| 58 bool TalkMediatorImpl::SendNotification(const Notification& data) { | 57 void TalkMediatorImpl::SendNotification(const Notification& data) { |
| 59 CheckOrSetValidThread(); | 58 CheckOrSetValidThread(); |
| 60 if (state_.logged_in && state_.subscribed) { | 59 mediator_thread_->SendNotification(data); |
| 61 mediator_thread_->SendNotification(data); | |
| 62 return true; | |
| 63 } | |
| 64 return false; | |
| 65 } | 60 } |
| 66 | 61 |
| 67 void TalkMediatorImpl::SetDelegate(TalkMediator::Delegate* delegate) { | 62 void TalkMediatorImpl::SetDelegate(TalkMediator::Delegate* delegate) { |
| 68 DCHECK_EQ(MessageLoop::current(), construction_message_loop_); | 63 DCHECK_EQ(MessageLoop::current(), construction_message_loop_); |
| 69 delegate_ = delegate; | 64 delegate_ = delegate; |
| 70 } | 65 } |
| 71 | 66 |
| 72 void TalkMediatorImpl::SetAuthToken(const std::string& email, | 67 void TalkMediatorImpl::SetAuthToken(const std::string& email, |
| 73 const std::string& token, | 68 const std::string& token, |
| 74 const std::string& token_service) { | 69 const std::string& token_service) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Now subscribe for updates to all the services we are interested in | 104 // Now subscribe for updates to all the services we are interested in |
| 110 mediator_thread_->SubscribeForUpdates(subscriptions_); | 105 mediator_thread_->SubscribeForUpdates(subscriptions_); |
| 111 } else { | 106 } else { |
| 112 VLOG(1) << "P2P: Logged off."; | 107 VLOG(1) << "P2P: Logged off."; |
| 113 OnSubscriptionStateChange(false); | 108 OnSubscriptionStateChange(false); |
| 114 } | 109 } |
| 115 } | 110 } |
| 116 | 111 |
| 117 void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) { | 112 void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) { |
| 118 CheckOrSetValidThread(); | 113 CheckOrSetValidThread(); |
| 119 state_.subscribed = subscribed; | |
| 120 VLOG(1) << "P2P: " << (subscribed ? "subscribed" : "unsubscribed"); | 114 VLOG(1) << "P2P: " << (subscribed ? "subscribed" : "unsubscribed"); |
| 121 if (delegate_) | 115 if (delegate_) |
| 122 delegate_->OnNotificationStateChange(subscribed); | 116 delegate_->OnNotificationStateChange(subscribed); |
| 123 } | 117 } |
| 124 | 118 |
| 125 void TalkMediatorImpl::OnIncomingNotification( | 119 void TalkMediatorImpl::OnIncomingNotification( |
| 126 const Notification& notification) { | 120 const Notification& notification) { |
| 127 CheckOrSetValidThread(); | 121 CheckOrSetValidThread(); |
| 128 VLOG(1) << "P2P: Updates are available on the server."; | 122 VLOG(1) << "P2P: Updates are available on the server."; |
| 129 if (delegate_) | 123 if (delegate_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 | 134 |
| 141 void TalkMediatorImpl::CheckOrSetValidThread() { | 135 void TalkMediatorImpl::CheckOrSetValidThread() { |
| 142 if (method_message_loop_) { | 136 if (method_message_loop_) { |
| 143 DCHECK_EQ(MessageLoop::current(), method_message_loop_); | 137 DCHECK_EQ(MessageLoop::current(), method_message_loop_); |
| 144 } else { | 138 } else { |
| 145 method_message_loop_ = MessageLoop::current(); | 139 method_message_loop_ = MessageLoop::current(); |
| 146 } | 140 } |
| 147 } | 141 } |
| 148 | 142 |
| 149 } // namespace notifier | 143 } // namespace notifier |
| OLD | NEW |