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

Side by Side Diff: base/message_pump_win.cc

Issue 10407011: Making sure that base::MessagePumpForUI from different modules are isolated from each other. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_pump_win.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_pump_win.h" 5 #include "base/message_pump_win.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/process_util.h"
11 #include "base/win/wrapped_window_proc.h" 12 #include "base/win/wrapped_window_proc.h"
12 13
13 namespace base { 14 namespace base {
14 15
15 static const wchar_t kWndClass[] = L"Chrome_MessagePumpWindow"; 16 static const wchar_t kWndClass[] = L"Chrome_MessagePumpWindow";
16 17
17 // Message sent to get an additional time slice for pumping (processing) another 18 // Message sent to get an additional time slice for pumping (processing) another
18 // task (a series of such messages creates a continuous task pump). 19 // task (a series of such messages creates a continuous task pump).
19 static const int kMsgHaveWork = WM_USER + 1; 20 static const int kMsgHaveWork = WM_USER + 1;
20 21
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 int delay = static_cast<int>(timeout); 76 int delay = static_cast<int>(timeout);
76 if (delay < 0) 77 if (delay < 0)
77 delay = 0; 78 delay = 0;
78 79
79 return delay; 80 return delay;
80 } 81 }
81 82
82 //----------------------------------------------------------------------------- 83 //-----------------------------------------------------------------------------
83 // MessagePumpForUI public: 84 // MessagePumpForUI public:
84 85
85 MessagePumpForUI::MessagePumpForUI() { 86 MessagePumpForUI::MessagePumpForUI() : instance_(NULL) {
86 InitMessageWnd(); 87 InitMessageWnd();
87 } 88 }
88 89
89 MessagePumpForUI::~MessagePumpForUI() { 90 MessagePumpForUI::~MessagePumpForUI() {
90 DestroyWindow(message_hwnd_); 91 DestroyWindow(message_hwnd_);
91 UnregisterClass(kWndClass, GetModuleHandle(NULL)); 92 UnregisterClass(kWndClass, instance_);
92 } 93 }
93 94
94 void MessagePumpForUI::ScheduleWork() { 95 void MessagePumpForUI::ScheduleWork() {
95 if (InterlockedExchange(&have_work_, 1)) 96 if (InterlockedExchange(&have_work_, 1))
96 return; // Someone else continued the pumping. 97 return; // Someone else continued the pumping.
97 98
98 // Make sure the MessagePump does some work for us. 99 // Make sure the MessagePump does some work for us.
99 PostMessage(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0); 100 PostMessage(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0);
100 } 101 }
101 102
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 break; 224 break;
224 225
225 if (more_work_is_plausible) 226 if (more_work_is_plausible)
226 continue; 227 continue;
227 228
228 WaitForWork(); // Wait (sleep) until we have work to do again. 229 WaitForWork(); // Wait (sleep) until we have work to do again.
229 } 230 }
230 } 231 }
231 232
232 void MessagePumpForUI::InitMessageWnd() { 233 void MessagePumpForUI::InitMessageWnd() {
233 HINSTANCE hinst = GetModuleHandle(NULL);
234
235 WNDCLASSEX wc = {0}; 234 WNDCLASSEX wc = {0};
236 wc.cbSize = sizeof(wc); 235 wc.cbSize = sizeof(wc);
237 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; 236 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>;
238 wc.hInstance = hinst; 237 wc.hInstance = base::GetModuleFromAddress(wc.lpfnWndProc);
239 wc.lpszClassName = kWndClass; 238 wc.lpszClassName = kWndClass;
239 instance_ = wc.hInstance;
240 RegisterClassEx(&wc); 240 RegisterClassEx(&wc);
241 241
242 message_hwnd_ = 242 message_hwnd_ =
243 CreateWindow(kWndClass, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0); 243 CreateWindow(kWndClass, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance_, 0);
244 DCHECK(message_hwnd_); 244 DCHECK(message_hwnd_);
245 } 245 }
246 246
247 void MessagePumpForUI::WaitForWork() { 247 void MessagePumpForUI::WaitForWork() {
248 // Wait until a message is available, up to the time needed by the timer 248 // Wait until a message is available, up to the time needed by the timer
249 // manager to fire the next set of timers. 249 // manager to fire the next set of timers.
250 int delay = GetCurrentDelay(); 250 int delay = GetCurrentDelay();
251 if (delay < 0) // Negative value means no timers waiting. 251 if (delay < 0) // Negative value means no timers waiting.
252 delay = INFINITE; 252 delay = INFINITE;
253 253
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 574
575 void MessagePumpForIO::WillProcessIOEvent() { 575 void MessagePumpForIO::WillProcessIOEvent() {
576 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); 576 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent());
577 } 577 }
578 578
579 void MessagePumpForIO::DidProcessIOEvent() { 579 void MessagePumpForIO::DidProcessIOEvent() {
580 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); 580 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent());
581 } 581 }
582 582
583 } // namespace base 583 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698