Chromium Code Reviews| 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" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "jingle/glue/chrome_async_socket.h" | 13 #include "jingle/glue/chrome_async_socket.h" |
| 14 #include "jingle/glue/task_pump.h" | 14 #include "jingle/glue/task_pump.h" |
| 15 #include "jingle/glue/xmpp_client_socket_factory.h" | 15 #include "jingle/glue/xmpp_client_socket_factory.h" |
| 16 #include "jingle/notifier/base/weak_xmpp_client.h" | 16 #include "jingle/notifier/base/weak_xmpp_client.h" |
| 17 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
| 18 #include "net/ssl/ssl_config_service.h" | 18 #include "net/ssl/ssl_config_service.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 #include "webrtc/libjingle/xmpp/xmppclientsettings.h" | 20 #include "webrtc/libjingle/xmpp/xmppclientsettings.h" |
| 21 | 21 |
| 22 namespace notifier { | 22 namespace notifier { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(CalledOnValidThread()); |
| 83 ClearClient(); | 83 ClearClient(); |
| 84 task_pump_->Stop(); | 84 task_pump_->Stop(); |
| 85 base::MessageLoop* current_message_loop = base::MessageLoop::current(); | |
| 86 CHECK(current_message_loop); | |
| 87 // We do this because XmppConnection may get destroyed as a result | 85 // We do this because XmppConnection may get destroyed as a result |
| 88 // 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 |
| 89 // 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 |
| 90 // (which is deleted by |task_pump_|) function. | 88 // (which is deleted by |task_pump_|) function. |
| 91 current_message_loop->DeleteSoon(FROM_HERE, task_pump_.release()); | 89 CHECK(base::ThreadTaskRunnerHandle::IsSet()); |
|
Sergey Ulanov
2016/06/20 22:53:25
I don't think you need this CHECK(). There is DCHE
fdoray
2016/06/21 13:01:51
Done.
| |
| 90 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, | |
| 91 task_pump_.release()); | |
| 92 } | 92 } |
| 93 | 93 |
| 94 void XmppConnection::OnStateChange(buzz::XmppEngine::State state) { | 94 void XmppConnection::OnStateChange(buzz::XmppEngine::State state) { |
| 95 DCHECK(CalledOnValidThread()); | 95 DCHECK(CalledOnValidThread()); |
| 96 VLOG(1) << "XmppClient state changed to " << state; | 96 VLOG(1) << "XmppClient state changed to " << state; |
| 97 if (!weak_xmpp_client_.get()) { | 97 if (!weak_xmpp_client_.get()) { |
| 98 LOG(DFATAL) << "weak_xmpp_client_ unexpectedly NULL"; | 98 LOG(DFATAL) << "weak_xmpp_client_ unexpectedly NULL"; |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 if (!delegate_) { | 101 if (!delegate_) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 } | 140 } |
| 141 | 141 |
| 142 void XmppConnection::ClearClient() { | 142 void XmppConnection::ClearClient() { |
| 143 if (weak_xmpp_client_.get()) { | 143 if (weak_xmpp_client_.get()) { |
| 144 weak_xmpp_client_->Invalidate(); | 144 weak_xmpp_client_->Invalidate(); |
| 145 DCHECK(!weak_xmpp_client_.get()); | 145 DCHECK(!weak_xmpp_client_.get()); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace notifier | 149 } // namespace notifier |
| OLD | NEW |