Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / jingle / notifier / base / weak_xmpp_client.cc
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
3 // found in the LICENSE file.
4
5 #include "jingle/notifier/base/weak_xmpp_client.h"
6
7 #include "base/compiler_specific.h"
8
9 namespace notifier {
10
11 WeakXmppClient::WeakXmppClient(rtc::TaskParent* parent)
12     : buzz::XmppClient(parent),
13       weak_ptr_factory_(this) {}
14
15 WeakXmppClient::~WeakXmppClient() {
16   DCHECK(CalledOnValidThread());
17   Invalidate();
18 }
19
20 void WeakXmppClient::Invalidate() {
21   DCHECK(CalledOnValidThread());
22   // We don't want XmppClient raising any signals once its invalidated.
23   SignalStateChange.disconnect_all();
24   SignalLogInput.disconnect_all();
25   SignalLogOutput.disconnect_all();
26   weak_ptr_factory_.InvalidateWeakPtrs();
27 }
28
29 base::WeakPtr<WeakXmppClient> WeakXmppClient::AsWeakPtr() {
30   DCHECK(CalledOnValidThread());
31   return weak_ptr_factory_.GetWeakPtr();
32 }
33
34 void WeakXmppClient::Stop() {
35   DCHECK(CalledOnValidThread());
36   // We don't want XmppClient used after it has been stopped.
37   Invalidate();
38   buzz::XmppClient::Stop();
39 }
40
41 }  // namespace notifier