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_thread.h" | 5 #include "remoting/jingle_glue/jingle_thread.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_pump.h" | 9 #include "base/message_pump.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "third_party/libjingle/source/talk/base/ssladapter.h" | 11 #include "third_party/libjingle/source/talk/base/ssladapter.h" |
12 | 12 |
13 namespace remoting { | 13 namespace remoting { |
14 | 14 |
15 const uint32 kRunTasksMessageId = 1; | 15 const uint32 kRunTasksMessageId = 1; |
16 const uint32 kStopMessageId = 2; | 16 const uint32 kStopMessageId = 2; |
17 | 17 |
18 class JingleThread::JingleMessagePump : public base::MessagePump, | 18 class JingleThread::JingleMessagePump : public base::MessagePump, |
19 public talk_base::MessageHandler { | 19 public talk_base::MessageHandler { |
20 public: | 20 public: |
21 JingleMessagePump(JingleThread* thread) : thread_(thread) { } | 21 JingleMessagePump(JingleThread* thread) : thread_(thread) { } |
22 | 22 |
23 virtual void Run(Delegate* delegate) { NOTIMPLEMENTED(); } | 23 virtual void Run(Delegate* delegate) { NOTIMPLEMENTED(); } |
24 virtual void Quit() { NOTIMPLEMENTED(); } | 24 virtual void Quit() { NOTIMPLEMENTED(); } |
25 virtual void ScheduleWork() { | 25 virtual void ScheduleWork() { |
26 thread_->Post(this, kRunTasksMessageId); | 26 thread_->Post(this, kRunTasksMessageId); |
27 } | 27 } |
28 virtual void ScheduleDelayedWork(const base::Time& time) { | 28 virtual void ScheduleDelayedWork(const base::TimeTicks& time) { |
29 delayed_work_time_ = time; | 29 delayed_work_time_ = time; |
30 ScheduleNextDelayedTask(); | 30 ScheduleNextDelayedTask(); |
31 } | 31 } |
32 | 32 |
33 void OnMessage(talk_base::Message* msg) { | 33 void OnMessage(talk_base::Message* msg) { |
34 DCHECK(msg->message_id == kRunTasksMessageId); | 34 DCHECK(msg->message_id == kRunTasksMessageId); |
35 | 35 |
36 // Clear currently pending messages in case there were delayed tasks. | 36 // Clear currently pending messages in case there were delayed tasks. |
37 // Will schedule it again from ScheduleNextDelayedTask() if neccessary. | 37 // Will schedule it again from ScheduleNextDelayedTask() if neccessary. |
38 thread_->Clear(this, kRunTasksMessageId); | 38 thread_->Clear(this, kRunTasksMessageId); |
(...skipping 20 matching lines...) Expand all Loading... |
59 | 59 |
60 ScheduleNextDelayedTask(); | 60 ScheduleNextDelayedTask(); |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 | 64 |
65 void ScheduleNextDelayedTask() { | 65 void ScheduleNextDelayedTask() { |
66 DCHECK_EQ(thread_->message_loop(), MessageLoop::current()); | 66 DCHECK_EQ(thread_->message_loop(), MessageLoop::current()); |
67 | 67 |
68 if (!delayed_work_time_.is_null()) { | 68 if (!delayed_work_time_.is_null()) { |
69 base::Time now = base::Time::Now(); | 69 base::TimeTicks now = base::TimeTicks::Now(); |
70 int delay = static_cast<int>((delayed_work_time_ - now).InMilliseconds()); | 70 int delay = static_cast<int>((delayed_work_time_ - now).InMilliseconds()); |
71 if (delay > 0) { | 71 if (delay > 0) { |
72 thread_->PostDelayed(delay, this, kRunTasksMessageId); | 72 thread_->PostDelayed(delay, this, kRunTasksMessageId); |
73 } else { | 73 } else { |
74 thread_->Post(this, kRunTasksMessageId); | 74 thread_->Post(this, kRunTasksMessageId); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 JingleThread* thread_; | 79 JingleThread* thread_; |
80 base::Time delayed_work_time_; | 80 base::TimeTicks delayed_work_time_; |
81 }; | 81 }; |
82 | 82 |
83 class JingleThread::JingleMessageLoop : public MessageLoop { | 83 class JingleThread::JingleMessageLoop : public MessageLoop { |
84 public: | 84 public: |
85 JingleMessageLoop(JingleThread* thread) | 85 JingleMessageLoop(JingleThread* thread) |
86 : MessageLoop(MessageLoop::TYPE_IO) { | 86 : MessageLoop(MessageLoop::TYPE_IO) { |
87 pump_ = new JingleMessagePump(thread); | 87 pump_ = new JingleMessagePump(thread); |
88 } | 88 } |
89 }; | 89 }; |
90 | 90 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Stop the thread only if there are no more messages left in the queue, | 160 // Stop the thread only if there are no more messages left in the queue, |
161 // otherwise post another task to try again later. | 161 // otherwise post another task to try again later. |
162 if (msgq_.size() > 0 || fPeekKeep_) { | 162 if (msgq_.size() > 0 || fPeekKeep_) { |
163 Post(this, kStopMessageId); | 163 Post(this, kStopMessageId); |
164 } else { | 164 } else { |
165 MessageQueue::Quit(); | 165 MessageQueue::Quit(); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |