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

Unified Diff: chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h

Issue 14208014: Simplify adding callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h
diff --git a/chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h b/chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..38b50ed67d02ae7e5e08fdedfb6f5337aae309e0
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h
@@ -0,0 +1,131 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
+
+#include <cstddef>
+#include <string>
+
+#include "base/string16.h"
+#include "base/values.h"
+
+namespace chromeos {
+
+template<typename T>
+struct UnwrapConstRef {
+ typedef T Type;
+};
+
+template<typename T>
+struct UnwrapConstRef<const T&> {
+ typedef T Type;
+};
+
+template<typename T>
+inline bool GetArg(const base::ListValue* args, size_t index, T* out_value);
+
+template<>
+inline bool GetArg<bool>(const base::ListValue* args,
+ size_t index,
+ bool* out_value) {
+ return args->GetBoolean(index, out_value);
+}
+
+template<>
+inline bool GetArg<int>(const base::ListValue* args,
+ size_t index,
+ int* out_value) {
+ return args->GetInteger(index, out_value);
+}
+
+template<>
+inline bool GetArg<double>(const base::ListValue* args,
+ size_t index,
+ double* out_value) {
+ return args->GetDouble(index, out_value);
+}
+
+template<>
+inline bool GetArg<std::string>(const base::ListValue* args,
+ size_t index,
+ std::string* out_value) {
+ return args->GetString(index, out_value);
+}
+
+template<>
+inline bool GetArg<string16>(const base::ListValue* args,
+ size_t index,
+ string16* out_value) {
+ return args->GetString(index, out_value);
+}
+
+inline void CallbackWrapper0(base::Callback<void()> callback,
bartfab (slow) 2013/04/16 17:04:35 #include "base/callback.h"
ygorshenin1 2013/04/16 17:52:43 Done.
+ const base::ListValue* args) {
+ DCHECK(args && args->empty());
bartfab (slow) 2013/04/16 17:04:35 Nit 1: #include "base/logging.h" Nit 2: Split into
ygorshenin1 2013/04/16 17:52:43 Done.
ygorshenin1 2013/04/16 17:52:43 Done.
+ callback.Run();
+}
+
+template<typename A1>
+void CallbackWrapper1(base::Callback<void(A1)> callback,
+ const base::ListValue* args) {
+ DCHECK(args && args->GetSize() == 1);
bartfab (slow) 2013/04/16 17:04:35 Nit 1: Split into two DCHECKs Nit 2: Use DCHECK_EQ
ygorshenin1 2013/04/16 17:52:43 Done.
+ typename UnwrapConstRef<A1>::Type arg1;
+ if (!GetArg(args, 0, &arg1)) {
+ NOTREACHED();
+ return;
+ }
+ callback.Run(arg1);
+}
+
+template<typename A1, typename A2>
+void CallbackWrapper2(base::Callback<void(A1, A2)> callback,
+ const base::ListValue* args) {
+ DCHECK(args && args->GetSize() == 2);
bartfab (slow) 2013/04/16 17:04:35 Nit 1: Split into two DCHECKs Nit 2: Use DCHECK_EQ
ygorshenin1 2013/04/16 17:52:43 Done.
+ typename UnwrapConstRef<A1>::Type arg1;
+ typename UnwrapConstRef<A2>::Type arg2;
+ if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2)) {
+ NOTREACHED();
+ return;
+ }
+ callback.Run(arg1, arg2);
+}
+
+template<typename A1, typename A2, typename A3>
+void CallbackWrapper3(base::Callback<void(A1, A2, A3)> callback,
+ const base::ListValue* args) {
+ DCHECK(args && args->GetSize() == 3);
bartfab (slow) 2013/04/16 17:04:35 Nit 1: Split into two DCHECKs Nit 2: Use DCHECK_EQ
ygorshenin1 2013/04/16 17:52:43 Done.
+ typename UnwrapConstRef<A1>::Type arg1;
+ typename UnwrapConstRef<A2>::Type arg2;
+ typename UnwrapConstRef<A3>::Type arg3;
+ if (!GetArg(args, 0, &arg1) ||
+ !GetArg(args, 1, &arg2) ||
+ !GetArg(args, 2, &arg3)) {
+ NOTREACHED();
+ return;
+ }
+ callback.Run(arg1, arg2, arg3);
+}
+
+template<typename A1, typename A2, typename A3, typename A4>
+void CallbackWrapper4(base::Callback<void(A1, A2, A3, A4)> callback,
+ const base::ListValue* args) {
+ DCHECK(args && args->GetSize() == 4);
bartfab (slow) 2013/04/16 17:04:35 Nit 1: Split into two DCHECKs Nit 2: Use DCHECK_EQ
ygorshenin1 2013/04/16 17:52:43 Done.
+ typename UnwrapConstRef<A1>::Type arg1;
+ typename UnwrapConstRef<A2>::Type arg2;
+ typename UnwrapConstRef<A3>::Type arg3;
+ typename UnwrapConstRef<A4>::Type arg4;
+ if (!GetArg(args, 0, &arg1) ||
+ !GetArg(args, 1, &arg2) ||
+ !GetArg(args, 2, &arg3) ||
+ !GetArg(args, 3, &arg4)) {
+ NOTREACHED();
+ return;
+ }
+ callback.Run(arg1, arg2, arg3, arg4);
+}
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_

Powered by Google App Engine
This is Rietveld 408576698