| 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 #include "chrome_frame/task_marshaller.h" | 5 #include "chrome_frame/task_marshaller.h" |
| 5 #include "base/task.h" | 6 #include "base/task.h" |
| 6 | 7 |
| 7 TaskMarshallerThroughMessageQueue::TaskMarshallerThroughMessageQueue() { | 8 TaskMarshallerThroughMessageQueue::TaskMarshallerThroughMessageQueue() { |
| 8 wnd_ = NULL; | 9 wnd_ = NULL; |
| 9 msg_ = 0xFFFF; | 10 msg_ = 0xFFFF; |
| 10 } | 11 } |
| 11 | 12 |
| 12 TaskMarshallerThroughMessageQueue::~TaskMarshallerThroughMessageQueue() { | 13 TaskMarshallerThroughMessageQueue::~TaskMarshallerThroughMessageQueue() { |
| 13 DeleteAll(); | 14 DeleteAll(); |
| 14 } | 15 } |
| 15 | 16 |
| 16 void TaskMarshallerThroughMessageQueue::PostTask( | 17 void TaskMarshallerThroughMessageQueue::PostTask( |
| 17 const tracked_objects::Location& from_here, Task* task) { | 18 const tracked_objects::Location& from_here, Task* task) { |
| 18 DCHECK(wnd_ != NULL); | 19 DCHECK(wnd_ != NULL); |
| 19 task->SetBirthPlace(from_here); | 20 task->SetBirthPlace(from_here); |
| 20 lock_.Acquire(); | 21 lock_.Acquire(); |
| 21 bool has_work = !pending_tasks_.empty(); | 22 bool has_work = !pending_tasks_.empty(); |
| 22 pending_tasks_.push(task); | 23 pending_tasks_.push(task); |
| 23 lock_.Release(); | 24 lock_.Release(); |
| 24 | 25 |
| 25 // Don't post message if there is already one. | 26 // Don't post message if there is already one. |
| 26 if (has_work) | 27 if (has_work) |
| 27 return; | 28 return; |
| 28 | 29 |
| 29 if (!::PostMessage(wnd_, msg_, 0, 0)) { | 30 if (!::PostMessage(wnd_, msg_, 0, 0)) { |
| 30 DLOG(INFO) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; | 31 DVLOG(1) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; |
| 31 DeleteAll(); | 32 DeleteAll(); |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 void TaskMarshallerThroughMessageQueue::PostDelayedTask( | 36 void TaskMarshallerThroughMessageQueue::PostDelayedTask( |
| 36 const tracked_objects::Location& source, Task* task, | 37 const tracked_objects::Location& source, |
| 38 Task* task, |
| 37 base::TimeDelta& delay) { | 39 base::TimeDelta& delay) { |
| 38 DCHECK(wnd_ != NULL); | 40 DCHECK(wnd_ != NULL); |
| 39 AutoLock lock(lock_); | 41 AutoLock lock(lock_); |
| 40 DelayedTask delayed_task(task, base::Time::Now() + delay); | 42 DelayedTask delayed_task(task, base::Time::Now() + delay); |
| 41 delayed_tasks_.push(delayed_task); | 43 delayed_tasks_.push(delayed_task); |
| 42 // If we become the 'top' task - reschedule the timer. | 44 // If we become the 'top' task - reschedule the timer. |
| 43 if (delayed_tasks_.top().task == task) { | 45 if (delayed_tasks_.top().task == task) { |
| 44 ::SetTimer(wnd_, reinterpret_cast<UINT_PTR>(this), | 46 ::SetTimer(wnd_, reinterpret_cast<UINT_PTR>(this), |
| 45 static_cast<DWORD>(delay.InMilliseconds()), NULL); | 47 static_cast<DWORD>(delay.InMilliseconds()), NULL); |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 | 50 |
| 49 BOOL TaskMarshallerThroughMessageQueue::ProcessWindowMessage(HWND hWnd, | 51 BOOL TaskMarshallerThroughMessageQueue::ProcessWindowMessage(HWND hWnd, |
| 50 UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, | 52 UINT uMsg, |
| 51 DWORD dwMsgMapID) { | 53 WPARAM wParam, |
| 54 LPARAM lParam, |
| 55 LRESULT& lResult, |
| 56 DWORD dwMsgMapID) { |
| 52 if (hWnd == wnd_ && uMsg == msg_) { | 57 if (hWnd == wnd_ && uMsg == msg_) { |
| 53 ExecuteQueuedTasks(); | 58 ExecuteQueuedTasks(); |
| 54 lResult = 0; | 59 lResult = 0; |
| 55 return TRUE; | 60 return TRUE; |
| 56 } | 61 } |
| 57 | 62 |
| 58 if (hWnd == wnd_ && uMsg == WM_TIMER) { | 63 if (hWnd == wnd_ && uMsg == WM_TIMER) { |
| 59 ExecuteDelayedTasks(); | 64 ExecuteDelayedTasks(); |
| 60 lResult = 0; | 65 lResult = 0; |
| 61 return TRUE; | 66 return TRUE; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 if (run_at < other.run_at) | 148 if (run_at < other.run_at) |
| 144 return false; | 149 return false; |
| 145 | 150 |
| 146 if (run_at > other.run_at) | 151 if (run_at > other.run_at) |
| 147 return true; | 152 return true; |
| 148 | 153 |
| 149 // If the times happen to match, then we use the sequence number to decide. | 154 // If the times happen to match, then we use the sequence number to decide. |
| 150 // Compare the difference to support integer roll-over. | 155 // Compare the difference to support integer roll-over. |
| 151 return (seq - other.seq) > 0; | 156 return (seq - other.seq) > 0; |
| 152 } | 157 } |
| OLD | NEW |