OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "remoting/jingle_glue/jingle_client.h" | 5 #include "remoting/jingle_glue/jingle_client.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/communicator/gaia_token_pre_xmpp_auth.h" | 9 #include "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" |
10 #include "remoting/jingle_glue/iq_request.h" | 10 #include "remoting/jingle_glue/iq_request.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 JingleClient::JingleClient(JingleThread* thread) | 25 JingleClient::JingleClient(JingleThread* thread) |
26 : thread_(thread), | 26 : thread_(thread), |
27 callback_(NULL), | 27 callback_(NULL), |
28 client_(NULL), | 28 client_(NULL), |
29 state_(START), | 29 state_(START), |
30 initialized_(false), | 30 initialized_(false), |
31 closed_(false) { | 31 closed_(false) { |
32 } | 32 } |
33 | 33 |
34 JingleClient::~JingleClient() { | 34 JingleClient::~JingleClient() { |
35 AutoLock auto_lock(state_lock_); | 35 base::AutoLock auto_lock(state_lock_); |
36 DCHECK(!initialized_ || closed_); | 36 DCHECK(!initialized_ || closed_); |
37 } | 37 } |
38 | 38 |
39 void JingleClient::Init( | 39 void JingleClient::Init( |
40 const std::string& username, const std::string& auth_token, | 40 const std::string& username, const std::string& auth_token, |
41 const std::string& auth_token_service, Callback* callback) { | 41 const std::string& auth_token_service, Callback* callback) { |
42 DCHECK_NE(username, ""); | 42 DCHECK_NE(username, ""); |
43 | 43 |
44 { | 44 { |
45 AutoLock auto_lock(state_lock_); | 45 base::AutoLock auto_lock(state_lock_); |
46 DCHECK(!initialized_ && !closed_); | 46 DCHECK(!initialized_ && !closed_); |
47 initialized_ = true; | 47 initialized_ = true; |
48 | 48 |
49 DCHECK(callback != NULL); | 49 DCHECK(callback != NULL); |
50 callback_ = callback; | 50 callback_ = callback; |
51 } | 51 } |
52 | 52 |
53 message_loop()->PostTask( | 53 message_loop()->PostTask( |
54 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, | 54 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, |
55 username, auth_token, auth_token_service)); | 55 username, auth_token, auth_token_service)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 receiver->EnableOutgoingMessages(); | 94 receiver->EnableOutgoingMessages(); |
95 receiver->Start(); | 95 receiver->Start(); |
96 } | 96 } |
97 | 97 |
98 void JingleClient::Close() { | 98 void JingleClient::Close() { |
99 Close(NULL); | 99 Close(NULL); |
100 } | 100 } |
101 | 101 |
102 void JingleClient::Close(Task* closed_task) { | 102 void JingleClient::Close(Task* closed_task) { |
103 { | 103 { |
104 AutoLock auto_lock(state_lock_); | 104 base::AutoLock auto_lock(state_lock_); |
105 // If the client is already closed then don't close again. | 105 // If the client is already closed then don't close again. |
106 if (closed_) { | 106 if (closed_) { |
107 if (closed_task) | 107 if (closed_task) |
108 thread_->message_loop()->PostTask(FROM_HERE, closed_task); | 108 thread_->message_loop()->PostTask(FROM_HERE, closed_task); |
109 return; | 109 return; |
110 } | 110 } |
111 closed_task_.reset(closed_task); | 111 closed_task_.reset(closed_task); |
112 closed_ = true; | 112 closed_ = true; |
113 } | 113 } |
114 | 114 |
(...skipping 15 matching lines...) Expand all Loading... |
130 client_ = NULL; | 130 client_ = NULL; |
131 } | 131 } |
132 | 132 |
133 if (closed_task_.get()) { | 133 if (closed_task_.get()) { |
134 closed_task_->Run(); | 134 closed_task_->Run(); |
135 closed_task_.reset(); | 135 closed_task_.reset(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 std::string JingleClient::GetFullJid() { | 139 std::string JingleClient::GetFullJid() { |
140 AutoLock auto_lock(full_jid_lock_); | 140 base::AutoLock auto_lock(full_jid_lock_); |
141 return full_jid_; | 141 return full_jid_; |
142 } | 142 } |
143 | 143 |
144 IqRequest* JingleClient::CreateIqRequest() { | 144 IqRequest* JingleClient::CreateIqRequest() { |
145 return new IqRequest(this); | 145 return new IqRequest(this); |
146 } | 146 } |
147 | 147 |
148 MessageLoop* JingleClient::message_loop() { | 148 MessageLoop* JingleClient::message_loop() { |
149 return thread_->message_loop(); | 149 return thread_->message_loop(); |
150 } | 150 } |
(...skipping 21 matching lines...) Expand all Loading... |
172 // closed. Reset the pointer so we don't try to use it later. | 172 // closed. Reset the pointer so we don't try to use it later. |
173 client_ = NULL; | 173 client_ = NULL; |
174 break; | 174 break; |
175 default: | 175 default: |
176 NOTREACHED(); | 176 NOTREACHED(); |
177 break; | 177 break; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void JingleClient::SetFullJid(const std::string& full_jid) { | 181 void JingleClient::SetFullJid(const std::string& full_jid) { |
182 AutoLock auto_lock(full_jid_lock_); | 182 base::AutoLock auto_lock(full_jid_lock_); |
183 full_jid_ = full_jid; | 183 full_jid_ = full_jid; |
184 } | 184 } |
185 | 185 |
186 void JingleClient::UpdateState(State new_state) { | 186 void JingleClient::UpdateState(State new_state) { |
187 if (new_state != state_) { | 187 if (new_state != state_) { |
188 state_ = new_state; | 188 state_ = new_state; |
189 { | 189 { |
190 // We have to have the lock held, otherwise we cannot be sure that | 190 // We have to have the lock held, otherwise we cannot be sure that |
191 // the client hasn't been closed when we call the callback. | 191 // the client hasn't been closed when we call the callback. |
192 AutoLock auto_lock(state_lock_); | 192 base::AutoLock auto_lock(state_lock_); |
193 if (!closed_) | 193 if (!closed_) |
194 callback_->OnStateChange(this, new_state); | 194 callback_->OnStateChange(this, new_state); |
195 } | 195 } |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 buzz::PreXmppAuth* JingleClient::CreatePreXmppAuth( | 199 buzz::PreXmppAuth* JingleClient::CreatePreXmppAuth( |
200 const buzz::XmppClientSettings& settings) { | 200 const buzz::XmppClientSettings& settings) { |
201 buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY); | 201 buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY); |
202 return new notifier::GaiaTokenPreXmppAuth(jid.Str(), settings.auth_cookie(), | 202 return new notifier::GaiaTokenPreXmppAuth(jid.Str(), settings.auth_cookie(), |
203 settings.token_service()); | 203 settings.token_service()); |
204 } | 204 } |
205 | 205 |
206 } // namespace remoting | 206 } // namespace remoting |
OLD | NEW |