Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.cc

Issue 225001: Use base/logging from chrome/browser/sync. Add a macro to libjingle's (Closed)
Patch Set: Added README.chromium Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.h" 5 #include "chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h"
10 #include "chrome/browser/sync/notifier/communicator/product_info.h" 11 #include "chrome/browser/sync/notifier/communicator/product_info.h"
11 #include "talk/base/byteorder.h" 12 #include "talk/base/byteorder.h"
12 #include "talk/base/common.h" 13 #include "talk/base/common.h"
13 #include "talk/base/firewallsocketserver.h" 14 #include "talk/base/firewallsocketserver.h"
14 #include "talk/base/logging.h" 15 #include "talk/base/logging.h"
15 #include "talk/base/socketadapters.h" 16 #include "talk/base/socketadapters.h"
16 #include "talk/base/ssladapter.h" 17 #include "talk/base/ssladapter.h"
17 #include "talk/xmpp/xmppengine.h" 18 #include "talk/xmpp/xmppengine.h"
18 19
19 namespace notifier { 20 namespace notifier {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 68 }
68 return true; 69 return true;
69 } 70 }
70 71
71 bool XmppSocketAdapter::Connect(const talk_base::SocketAddress& addr) { 72 bool XmppSocketAdapter::Connect(const talk_base::SocketAddress& addr) {
72 if (state_ != STATE_CLOSED) { 73 if (state_ != STATE_CLOSED) {
73 SetError(ERROR_WRONGSTATE); 74 SetError(ERROR_WRONGSTATE);
74 return false; 75 return false;
75 } 76 }
76 77
77 LOG(LS_INFO) << "XmppSocketAdapter::Connect(" << addr.ToString() << ")"; 78 LOG(INFO) << "XmppSocketAdapter::Connect(" << addr.ToString() << ")";
78 79
79 // Clean up any previous socket - cannot delete socket on close because close 80 // Clean up any previous socket - cannot delete socket on close because close
80 // happens during the child socket's stack callback. 81 // happens during the child socket's stack callback.
81 if (socket_) { 82 if (socket_) {
82 delete socket_; 83 delete socket_;
83 socket_ = NULL; 84 socket_ = NULL;
84 } 85 }
85 86
86 talk_base::AsyncSocket* socket = 87 talk_base::AsyncSocket* socket =
87 talk_base::Thread::Current()->socketserver()->CreateAsyncSocket( 88 talk_base::Thread::Current()->socketserver()->CreateAsyncSocket(
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 if (socket_) { 242 if (socket_) {
242 state_ = STATE_CLOSING; 243 state_ = STATE_CLOSING;
243 socket_->Close(); 244 socket_->Close();
244 } 245 }
245 246
246 // If we didn't get the callback, then we better make sure we signal 247 // If we didn't get the callback, then we better make sure we signal
247 // closed. 248 // closed.
248 if (state_ != STATE_CLOSED) { 249 if (state_ != STATE_CLOSED) {
249 // The socket was closed manually, not directly due to error. 250 // The socket was closed manually, not directly due to error.
250 if (error_ != ERROR_NONE) { 251 if (error_ != ERROR_NONE) {
251 LOG(LS_INFO) << "XmppSocketAdapter::Close - previous Error: " << error_ 252 LOG(INFO) << "XmppSocketAdapter::Close - previous Error: " << error_
252 << " WSAError: " << wsa_error_; 253 << " WSAError: " << wsa_error_;
253 error_ = ERROR_NONE; 254 error_ = ERROR_NONE;
254 wsa_error_ = 0; 255 wsa_error_ = 0;
255 } 256 }
256 NotifyClose(); 257 NotifyClose();
257 } 258 }
258 return true; 259 return true;
259 } 260 }
260 261
261 void XmppSocketAdapter::NotifyClose() { 262 void XmppSocketAdapter::NotifyClose() {
262 if (state_ == STATE_CLOSED) { 263 if (state_ == STATE_CLOSED) {
263 SetError(ERROR_WRONGSTATE); 264 SetError(ERROR_WRONGSTATE);
264 } else { 265 } else {
265 LOG(LS_INFO) << "XmppSocketAdapter::NotifyClose - Error: " << error_ 266 LOG(INFO) << "XmppSocketAdapter::NotifyClose - Error: " << error_
266 << " WSAError: " << wsa_error_; 267 << " WSAError: " << wsa_error_;
267 state_ = STATE_CLOSED; 268 state_ = STATE_CLOSED;
268 SignalClosed(); 269 SignalClosed();
269 FreeState(); 270 FreeState();
270 } 271 }
271 } 272 }
272 273
273 void XmppSocketAdapter::OnConnectEvent(talk_base::AsyncSocket *socket) { 274 void XmppSocketAdapter::OnConnectEvent(talk_base::AsyncSocket *socket) {
274 if (state_ == STATE_CONNECTING) { 275 if (state_ == STATE_CONNECTING) {
275 state_ = STATE_OPEN; 276 state_ = STATE_OPEN;
276 LOG(LS_INFO) << "XmppSocketAdapter::OnConnectEvent - STATE_OPEN"; 277 LOG(INFO) << "XmppSocketAdapter::OnConnectEvent - STATE_OPEN";
277 SignalConnected(); 278 SignalConnected();
278 #if defined(FEATURE_ENABLE_SSL) 279 #if defined(FEATURE_ENABLE_SSL)
279 } else if (state_ == STATE_TLS_CONNECTING) { 280 } else if (state_ == STATE_TLS_CONNECTING) {
280 state_ = STATE_TLS_OPEN; 281 state_ = STATE_TLS_OPEN;
281 LOG(LS_INFO) << "XmppSocketAdapter::OnConnectEvent - STATE_TLS_OPEN"; 282 LOG(INFO) << "XmppSocketAdapter::OnConnectEvent - STATE_TLS_OPEN";
282 SignalSSLConnected(); 283 SignalSSLConnected();
283 if (write_buffer_length_ > 0) { 284 if (write_buffer_length_ > 0) {
284 HandleWritable(); 285 HandleWritable();
285 } 286 }
286 #endif // defined(FEATURE_ENABLE_SSL) 287 #endif // defined(FEATURE_ENABLE_SSL)
287 } else { 288 } else {
288 LOG(LS_INFO) << "XmppSocketAdapter::OnConnectEvent - state is " << state_; 289 LOG(INFO) << "XmppSocketAdapter::OnConnectEvent - state is " << state_;
289 ASSERT(false); 290 ASSERT(false);
290 } 291 }
291 } 292 }
292 293
293 void XmppSocketAdapter::OnReadEvent(talk_base::AsyncSocket *socket) { 294 void XmppSocketAdapter::OnReadEvent(talk_base::AsyncSocket *socket) {
294 HandleReadable(); 295 HandleReadable();
295 } 296 }
296 297
297 void XmppSocketAdapter::OnWriteEvent(talk_base::AsyncSocket *socket) { 298 void XmppSocketAdapter::OnWriteEvent(talk_base::AsyncSocket *socket) {
298 HandleWritable(); 299 HandleWritable();
299 } 300 }
300 301
301 void XmppSocketAdapter::OnCloseEvent(talk_base::AsyncSocket *socket, 302 void XmppSocketAdapter::OnCloseEvent(talk_base::AsyncSocket *socket,
302 int error) { 303 int error) {
303 LOG(LS_INFO) << "XmppSocketAdapter::OnCloseEvent(" << error << ")"; 304 LOG(INFO) << "XmppSocketAdapter::OnCloseEvent(" << error << ")";
304 SetWSAError(error); 305 SetWSAError(error);
305 if (error == SOCKET_EACCES) { 306 if (error == SOCKET_EACCES) {
306 SignalAuthenticationError(); // Proxy needs authentication. 307 SignalAuthenticationError(); // Proxy needs authentication.
307 } 308 }
308 NotifyClose(); 309 NotifyClose();
309 } 310 }
310 311
311 #if defined(FEATURE_ENABLE_SSL) 312 #if defined(FEATURE_ENABLE_SSL)
312 bool XmppSocketAdapter::StartTls(const std::string& verify_host_name) { 313 bool XmppSocketAdapter::StartTls(const std::string& verify_host_name) {
313 if (state_ != STATE_OPEN) { 314 if (state_ != STATE_OPEN) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 int wsa_error = 0; 417 int wsa_error = 0;
417 FlushWriteQueue(&error, &wsa_error); 418 FlushWriteQueue(&error, &wsa_error);
418 if (error != ERROR_NONE) { 419 if (error != ERROR_NONE) {
419 Close(); 420 Close();
420 return false; 421 return false;
421 } 422 }
422 return true; 423 return true;
423 } 424 }
424 425
425 } // namespace notifier 426 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698