| 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 #include "jingle/notifier/base/xmpp_connection.h" | 5 #include "jingle/notifier/base/xmpp_connection.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 CreateSocket(xmpp_client_settings, | 72 CreateSocket(xmpp_client_settings, |
| 73 request_context_getter), | 73 request_context_getter), |
| 74 pre_xmpp_auth); | 74 pre_xmpp_auth); |
| 75 // buzz::XmppClient::Connect() should never fail. | 75 // buzz::XmppClient::Connect() should never fail. |
| 76 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK); | 76 DCHECK_EQ(connect_status, buzz::XMPP_RETURN_OK); |
| 77 weak_xmpp_client->Start(); | 77 weak_xmpp_client->Start(); |
| 78 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr(); | 78 weak_xmpp_client_ = weak_xmpp_client->AsWeakPtr(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 XmppConnection::~XmppConnection() { | 81 XmppConnection::~XmppConnection() { |
| 82 DCHECK(CalledOnValidThread()); | 82 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 83 ClearClient(); | 83 ClearClient(); |
| 84 task_pump_->Stop(); | 84 task_pump_->Stop(); |
| 85 // We do this because XmppConnection may get destroyed as a result | 85 // We do this because XmppConnection may get destroyed as a result |
| 86 // of a signal from XmppClient. If we delete |task_pump_| here, bad | 86 // of a signal from XmppClient. If we delete |task_pump_| here, bad |
| 87 // things happen when the stack pops back up to the XmppClient's | 87 // things happen when the stack pops back up to the XmppClient's |
| 88 // (which is deleted by |task_pump_|) function. | 88 // (which is deleted by |task_pump_|) function. |
| 89 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, | 89 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, |
| 90 task_pump_.release()); | 90 task_pump_.release()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void XmppConnection::OnStateChange(buzz::XmppEngine::State state) { | 93 void XmppConnection::OnStateChange(buzz::XmppEngine::State state) { |
| 94 DCHECK(CalledOnValidThread()); | 94 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 95 VLOG(1) << "XmppClient state changed to " << state; | 95 VLOG(1) << "XmppClient state changed to " << state; |
| 96 if (!weak_xmpp_client_.get()) { | 96 if (!weak_xmpp_client_.get()) { |
| 97 LOG(DFATAL) << "weak_xmpp_client_ unexpectedly NULL"; | 97 LOG(DFATAL) << "weak_xmpp_client_ unexpectedly NULL"; |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 if (!delegate_) { | 100 if (!delegate_) { |
| 101 LOG(DFATAL) << "delegate_ unexpectedly NULL"; | 101 LOG(DFATAL) << "delegate_ unexpectedly NULL"; |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 switch (state) { | 104 switch (state) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 122 delegate->OnError(error, subcode, stream_error); | 122 delegate->OnError(error, subcode, stream_error); |
| 123 break; | 123 break; |
| 124 } | 124 } |
| 125 default: | 125 default: |
| 126 // Do nothing. | 126 // Do nothing. |
| 127 break; | 127 break; |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void XmppConnection::OnInputLog(const char* data, int len) { | 131 void XmppConnection::OnInputLog(const char* data, int len) { |
| 132 DCHECK(CalledOnValidThread()); | 132 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 133 VLOG(2) << "XMPP Input: " << base::StringPiece(data, len); | 133 VLOG(2) << "XMPP Input: " << base::StringPiece(data, len); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void XmppConnection::OnOutputLog(const char* data, int len) { | 136 void XmppConnection::OnOutputLog(const char* data, int len) { |
| 137 DCHECK(CalledOnValidThread()); | 137 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 138 VLOG(2) << "XMPP Output: " << base::StringPiece(data, len); | 138 VLOG(2) << "XMPP Output: " << base::StringPiece(data, len); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void XmppConnection::ClearClient() { | 141 void XmppConnection::ClearClient() { |
| 142 if (weak_xmpp_client_.get()) { | 142 if (weak_xmpp_client_.get()) { |
| 143 weak_xmpp_client_->Invalidate(); | 143 weak_xmpp_client_->Invalidate(); |
| 144 DCHECK(!weak_xmpp_client_.get()); | 144 DCHECK(!weak_xmpp_client_.get()); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace notifier | 148 } // namespace notifier |
| OLD | NEW |