OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <mmsystem.h> | 10 #include <mmsystem.h> |
darin (slow to review)
2008/09/08 18:15:22
nit: please kill this include
| |
11 #endif | 11 #endif |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_pump_default.h" | 15 #include "base/message_pump_default.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/thread_local_storage.h" | 17 #include "base/thread_local_storage.h" |
18 | 18 |
19 // a TLS index to the message loop for the current thread | 19 // a TLS index to the message loop for the current thread |
20 // Note that if we start doing complex stuff in other static initializers | 20 // Note that if we start doing complex stuff in other static initializers |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 | 61 |
62 MessageLoop::MessageLoop(Type type) | 62 MessageLoop::MessageLoop(Type type) |
63 : type_(type), | 63 : type_(type), |
64 nestable_tasks_allowed_(true), | 64 nestable_tasks_allowed_(true), |
65 exception_restoration_(false), | 65 exception_restoration_(false), |
66 state_(NULL), | 66 state_(NULL), |
67 next_sequence_num_(0) { | 67 next_sequence_num_(0) { |
68 DCHECK(!tls_index_.Get()) << "should only have one message loop per thread"; | 68 DCHECK(!tls_index_.Get()) << "should only have one message loop per thread"; |
69 tls_index_.Set(this); | 69 tls_index_.Set(this); |
70 | 70 |
71 // TODO(darin): This does not seem like the best place for this code to live! | |
72 #if defined(OS_WIN) | |
73 // We've experimented with all sorts of timers, and initially tried | |
74 // to avoid using timeBeginPeriod because it does affect the system | |
75 // globally. However, after much investigation, it turns out that all | |
76 // of the major plugins (flash, windows media 9-11, and quicktime) | |
77 // already use timeBeginPeriod to increase the speed of the clock. | |
78 // Since the browser must work with these plugins, the browser already | |
79 // needs to support a fast clock. We may as well use this ourselves, | |
80 // as it really is the best timer mechanism for our needs. | |
81 timeBeginPeriod(1); | |
82 #endif | |
83 | |
84 // TODO(darin): Choose the pump based on the requested type. | 71 // TODO(darin): Choose the pump based on the requested type. |
85 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
86 if (type_ == TYPE_DEFAULT) { | 73 if (type_ == TYPE_DEFAULT) { |
87 pump_ = new base::MessagePumpDefault(); | 74 pump_ = new base::MessagePumpDefault(); |
88 } else { | 75 } else { |
89 pump_ = new base::MessagePumpWin(); | 76 pump_ = new base::MessagePumpWin(); |
90 } | 77 } |
91 #else | 78 #else |
92 pump_ = new base::MessagePumpDefault(); | 79 pump_ = new base::MessagePumpDefault(); |
93 #endif | 80 #endif |
(...skipping 18 matching lines...) Expand all Loading... | |
112 DeletePendingTasks(); | 99 DeletePendingTasks(); |
113 ReloadWorkQueue(); | 100 ReloadWorkQueue(); |
114 DeletePendingTasks(); | 101 DeletePendingTasks(); |
115 | 102 |
116 // Delete tasks in the delayed work queue. | 103 // Delete tasks in the delayed work queue. |
117 while (!delayed_work_queue_.empty()) { | 104 while (!delayed_work_queue_.empty()) { |
118 Task* task = delayed_work_queue_.top().task; | 105 Task* task = delayed_work_queue_.top().task; |
119 delayed_work_queue_.pop(); | 106 delayed_work_queue_.pop(); |
120 delete task; | 107 delete task; |
121 } | 108 } |
122 | |
123 #if defined(OS_WIN) | |
124 // Match timeBeginPeriod() from construction. | |
125 timeEndPeriod(1); | |
126 #endif | |
127 } | 109 } |
128 | 110 |
129 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { | 111 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { |
130 DCHECK(this == current()); | 112 DCHECK(this == current()); |
131 destruction_observers_.AddObserver(obs); | 113 destruction_observers_.AddObserver(obs); |
132 } | 114 } |
133 | 115 |
134 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { | 116 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { |
135 DCHECK(this == current()); | 117 DCHECK(this == current()); |
136 destruction_observers_.RemoveObserver(obs); | 118 destruction_observers_.RemoveObserver(obs); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 //------------------------------------------------------------------------------ | 532 //------------------------------------------------------------------------------ |
551 // MessageLoopForIO | 533 // MessageLoopForIO |
552 | 534 |
553 #if defined(OS_WIN) | 535 #if defined(OS_WIN) |
554 | 536 |
555 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { | 537 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { |
556 pump_win()->WatchObject(object, watcher); | 538 pump_win()->WatchObject(object, watcher); |
557 } | 539 } |
558 | 540 |
559 #endif // defined(OS_WIN) | 541 #endif // defined(OS_WIN) |
OLD | NEW |