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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/base_screen_handler.h

Issue 14208014: Simplify adding callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 7 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h"
13 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_message_handler.h" 16 #include "content/public/browser/web_ui_message_handler.h"
15 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
16 18
17 namespace base { 19 namespace base {
18 class DictionaryValue; 20 class DictionaryValue;
19 class ListValue; 21 class ListValue;
20 class Value; 22 class Value;
21 } 23 }
22 24
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void CallJS(const std::string& method, 100 void CallJS(const std::string& method,
99 const base::Value& arg1, 101 const base::Value& arg1,
100 const base::Value& arg2, 102 const base::Value& arg2,
101 const base::Value& arg3); 103 const base::Value& arg3);
102 void CallJS(const std::string& method, 104 void CallJS(const std::string& method,
103 const base::Value& arg1, 105 const base::Value& arg1,
104 const base::Value& arg2, 106 const base::Value& arg2,
105 const base::Value& arg3, 107 const base::Value& arg3,
106 const base::Value& arg4); 108 const base::Value& arg4);
107 109
108 // Shortcut method for adding WebUI callbacks. 110 // Shortcut methods for adding WebUI callbacks.
109 template<typename T> 111 template<typename T>
112 void AddRawCallback(const std::string& name,
113 void (T::*method)(const base::ListValue* args)) {
114 web_ui()->RegisterMessageCallback(
115 name,
116 base::Bind(method, base::Unretained(static_cast<T*>(this))));
117 }
118
119 template<typename T>
120 void AddCallback(const std::string& name, void (T::*method)()) {
121 base::Callback<void()> callback =
122 base::Bind(method, base::Unretained(static_cast<T*>(this)));
123 web_ui()->RegisterMessageCallback(
124 name, base::Bind(&CallbackWrapper0, callback));
125 }
126
127 template<typename T, typename A1>
128 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) {
129 base::Callback<void(A1)> callback =
130 base::Bind(method, base::Unretained(static_cast<T*>(this)));
131 web_ui()->RegisterMessageCallback(
132 name, base::Bind(&CallbackWrapper1<A1>, callback));
133 }
134
135 template<typename T, typename A1, typename A2>
110 void AddCallback(const std::string& name, 136 void AddCallback(const std::string& name,
111 void (T::*callback)(const base::ListValue* args)) { 137 void (T::*method)(A1 arg1, A2 arg2)) {
112 web_ui()->RegisterMessageCallback(name, 138 base::Callback<void(A1, A2)> callback =
113 base::Bind(callback, base::Unretained(static_cast<T*>(this)))); 139 base::Bind(method, base::Unretained(static_cast<T*>(this)));
140 web_ui()->RegisterMessageCallback(
141 name, base::Bind(&CallbackWrapper2<A1, A2>, callback));
142 }
143
144 template<typename T, typename A1, typename A2, typename A3>
145 void AddCallback(const std::string& name,
146 void (T::*method)(A1 arg1, A2 arg2, A3 arg3)) {
147 base::Callback<void(A1, A2, A3)> callback =
148 base::Bind(method, base::Unretained(static_cast<T*>(this)));
149 web_ui()->RegisterMessageCallback(
150 name, base::Bind(&CallbackWrapper3<A1, A2, A3>, callback));
151 }
152
153 template<typename T, typename A1, typename A2, typename A3, typename A4>
154 void AddCallback(const std::string& name,
155 void (T::*method)(A1 arg1, A2 arg2, A3 arg3, A4 arg4)) {
156 base::Callback<void(A1, A2, A3, A4)> callback =
157 base::Bind(method, base::Unretained(static_cast<T*>(this)));
158 web_ui()->RegisterMessageCallback(
159 name, base::Bind(&CallbackWrapper4<A1, A2, A3, A4>, callback));
114 } 160 }
115 161
116 // Called when the page is ready and handler can do initialization. 162 // Called when the page is ready and handler can do initialization.
117 virtual void Initialize() = 0; 163 virtual void Initialize() = 0;
118 164
119 // Show selected WebUI |screen|. Optionally it can pass screen initialization 165 // Show selected WebUI |screen|. Optionally it can pass screen initialization
120 // data via |data| parameter. 166 // data via |data| parameter.
121 void ShowScreen(const char* screen, const base::DictionaryValue* data); 167 void ShowScreen(const char* screen, const base::DictionaryValue* data);
122 168
123 // Whether page is ready. 169 // Whether page is ready.
124 bool page_is_ready() const { return page_is_ready_; } 170 bool page_is_ready() const { return page_is_ready_; }
125 171
126 // Returns the window which shows us. 172 // Returns the window which shows us.
127 virtual gfx::NativeWindow GetNativeWindow(); 173 virtual gfx::NativeWindow GetNativeWindow();
128 174
129 private: 175 private:
130 // Keeps whether page is ready. 176 // Keeps whether page is ready.
131 bool page_is_ready_; 177 bool page_is_ready_;
132 178
133 base::DictionaryValue* localized_values_; 179 base::DictionaryValue* localized_values_;
134 180
135 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); 181 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler);
136 }; 182 };
137 183
138 } // namespace chromeos 184 } // namespace chromeos
139 185
140 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ 186 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698