OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ | |
7 | |
8 #include <cstddef> | |
9 #include <string> | |
10 | |
11 #include "base/string16.h" | |
12 #include "base/values.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 template<typename T> | |
17 struct UnwrapConstRef { | |
18 typedef T Type; | |
19 }; | |
20 | |
21 template<typename T> | |
22 struct UnwrapConstRef<const T&> { | |
23 typedef T Type; | |
24 }; | |
25 | |
26 template<typename T> | |
27 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value); | |
28 | |
29 template<> | |
30 inline bool GetArg<bool>(const base::ListValue* args, | |
31 size_t index, | |
32 bool* out_value) { | |
33 return args->GetBoolean(index, out_value); | |
34 } | |
35 | |
36 template<> | |
37 inline bool GetArg<int>(const base::ListValue* args, | |
38 size_t index, | |
39 int* out_value) { | |
40 return args->GetInteger(index, out_value); | |
41 } | |
42 | |
43 template<> | |
44 inline bool GetArg<double>(const base::ListValue* args, | |
45 size_t index, | |
46 double* out_value) { | |
47 return args->GetDouble(index, out_value); | |
48 } | |
49 | |
50 template<> | |
51 inline bool GetArg<std::string>(const base::ListValue* args, | |
52 size_t index, | |
53 std::string* out_value) { | |
54 return args->GetString(index, out_value); | |
55 } | |
56 | |
57 template<> | |
58 inline bool GetArg<string16>(const base::ListValue* args, | |
59 size_t index, | |
60 string16* out_value) { | |
61 return args->GetString(index, out_value); | |
62 } | |
63 | |
64 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.
| |
65 const base::ListValue* args) { | |
66 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.
| |
67 callback.Run(); | |
68 } | |
69 | |
70 template<typename A1> | |
71 void CallbackWrapper1(base::Callback<void(A1)> callback, | |
72 const base::ListValue* args) { | |
73 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.
| |
74 typename UnwrapConstRef<A1>::Type arg1; | |
75 if (!GetArg(args, 0, &arg1)) { | |
76 NOTREACHED(); | |
77 return; | |
78 } | |
79 callback.Run(arg1); | |
80 } | |
81 | |
82 template<typename A1, typename A2> | |
83 void CallbackWrapper2(base::Callback<void(A1, A2)> callback, | |
84 const base::ListValue* args) { | |
85 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.
| |
86 typename UnwrapConstRef<A1>::Type arg1; | |
87 typename UnwrapConstRef<A2>::Type arg2; | |
88 if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2)) { | |
89 NOTREACHED(); | |
90 return; | |
91 } | |
92 callback.Run(arg1, arg2); | |
93 } | |
94 | |
95 template<typename A1, typename A2, typename A3> | |
96 void CallbackWrapper3(base::Callback<void(A1, A2, A3)> callback, | |
97 const base::ListValue* args) { | |
98 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.
| |
99 typename UnwrapConstRef<A1>::Type arg1; | |
100 typename UnwrapConstRef<A2>::Type arg2; | |
101 typename UnwrapConstRef<A3>::Type arg3; | |
102 if (!GetArg(args, 0, &arg1) || | |
103 !GetArg(args, 1, &arg2) || | |
104 !GetArg(args, 2, &arg3)) { | |
105 NOTREACHED(); | |
106 return; | |
107 } | |
108 callback.Run(arg1, arg2, arg3); | |
109 } | |
110 | |
111 template<typename A1, typename A2, typename A3, typename A4> | |
112 void CallbackWrapper4(base::Callback<void(A1, A2, A3, A4)> callback, | |
113 const base::ListValue* args) { | |
114 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.
| |
115 typename UnwrapConstRef<A1>::Type arg1; | |
116 typename UnwrapConstRef<A2>::Type arg2; | |
117 typename UnwrapConstRef<A3>::Type arg3; | |
118 typename UnwrapConstRef<A4>::Type arg4; | |
119 if (!GetArg(args, 0, &arg1) || | |
120 !GetArg(args, 1, &arg2) || | |
121 !GetArg(args, 2, &arg3) || | |
122 !GetArg(args, 3, &arg4)) { | |
123 NOTREACHED(); | |
124 return; | |
125 } | |
126 callback.Run(arg1, arg2, arg3, arg4); | |
127 } | |
128 | |
129 } // namespace chromeos | |
130 | |
131 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ | |
OLD | NEW |