OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_UTILS_H_ | 5 #ifndef COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ | 6 #define COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "components/login/login_export.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace login { |
17 | 18 |
18 typedef std::vector<std::string> StringList; | 19 typedef std::vector<std::string> StringList; |
19 typedef std::vector<base::string16> String16List; | 20 typedef std::vector<base::string16> String16List; |
20 | 21 |
21 template<typename T> | 22 template <typename T> |
22 struct UnwrapConstRef { | 23 struct LOGIN_EXPORT UnwrapConstRef { |
23 typedef T Type; | 24 typedef T Type; |
24 }; | 25 }; |
25 | 26 |
26 template<typename T> | 27 template <typename T> |
27 struct UnwrapConstRef<const T&> { | 28 struct LOGIN_EXPORT UnwrapConstRef<const T&> { |
28 typedef T Type; | 29 typedef T Type; |
29 }; | 30 }; |
30 | 31 |
31 bool ParseValue(const base::Value* value, bool* out_value); | 32 bool LOGIN_EXPORT ParseValue(const base::Value* value, bool* out_value); |
32 bool ParseValue(const base::Value* value, int* out_value); | 33 bool LOGIN_EXPORT ParseValue(const base::Value* value, int* out_value); |
33 bool ParseValue(const base::Value* value, double* out_value); | 34 bool LOGIN_EXPORT ParseValue(const base::Value* value, double* out_value); |
34 bool ParseValue(const base::Value* value, std::string* out_value); | 35 bool LOGIN_EXPORT ParseValue(const base::Value* value, std::string* out_value); |
35 bool ParseValue(const base::Value* value, base::string16* out_value); | 36 bool LOGIN_EXPORT |
36 bool ParseValue(const base::Value* value, | 37 ParseValue(const base::Value* value, base::string16* out_value); |
37 const base::DictionaryValue** out_value); | 38 bool LOGIN_EXPORT ParseValue(const base::Value* value, |
38 bool ParseValue(const base::Value* value, StringList* out_value); | 39 const base::DictionaryValue** out_value); |
39 bool ParseValue(const base::Value* value, String16List* out_value); | 40 bool LOGIN_EXPORT ParseValue(const base::Value* value, StringList* out_value); |
| 41 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value); |
40 | 42 |
41 template<typename T> | 43 template <typename T> |
42 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) { | 44 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) { |
43 const base::Value* value; | 45 const base::Value* value; |
44 if (!args->Get(index, &value)) | 46 if (!args->Get(index, &value)) |
45 return false; | 47 return false; |
46 return ParseValue(value, out_value); | 48 return ParseValue(value, out_value); |
47 } | 49 } |
48 | 50 |
49 base::FundamentalValue MakeValue(bool v); | 51 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v); |
50 base::FundamentalValue MakeValue(int v); | 52 base::FundamentalValue LOGIN_EXPORT MakeValue(int v); |
51 base::FundamentalValue MakeValue(double v); | 53 base::FundamentalValue LOGIN_EXPORT MakeValue(double v); |
52 base::StringValue MakeValue(const std::string& v); | 54 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v); |
53 base::StringValue MakeValue(const base::string16& v); | 55 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v); |
54 | 56 |
55 template<typename T> | 57 template <typename T> |
56 inline const T& MakeValue(const T& v) { | 58 inline const T& MakeValue(const T& v) { |
57 return v; | 59 return v; |
58 } | 60 } |
59 | 61 |
60 void CallbackWrapper0(base::Callback<void()> callback, | 62 void LOGIN_EXPORT CallbackWrapper0(base::Callback<void()> callback, |
61 const base::ListValue* args); | 63 const base::ListValue* args); |
62 | 64 |
63 template<typename A1> | 65 template <typename A1> |
64 void CallbackWrapper1(base::Callback<void(A1)> callback, | 66 void CallbackWrapper1(base::Callback<void(A1)> callback, |
65 const base::ListValue* args) { | 67 const base::ListValue* args) { |
66 DCHECK(args); | 68 DCHECK(args); |
67 DCHECK_EQ(1u, args->GetSize()); | 69 DCHECK_EQ(1u, args->GetSize()); |
68 typename UnwrapConstRef<A1>::Type arg1; | 70 typename UnwrapConstRef<A1>::Type arg1; |
69 if (!GetArg(args, 0, &arg1)) { | 71 if (!GetArg(args, 0, &arg1)) { |
70 NOTREACHED(); | 72 NOTREACHED(); |
71 return; | 73 return; |
72 } | 74 } |
73 callback.Run(arg1); | 75 callback.Run(arg1); |
74 } | 76 } |
75 | 77 |
76 template<typename A1, typename A2> | 78 template <typename A1, typename A2> |
77 void CallbackWrapper2(base::Callback<void(A1, A2)> callback, | 79 void CallbackWrapper2(base::Callback<void(A1, A2)> callback, |
78 const base::ListValue* args) { | 80 const base::ListValue* args) { |
79 DCHECK(args); | 81 DCHECK(args); |
80 DCHECK_EQ(2u, args->GetSize()); | 82 DCHECK_EQ(2u, args->GetSize()); |
81 typename UnwrapConstRef<A1>::Type arg1; | 83 typename UnwrapConstRef<A1>::Type arg1; |
82 typename UnwrapConstRef<A2>::Type arg2; | 84 typename UnwrapConstRef<A2>::Type arg2; |
83 if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2)) { | 85 if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2)) { |
84 NOTREACHED(); | 86 NOTREACHED(); |
85 return; | 87 return; |
86 } | 88 } |
87 callback.Run(arg1, arg2); | 89 callback.Run(arg1, arg2); |
88 } | 90 } |
89 | 91 |
90 template<typename A1, typename A2, typename A3> | 92 template <typename A1, typename A2, typename A3> |
91 void CallbackWrapper3(base::Callback<void(A1, A2, A3)> callback, | 93 void CallbackWrapper3(base::Callback<void(A1, A2, A3)> callback, |
92 const base::ListValue* args) { | 94 const base::ListValue* args) { |
93 DCHECK(args); | 95 DCHECK(args); |
94 DCHECK_EQ(3u, args->GetSize()); | 96 DCHECK_EQ(3u, args->GetSize()); |
95 typename UnwrapConstRef<A1>::Type arg1; | 97 typename UnwrapConstRef<A1>::Type arg1; |
96 typename UnwrapConstRef<A2>::Type arg2; | 98 typename UnwrapConstRef<A2>::Type arg2; |
97 typename UnwrapConstRef<A3>::Type arg3; | 99 typename UnwrapConstRef<A3>::Type arg3; |
98 if (!GetArg(args, 0, &arg1) || | 100 if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2) || |
99 !GetArg(args, 1, &arg2) || | |
100 !GetArg(args, 2, &arg3)) { | 101 !GetArg(args, 2, &arg3)) { |
101 NOTREACHED(); | 102 NOTREACHED(); |
102 return; | 103 return; |
103 } | 104 } |
104 callback.Run(arg1, arg2, arg3); | 105 callback.Run(arg1, arg2, arg3); |
105 } | 106 } |
106 | 107 |
107 template<typename A1, typename A2, typename A3, typename A4> | 108 template <typename A1, typename A2, typename A3, typename A4> |
108 void CallbackWrapper4(base::Callback<void(A1, A2, A3, A4)> callback, | 109 void CallbackWrapper4(base::Callback<void(A1, A2, A3, A4)> callback, |
109 const base::ListValue* args) { | 110 const base::ListValue* args) { |
110 DCHECK(args); | 111 DCHECK(args); |
111 DCHECK_EQ(4u, args->GetSize()); | 112 DCHECK_EQ(4u, args->GetSize()); |
112 typename UnwrapConstRef<A1>::Type arg1; | 113 typename UnwrapConstRef<A1>::Type arg1; |
113 typename UnwrapConstRef<A2>::Type arg2; | 114 typename UnwrapConstRef<A2>::Type arg2; |
114 typename UnwrapConstRef<A3>::Type arg3; | 115 typename UnwrapConstRef<A3>::Type arg3; |
115 typename UnwrapConstRef<A4>::Type arg4; | 116 typename UnwrapConstRef<A4>::Type arg4; |
116 if (!GetArg(args, 0, &arg1) || | 117 if (!GetArg(args, 0, &arg1) || !GetArg(args, 1, &arg2) || |
117 !GetArg(args, 1, &arg2) || | 118 !GetArg(args, 2, &arg3) || !GetArg(args, 3, &arg4)) { |
118 !GetArg(args, 2, &arg3) || | |
119 !GetArg(args, 3, &arg4)) { | |
120 NOTREACHED(); | 119 NOTREACHED(); |
121 return; | 120 return; |
122 } | 121 } |
123 callback.Run(arg1, arg2, arg3, arg4); | 122 callback.Run(arg1, arg2, arg3, arg4); |
124 } | 123 } |
125 | 124 |
126 } // namespace chromeos | 125 } // namespace login |
127 | 126 |
128 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ | 127 #endif // COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ |
OLD | NEW |