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

Side by Side Diff: remoting/jingle_glue/jingle_thread.cc

Issue 6003003: Fix crash in JingleThread caused by non-nestable tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/sync
Patch Set: Addressed comments Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/jingle_glue/jingle_thread_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 24 matching lines...) Expand all
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);
39 39
40 // This code is executed whenever we get new message in |message_loop_|. 40 // This code is executed whenever we get new message in |message_loop_|.
41 // JingleMessagePump posts new tasks in the jingle thread. 41 // JingleMessagePump posts new tasks in the jingle thread.
42 // TODO(sergeyu): Remove it when JingleThread moved on Chromium's 42 // TODO(sergeyu): Remove it when JingleThread moved on Chromium's
43 // base::Thread. 43 // base::Thread.
44 base::MessagePump::Delegate* delegate = thread_->message_loop(); 44 base::MessagePump::Delegate* delegate = thread_->message_loop();
45 // Loop until we run out of work.
46 while (true) {
47 if (!delegate->DoWork())
48 break;
49 }
50
51 // Process all pending tasks. 45 // Process all pending tasks.
52 while (true) { 46 while (true) {
53 if (delegate->DoWork()) 47 if (delegate->DoWork())
54 continue; 48 continue;
55 if (delegate->DoDelayedWork(&delayed_work_time_)) 49 if (delegate->DoDelayedWork(&delayed_work_time_))
56 continue; 50 continue;
57 break; 51 break;
58 } 52 }
59 53
60 ScheduleNextDelayedTask(); 54 ScheduleNextDelayedTask();
61 } 55 }
62 56
63 private: 57 private:
64
65 void ScheduleNextDelayedTask() { 58 void ScheduleNextDelayedTask() {
66 DCHECK_EQ(thread_->message_loop(), MessageLoop::current()); 59 DCHECK_EQ(thread_->message_loop(), MessageLoop::current());
67 60
68 if (!delayed_work_time_.is_null()) { 61 if (!delayed_work_time_.is_null()) {
69 base::TimeTicks now = base::TimeTicks::Now(); 62 base::TimeTicks now = base::TimeTicks::Now();
70 int delay = static_cast<int>((delayed_work_time_ - now).InMilliseconds()); 63 int delay = static_cast<int>((delayed_work_time_ - now).InMilliseconds());
71 if (delay > 0) { 64 if (delay > 0) {
72 thread_->PostDelayed(delay, this, kRunTasksMessageId); 65 thread_->PostDelayed(delay, this, kRunTasksMessageId);
73 } else { 66 } else {
74 thread_->Post(this, kRunTasksMessageId); 67 thread_->Post(this, kRunTasksMessageId);
75 } 68 }
76 } 69 }
77 } 70 }
78 71
79 JingleThread* thread_; 72 JingleThread* thread_;
80 base::TimeTicks delayed_work_time_; 73 base::TimeTicks delayed_work_time_;
81 }; 74 };
82 75
83 class JingleThread::JingleMessageLoop : public MessageLoop { 76 class JingleThread::JingleMessageLoop : public MessageLoop {
84 public: 77 public:
85 JingleMessageLoop(JingleThread* thread) 78 JingleMessageLoop(JingleThread* thread)
86 : MessageLoop(MessageLoop::TYPE_IO) { 79 : MessageLoop(MessageLoop::TYPE_IO) {
87 pump_ = new JingleMessagePump(thread); 80 pump_ = new JingleMessagePump(thread);
88 } 81 }
82
83 void Initialize() {
84 jingle_message_loop_state_.reset(new AutoRunState(this));
85 }
86
87 private:
88 // AutoRunState sets |state_| for this message loop. It needs to be
89 // created here because we never call Run() or RunAllPending() for
90 // the thread.
91 scoped_ptr<AutoRunState> jingle_message_loop_state_;
89 }; 92 };
90 93
91 TaskPump::TaskPump() { 94 TaskPump::TaskPump() {
92 } 95 }
93 96
94 void TaskPump::WakeTasks() { 97 void TaskPump::WakeTasks() {
95 talk_base::Thread::Current()->Post(this); 98 talk_base::Thread::Current()->Post(this);
96 } 99 }
97 100
98 int64 TaskPump::CurrentTime() { 101 int64 TaskPump::CurrentTime() {
(...skipping 14 matching lines...) Expand all
113 JingleThread::~JingleThread() { } 116 JingleThread::~JingleThread() { }
114 117
115 void JingleThread::Start() { 118 void JingleThread::Start() {
116 Thread::Start(); 119 Thread::Start();
117 started_event_.Wait(); 120 started_event_.Wait();
118 } 121 }
119 122
120 void JingleThread::Run() { 123 void JingleThread::Run() {
121 JingleMessageLoop message_loop(this); 124 JingleMessageLoop message_loop(this);
122 message_loop_ = &message_loop; 125 message_loop_ = &message_loop;
126 message_loop.Initialize();
awong 2010/12/23 23:02:49 Do this before assigning it to the member variable
Sergey Ulanov 2010/12/23 23:37:53 Done.
123 127
124 TaskPump task_pump; 128 TaskPump task_pump;
125 task_pump_ = &task_pump; 129 task_pump_ = &task_pump;
126 130
127 // Signal after we've initialized |message_loop_| and |task_pump_|. 131 // Signal after we've initialized |message_loop_| and |task_pump_|.
128 started_event_.Signal(); 132 started_event_.Signal();
129 133
130 Thread::Run(); 134 Thread::Run();
131 135
132 stopped_event_.Signal(); 136 stopped_event_.Signal();
(...skipping 27 matching lines...) Expand all
160 // Stop the thread only if there are no more messages left in the queue, 164 // Stop the thread only if there are no more messages left in the queue,
161 // otherwise post another task to try again later. 165 // otherwise post another task to try again later.
162 if (msgq_.size() > 0 || fPeekKeep_) { 166 if (msgq_.size() > 0 || fPeekKeep_) {
163 Post(this, kStopMessageId); 167 Post(this, kStopMessageId);
164 } else { 168 } else {
165 MessageQueue::Quit(); 169 MessageQueue::Quit();
166 } 170 }
167 } 171 }
168 172
169 } // namespace remoting 173 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/jingle_glue/jingle_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698