summaryrefslogtreecommitdiffstats
path: root/jingle/notifier/base
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 16:53:42 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 16:53:42 +0000
commitba62fbd428232eee1815d4b4d63fc65cb3ead566 (patch)
tree56d05f663fe81afc7c7f6c232d1f650994bbe8ed /jingle/notifier/base
parenta538b1cdbd69c307ef672b5176c8ac9039981c41 (diff)
downloadchromium_src-ba62fbd428232eee1815d4b4d63fc65cb3ead566.zip
chromium_src-ba62fbd428232eee1815d4b4d63fc65cb3ead566.tar.gz
chromium_src-ba62fbd428232eee1815d4b4d63fc65cb3ead566.tar.bz2
Revert r59012 which started using Chrome sockets for sync.
This caused us to write to ChromeNetLog from the sync thread. ChromeNetLog is not thread safe, so this causes problems. BUG=55116,54146 TEST=Start up chrome. Does not repeatedly hit DCHECKs on ChromeNetLog::AddEntry(). Review URL: http://codereview.chromium.org/3358028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/notifier/base')
-rw-r--r--jingle/notifier/base/notifier_options.h13
-rw-r--r--jingle/notifier/base/signal_thread_task.h96
-rw-r--r--jingle/notifier/base/ssl_adapter.cc27
-rw-r--r--jingle/notifier/base/ssl_adapter.h33
-rw-r--r--jingle/notifier/base/static_assert.h21
5 files changed, 187 insertions, 3 deletions
diff --git a/jingle/notifier/base/notifier_options.h b/jingle/notifier/base/notifier_options.h
index 289b7d8..32374cf 100644
--- a/jingle/notifier/base/notifier_options.h
+++ b/jingle/notifier/base/notifier_options.h
@@ -12,16 +12,23 @@ namespace notifier {
struct NotifierOptions {
NotifierOptions()
- : try_ssltcp_first(false),
+ : use_chrome_async_socket(true),
+ try_ssltcp_first(false),
notification_method(kDefaultNotificationMethod) {}
- NotifierOptions(const bool try_ssltcp_first,
+ NotifierOptions(const bool use_chrome_async_socket,
+ const bool try_ssltcp_first,
const net::HostPortPair& xmpp_host_port,
NotificationMethod notification_method)
- : try_ssltcp_first(try_ssltcp_first),
+ : use_chrome_async_socket(use_chrome_async_socket),
+ try_ssltcp_first(try_ssltcp_first),
xmpp_host_port(xmpp_host_port),
notification_method(notification_method) {}
+ // Indicates whether to use the chrome-socket-based buzz::AsyncSocket
+ // implementation for notifications.
+ bool use_chrome_async_socket;
+
// Indicates that the SSLTCP port (443) is to be tried before the the XMPP
// port (5222) during login.
bool try_ssltcp_first;
diff --git a/jingle/notifier/base/signal_thread_task.h b/jingle/notifier/base/signal_thread_task.h
new file mode 100644
index 0000000..8a6ff27
--- /dev/null
+++ b/jingle/notifier/base/signal_thread_task.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef JINGLE_NOTIFIER_BASE_SIGNAL_THREAD_TASK_H_
+#define JINGLE_NOTIFIER_BASE_SIGNAL_THREAD_TASK_H_
+
+#include "base/logging.h"
+#include "talk/base/common.h"
+#include "talk/base/signalthread.h"
+#include "talk/base/sigslot.h"
+#include "talk/base/task.h"
+
+namespace notifier {
+
+template<class T>
+class SignalThreadTask : public talk_base::Task,
+ public sigslot::has_slots<> {
+ public:
+ // Takes ownership of signal_thread.
+ SignalThreadTask(talk_base::Task* task_parent, T** signal_thread)
+ : talk_base::Task(task_parent),
+ signal_thread_(NULL),
+ finished_(false) {
+ SetSignalThread(signal_thread);
+ }
+
+ virtual ~SignalThreadTask() {
+ ClearSignalThread();
+ }
+
+ virtual void Stop() {
+ Task::Stop();
+ ClearSignalThread();
+ }
+
+ virtual int ProcessStart() {
+ DCHECK_EQ(GetState(), talk_base::Task::STATE_START);
+ signal_thread_->SignalWorkDone.connect(
+ this,
+ &SignalThreadTask<T>::OnWorkDone);
+ signal_thread_->Start();
+ return talk_base::Task::STATE_RESPONSE;
+ }
+
+ int ProcessResponse() {
+ if (!finished_) {
+ return talk_base::Task::STATE_BLOCKED;
+ }
+ SignalWorkDone(signal_thread_);
+ ClearSignalThread();
+ return talk_base::Task::STATE_DONE;
+ }
+
+ sigslot::signal1<T*> SignalWorkDone;
+
+ private:
+ // Takes ownership of signal_thread.
+ void SetSignalThread(T** signal_thread) {
+ DCHECK(!signal_thread_);
+ DCHECK(signal_thread);
+ DCHECK(*signal_thread);
+ // No one should be listening to the signal thread for work done.
+ // They should be using this class instead. Unfortunately, we
+ // can't verify this.
+
+ signal_thread_ = *signal_thread;
+
+ // Helps callers not to use signal thread after this point since this class
+ // has taken ownership (and avoid the error of doing
+ // signal_thread->Start()).
+ *signal_thread = NULL;
+ }
+
+ void OnWorkDone(talk_base::SignalThread* signal_thread) {
+ DCHECK_EQ(signal_thread, signal_thread_);
+ finished_ = true;
+ Wake();
+ }
+
+ void ClearSignalThread() {
+ if (signal_thread_) {
+ // Don't wait on the thread destruction, or we may deadlock.
+ signal_thread_->Destroy(false);
+ signal_thread_ = NULL;
+ }
+ }
+
+ T* signal_thread_;
+ bool finished_;
+ DISALLOW_COPY_AND_ASSIGN(SignalThreadTask);
+};
+
+} // namespace notifier
+
+#endif // JINGLE_NOTIFIER_BASE_SIGNAL_THREAD_TASK_H_
diff --git a/jingle/notifier/base/ssl_adapter.cc b/jingle/notifier/base/ssl_adapter.cc
new file mode 100644
index 0000000..2111244
--- /dev/null
+++ b/jingle/notifier/base/ssl_adapter.cc
@@ -0,0 +1,27 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "jingle/notifier/base/ssl_adapter.h"
+
+#if defined(OS_WIN)
+#include "talk/base/ssladapter.h"
+#else
+#include "jingle/notifier/communicator/ssl_socket_adapter.h"
+#endif
+
+namespace notifier {
+
+talk_base::SSLAdapter* CreateSSLAdapter(talk_base::AsyncSocket* socket) {
+ talk_base::SSLAdapter* ssl_adapter =
+#if defined(OS_WIN)
+ talk_base::SSLAdapter::Create(socket);
+#else
+ notifier::SSLSocketAdapter::Create(socket);
+#endif
+ DCHECK(ssl_adapter);
+ return ssl_adapter;
+}
+
+} // namespace notifier
+
diff --git a/jingle/notifier/base/ssl_adapter.h b/jingle/notifier/base/ssl_adapter.h
new file mode 100644
index 0000000..32517cd
--- /dev/null
+++ b/jingle/notifier/base/ssl_adapter.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef JINGLE_NOTIFIER_BASE_SSL_ADAPTER_H_
+#define JINGLE_NOTIFIER_BASE_SSL_ADAPTER_H_
+
+namespace talk_base {
+class AsyncSocket;
+class SSLAdapter;
+} // namespace talk_base
+
+namespace notifier {
+
+// Wraps the given socket in a platform-dependent SSLAdapter
+// implementation.
+talk_base::SSLAdapter* CreateSSLAdapter(talk_base::AsyncSocket* socket);
+
+// Utility template class that overrides CreateSSLAdapter() to use the
+// above function.
+template <class SocketFactory>
+class SSLAdapterSocketFactory : public SocketFactory {
+ public:
+ virtual talk_base::SSLAdapter* CreateSSLAdapter(
+ talk_base::AsyncSocket* socket) {
+ return ::notifier::CreateSSLAdapter(socket);
+ }
+};
+
+} // namespace notifier
+
+#endif // JINGLE_NOTIFIER_BASE_SSL_ADAPTER_H_
+
diff --git a/jingle/notifier/base/static_assert.h b/jingle/notifier/base/static_assert.h
new file mode 100644
index 0000000..58a8fe4
--- /dev/null
+++ b/jingle/notifier/base/static_assert.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef JINGLE_NOTIFIER_BASE_STATIC_ASSERT_H_
+#define JINGLE_NOTIFIER_BASE_STATIC_ASSERT_H_
+
+template<bool> struct STATIC_ASSERTION_FAILURE;
+
+template<> struct STATIC_ASSERTION_FAILURE<true> {
+ enum { value = 1 };
+};
+
+template<int> struct static_assert_test{};
+
+#define STATIC_ASSERT(B) \
+typedef static_assert_test<\
+ sizeof(STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
+ static_assert_typedef_ ## __LINE__
+
+#endif // JINGLE_NOTIFIER_BASE_STATIC_ASSERT_H_