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

Side by Side Diff: components/login/base_screen_handler_utils.h

Issue 1455263002: Reland of This CL replaces e-mail with AccountId on user selection screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « components/login/DEPS ('k') | components/login/base_screen_handler_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ 5 #ifndef COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
6 #define COMPONENTS_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/tuple.h" 14 #include "base/tuple.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/login/login_export.h" 16 #include "components/login/login_export.h"
17 #include "components/signin/core/account_id/account_id.h"
17 18
18 namespace login { 19 namespace login {
19 20
20 typedef std::vector<std::string> StringList; 21 typedef std::vector<std::string> StringList;
21 typedef std::vector<base::string16> String16List; 22 typedef std::vector<base::string16> String16List;
22 23
23 template <typename T> 24 template <typename T>
24 struct LOGIN_EXPORT UnwrapConstRef { 25 struct LOGIN_EXPORT UnwrapConstRef {
25 typedef T Type; 26 typedef T Type;
26 }; 27 };
27 28
28 template <typename T> 29 template <typename T>
29 struct UnwrapConstRef<const T&> { 30 struct UnwrapConstRef<const T&> {
30 typedef T Type; 31 typedef T Type;
31 }; 32 };
32 33
33 bool LOGIN_EXPORT ParseValue(const base::Value* value, bool* out_value); 34 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, int* out_value);
35 bool LOGIN_EXPORT ParseValue(const base::Value* value, double* out_value); 36 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 ParseValue(const base::Value* value, std::string* out_value);
37 bool LOGIN_EXPORT 38 bool LOGIN_EXPORT
38 ParseValue(const base::Value* value, base::string16* out_value); 39 ParseValue(const base::Value* value, base::string16* out_value);
39 bool LOGIN_EXPORT ParseValue(const base::Value* value, 40 bool LOGIN_EXPORT ParseValue(const base::Value* value,
40 const base::DictionaryValue** out_value); 41 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, StringList* out_value);
42 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value); 43 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value);
44 bool LOGIN_EXPORT ParseValue(const base::Value* value, AccountId* out_value);
43 45
44 template <typename T> 46 template <typename T>
45 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) { 47 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) {
46 const base::Value* value; 48 const base::Value* value;
47 if (!args->Get(index, &value)) 49 if (!args->Get(index, &value))
48 return false; 50 return false;
49 return ParseValue(value, out_value); 51 return ParseValue(value, out_value);
50 } 52 }
51 53
52 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v); 54 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v);
53 base::FundamentalValue LOGIN_EXPORT MakeValue(int v); 55 base::FundamentalValue LOGIN_EXPORT MakeValue(int v);
54 base::FundamentalValue LOGIN_EXPORT MakeValue(double v); 56 base::FundamentalValue LOGIN_EXPORT MakeValue(double v);
55 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v); 57 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v);
56 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v); 58 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v);
59 base::StringValue LOGIN_EXPORT MakeValue(const AccountId& v);
57 60
58 template <typename T> 61 template <typename T>
59 inline const T& MakeValue(const T& v) { 62 inline const T& MakeValue(const T& v) {
60 return v; 63 return v;
61 } 64 }
62 65
66 template <typename T>
67 struct ParsedValueContainer {
68 T value;
69 };
70
71 template <>
72 struct LOGIN_EXPORT ParsedValueContainer<AccountId> {
73 ParsedValueContainer();
74 AccountId value = EmptyAccountId();
75 };
76
63 template <typename Arg, size_t index> 77 template <typename Arg, size_t index>
64 typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) { 78 typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) {
65 typename UnwrapConstRef<Arg>::Type parsed; 79 ParsedValueContainer<typename UnwrapConstRef<Arg>::Type> parsed;
66 CHECK(GetArg(args, index, &parsed)); 80 CHECK(GetArg(args, index, &parsed.value));
67 return parsed; 81 return parsed.value;
68 } 82 }
69 83
70 template <typename... Args, size_t... Ns> 84 template <typename... Args, size_t... Ns>
71 inline void DispatchToCallback(const base::Callback<void(Args...)>& callback, 85 inline void DispatchToCallback(const base::Callback<void(Args...)>& callback,
72 const base::ListValue* args, 86 const base::ListValue* args,
73 base::IndexSequence<Ns...> indexes) { 87 base::IndexSequence<Ns...> indexes) {
74 DCHECK(args); 88 DCHECK(args);
75 DCHECK_EQ(sizeof...(Args), args->GetSize()); 89 DCHECK_EQ(sizeof...(Args), args->GetSize());
76 90
77 callback.Run(ParseArg<Args, Ns>(args)...); 91 callback.Run(ParseArg<Args, Ns>(args)...);
78 } 92 }
79 93
80 template <typename... Args> 94 template <typename... Args>
81 void CallbackWrapper(const base::Callback<void(Args...)>& callback, 95 void CallbackWrapper(const base::Callback<void(Args...)>& callback,
82 const base::ListValue* args) { 96 const base::ListValue* args) {
83 DispatchToCallback(callback, args, 97 DispatchToCallback(callback, args,
84 base::MakeIndexSequence<sizeof...(Args)>()); 98 base::MakeIndexSequence<sizeof...(Args)>());
85 } 99 }
86 100
87 101
88 } // namespace login 102 } // namespace login
89 103
90 #endif // COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ 104 #endif // COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_
OLDNEW
« no previous file with comments | « components/login/DEPS ('k') | components/login/base_screen_handler_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698