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

Side by Side Diff: base/message_loop/message_pump_win.cc

Issue 17078005: Move message_pump to base/message_loop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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_loop/message_pump_win.h ('k') | base/message_pump.h » ('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) 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_loop/message_pump_win.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/win/wrapped_window_proc.h" 14 #include "base/win/wrapped_window_proc.h"
15 15
16 namespace base {
17
16 namespace { 18 namespace {
17 19
18 enum MessageLoopProblems { 20 enum MessageLoopProblems {
19 MESSAGE_POST_ERROR, 21 MESSAGE_POST_ERROR,
20 COMPLETION_POST_ERROR, 22 COMPLETION_POST_ERROR,
21 SET_TIMER_ERROR, 23 SET_TIMER_ERROR,
22 MESSAGE_LOOP_PROBLEM_MAX, 24 MESSAGE_LOOP_PROBLEM_MAX,
23 }; 25 };
24 26
25 } // namespace 27 } // namespace
26 28
27 namespace base {
28
29 static const wchar_t kWndClassFormat[] = L"Chrome_MessagePumpWindow_%p"; 29 static const wchar_t kWndClassFormat[] = L"Chrome_MessagePumpWindow_%p";
30 30
31 // Message sent to get an additional time slice for pumping (processing) another 31 // Message sent to get an additional time slice for pumping (processing) another
32 // task (a series of such messages creates a continuous task pump). 32 // task (a series of such messages creates a continuous task pump).
33 static const int kMsgHaveWork = WM_USER + 1; 33 static const int kMsgHaveWork = WM_USER + 1;
34 34
35 //----------------------------------------------------------------------------- 35 //-----------------------------------------------------------------------------
36 // MessagePumpWin public: 36 // MessagePumpWin public:
37 37
38 void MessagePumpWin::AddObserver(MessagePumpObserver* observer) { 38 void MessagePumpWin::AddObserver(MessagePumpObserver* observer) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 MessagePumpForUI::MessagePumpForUI() 99 MessagePumpForUI::MessagePumpForUI()
100 : atom_(0), 100 : atom_(0),
101 message_filter_(new MessageFilter) { 101 message_filter_(new MessageFilter) {
102 InitMessageWnd(); 102 InitMessageWnd();
103 } 103 }
104 104
105 MessagePumpForUI::~MessagePumpForUI() { 105 MessagePumpForUI::~MessagePumpForUI() {
106 DestroyWindow(message_hwnd_); 106 DestroyWindow(message_hwnd_);
107 UnregisterClass(MAKEINTATOM(atom_), 107 UnregisterClass(MAKEINTATOM(atom_),
108 base::GetModuleFromAddress(&WndProcThunk)); 108 GetModuleFromAddress(&WndProcThunk));
109 } 109 }
110 110
111 void MessagePumpForUI::ScheduleWork() { 111 void MessagePumpForUI::ScheduleWork() {
112 if (InterlockedExchange(&have_work_, 1)) 112 if (InterlockedExchange(&have_work_, 1))
113 return; // Someone else continued the pumping. 113 return; // Someone else continued the pumping.
114 114
115 // Make sure the MessagePump does some work for us. 115 // Make sure the MessagePump does some work for us.
116 BOOL ret = PostMessage(message_hwnd_, kMsgHaveWork, 116 BOOL ret = PostMessage(message_hwnd_, kMsgHaveWork,
117 reinterpret_cast<WPARAM>(this), 0); 117 reinterpret_cast<WPARAM>(this), 0);
118 if (ret) 118 if (ret)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 if (more_work_is_plausible) 265 if (more_work_is_plausible)
266 continue; 266 continue;
267 267
268 WaitForWork(); // Wait (sleep) until we have work to do again. 268 WaitForWork(); // Wait (sleep) until we have work to do again.
269 } 269 }
270 } 270 }
271 271
272 void MessagePumpForUI::InitMessageWnd() { 272 void MessagePumpForUI::InitMessageWnd() {
273 // Generate a unique window class name. 273 // Generate a unique window class name.
274 string16 class_name = base::StringPrintf(kWndClassFormat, this); 274 string16 class_name = StringPrintf(kWndClassFormat, this);
275 275
276 HINSTANCE instance = base::GetModuleFromAddress(&WndProcThunk); 276 HINSTANCE instance = GetModuleFromAddress(&WndProcThunk);
277 WNDCLASSEX wc = {0}; 277 WNDCLASSEX wc = {0};
278 wc.cbSize = sizeof(wc); 278 wc.cbSize = sizeof(wc);
279 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; 279 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>;
280 wc.hInstance = instance; 280 wc.hInstance = instance;
281 wc.lpszClassName = class_name.c_str(); 281 wc.lpszClassName = class_name.c_str();
282 atom_ = RegisterClassEx(&wc); 282 atom_ = RegisterClassEx(&wc);
283 DCHECK(atom_); 283 DCHECK(atom_);
284 284
285 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, 285 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0,
286 HWND_MESSAGE, 0, instance, 0); 286 HWND_MESSAGE, 0, instance, 0);
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 677
678 // static 678 // static
679 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( 679 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler(
680 ULONG_PTR key, 680 ULONG_PTR key,
681 bool* has_valid_io_context) { 681 bool* has_valid_io_context) {
682 *has_valid_io_context = ((key & 1) == 0); 682 *has_valid_io_context = ((key & 1) == 0);
683 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); 683 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1));
684 } 684 }
685 685
686 } // namespace base 686 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_win.h ('k') | base/message_pump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698