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

Unified Diff: remoting/jingle_glue/jingle_thread.cc

Issue 2690003: Copy the (early prototype of) remoting in Chrome into the public tree.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/jingle_glue/jingle_thread.h ('k') | remoting/jingle_glue/jingle_thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/jingle_glue/jingle_thread.cc
===================================================================
--- remoting/jingle_glue/jingle_thread.cc (revision 0)
+++ remoting/jingle_glue/jingle_thread.cc (revision 0)
@@ -0,0 +1,80 @@
+// Copyright (c) 2010 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 "remoting/jingle_glue/jingle_thread.h"
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "talk/base/ssladapter.h"
+
+namespace remoting {
+
+const int kRunTasksMessageId = 1;
+
+TaskPump::TaskPump() {
+}
+
+void TaskPump::WakeTasks() {
+ talk_base::Thread::Current()->Post(this);
+}
+
+int64 TaskPump::CurrentTime() {
+ return static_cast<int64>(talk_base::Time());
+}
+
+void TaskPump::OnMessage(talk_base::Message* pmsg) {
+ RunTasks();
+}
+
+JingleThread::JingleThread()
+ : message_loop_(NULL),
+ task_pump_(NULL),
+ started_event_(true, false) { }
+
+JingleThread::~JingleThread() { }
+
+void JingleThread::Start() {
+ Thread::Start();
+ started_event_.Wait();
+}
+
+void JingleThread::Run() {
+ LOG(INFO) << "Started Jingle thread.";
+
+ MessageLoopForIO message_loop;
+ message_loop_ = &message_loop;
+
+ TaskPump task_pump;
+ task_pump_ = &task_pump;
+
+ // Signal after we've initialized |message_loop_| and |task_pump_|.
+ started_event_.Signal();
+
+ Post(this, kRunTasksMessageId);
+
+ Thread::Run();
+
+ message_loop.RunAllPending();
+
+ task_pump_ = NULL;
+ message_loop_ = NULL;
+
+ LOG(INFO) << "Jingle thread finished.";
+}
+
+// This method is called every 20ms to process tasks from |message_loop_|
+// on this thread.
+// TODO(sergeyu): Remove it when JingleThread moved to Chromium's base::Thread.
+void JingleThread::PumpAuxiliaryLoops() {
+ MessageLoop::current()->RunAllPending();
+
+ // Schedule next execution 20ms from now.
+ PostDelayed(20, this, kRunTasksMessageId);
+}
+
+void JingleThread::OnMessage(talk_base::Message* msg) {
+ PumpAuxiliaryLoops();
+}
+
+} // namespace remoting
Property changes on: remoting/jingle_glue/jingle_thread.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « remoting/jingle_glue/jingle_thread.h ('k') | remoting/jingle_glue/jingle_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698