Disable failing PartnerDisableIncognitoModeIntegrationTest#testEnabledParentalControl...
[chromium-blink-merge.git] / components / login / base_screen_handler_utils.h
blob71d2e7f1687ff6417d0dd839878532f017694c7a
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.
5 #ifndef COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
6 #define COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
8 #include <cstddef>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14 #include "base/tuple.h"
15 #include "base/values.h"
16 #include "components/login/login_export.h"
18 namespace login {
20 typedef std::vector<std::string> StringList;
21 typedef std::vector<base::string16> String16List;
23 template <typename T>
24 struct LOGIN_EXPORT UnwrapConstRef {
25 typedef T Type;
28 template <typename T>
29 struct UnwrapConstRef<const T&> {
30 typedef T Type;
33 bool LOGIN_EXPORT ParseValue(const base::Value* value, bool* out_value);
34 bool LOGIN_EXPORT ParseValue(const base::Value* value, int* out_value);
35 bool LOGIN_EXPORT ParseValue(const base::Value* value, double* out_value);
36 bool LOGIN_EXPORT ParseValue(const base::Value* value, std::string* out_value);
37 bool LOGIN_EXPORT
38 ParseValue(const base::Value* value, base::string16* out_value);
39 bool LOGIN_EXPORT ParseValue(const base::Value* value,
40 const base::DictionaryValue** out_value);
41 bool LOGIN_EXPORT ParseValue(const base::Value* value, StringList* out_value);
42 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value);
44 template <typename T>
45 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) {
46 const base::Value* value;
47 if (!args->Get(index, &value))
48 return false;
49 return ParseValue(value, out_value);
52 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v);
53 base::FundamentalValue LOGIN_EXPORT MakeValue(int v);
54 base::FundamentalValue LOGIN_EXPORT MakeValue(double v);
55 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v);
56 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v);
58 template <typename T>
59 inline const T& MakeValue(const T& v) {
60 return v;
63 template <typename Arg, size_t index>
64 typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) {
65 typename UnwrapConstRef<Arg>::Type parsed;
66 CHECK(GetArg(args, index, &parsed));
67 return parsed;
70 template <typename... Args, size_t... Ns>
71 inline void DispatchToCallback(const base::Callback<void(Args...)>& callback,
72 const base::ListValue* args,
73 base::IndexSequence<Ns...> indexes) {
74 DCHECK(args);
75 DCHECK_EQ(sizeof...(Args), args->GetSize());
77 callback.Run(ParseArg<Args, Ns>(args)...);
80 template <typename... Args>
81 void CallbackWrapper(const base::Callback<void(Args...)>& callback,
82 const base::ListValue* args) {
83 DispatchToCallback(callback, args,
84 base::MakeIndexSequence<sizeof...(Args)>());
88 } // namespace login
90 #endif // COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_