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

Side by Side Diff: base/win/message_window.h

Issue 2824533002: Migrate Bind to BindOnce or BindRepeating in //base/message_loop (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef BASE_WIN_MESSAGE_WINDOW_H_ 5 #ifndef BASE_WIN_MESSAGE_WINDOW_H_
6 #define BASE_WIN_MESSAGE_WINDOW_H_ 6 #define BASE_WIN_MESSAGE_WINDOW_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 16
17 namespace base { 17 namespace base {
18 namespace win { 18 namespace win {
19 19
20 // Implements a message-only window. 20 // Implements a message-only window.
21 class BASE_EXPORT MessageWindow : public base::NonThreadSafe { 21 class BASE_EXPORT MessageWindow : public base::NonThreadSafe {
22 public: 22 public:
23 // Used to register a process-wide message window class. 23 // Used to register a process-wide message window class.
24 class WindowClass; 24 class WindowClass;
25 25
26 // Implement this callback to handle messages received by the message window. 26 // Implement this callback to handle messages received by the message window.
27 // If the callback returns |false|, the first four parameters are passed to 27 // If the callback returns |false|, the first four parameters are passed to
28 // DefWindowProc(). Otherwise, |*result| is returned by the window procedure. 28 // DefWindowProc(). Otherwise, |*result| is returned by the window procedure.
29 typedef base::Callback<bool(UINT message, 29 using MessageCallback = base::RepeatingCallback<
30 WPARAM wparam, 30 bool(UINT message, WPARAM wparam, LPARAM lparam, LRESULT* result)>;
31 LPARAM lparam,
32 LRESULT* result)> MessageCallback;
33 31
34 MessageWindow(); 32 MessageWindow();
35 ~MessageWindow(); 33 ~MessageWindow();
36 34
37 // Creates a message-only window. The incoming messages will be passed by 35 // Creates a message-only window. The incoming messages will be passed by
38 // |message_callback|. |message_callback| must outlive |this|. 36 // |message_callback|. |message_callback| must outlive |this|.
39 bool Create(const MessageCallback& message_callback); 37 bool Create(MessageCallback message_callback);
40 38
41 // Same as Create() but assigns the name to the created window. 39 // Same as Create() but assigns the name to the created window.
42 bool CreateNamed(const MessageCallback& message_callback, 40 bool CreateNamed(MessageCallback message_callback,
43 const string16& window_name); 41 const string16& window_name);
44 42
45 HWND hwnd() const { return window_; } 43 HWND hwnd() const { return window_; }
46 44
47 // Retrieves a handle of the first message-only window with matching 45 // Retrieves a handle of the first message-only window with matching
48 // |window_name|. 46 // |window_name|.
49 static HWND FindWindow(const string16& window_name); 47 static HWND FindWindow(const string16& window_name);
50 48
51 private: 49 private:
52 // Give |WindowClass| access to WindowProc(). 50 // Give |WindowClass| access to WindowProc().
53 friend class WindowClass; 51 friend class WindowClass;
54 52
55 // Contains the actual window creation code. 53 // Contains the actual window creation code.
56 bool DoCreate(const MessageCallback& message_callback, 54 bool DoCreate(MessageCallback message_callback, const wchar_t* window_name);
57 const wchar_t* window_name);
58 55
59 // Invoked by the OS to process incoming window messages. 56 // Invoked by the OS to process incoming window messages.
60 static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, 57 static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam,
61 LPARAM lparam); 58 LPARAM lparam);
62 59
63 // Invoked to handle messages received by the window. 60 // Invoked to handle messages received by the window.
64 MessageCallback message_callback_; 61 MessageCallback message_callback_;
65 62
66 // Handle of the input window. 63 // Handle of the input window.
67 HWND window_; 64 HWND window_;
68 65
69 DISALLOW_COPY_AND_ASSIGN(MessageWindow); 66 DISALLOW_COPY_AND_ASSIGN(MessageWindow);
70 }; 67 };
71 68
72 } // namespace win 69 } // namespace win
73 } // namespace base 70 } // namespace base
74 71
75 #endif // BASE_WIN_MESSAGE_WINDOW_H_ 72 #endif // BASE_WIN_MESSAGE_WINDOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698