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

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

Issue 1454153002: Revert 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"
18 17
19 namespace login { 18 namespace login {
20 19
21 typedef std::vector<std::string> StringList; 20 typedef std::vector<std::string> StringList;
22 typedef std::vector<base::string16> String16List; 21 typedef std::vector<base::string16> String16List;
23 22
24 template <typename T> 23 template <typename T>
25 struct LOGIN_EXPORT UnwrapConstRef { 24 struct LOGIN_EXPORT UnwrapConstRef {
26 typedef T Type; 25 typedef T Type;
27 }; 26 };
28 27
29 template <typename T> 28 template <typename T>
30 struct UnwrapConstRef<const T&> { 29 struct UnwrapConstRef<const T&> {
31 typedef T Type; 30 typedef T Type;
32 }; 31 };
33 32
34 bool LOGIN_EXPORT ParseValue(const base::Value* value, bool* out_value); 33 bool LOGIN_EXPORT ParseValue(const base::Value* value, bool* out_value);
35 bool LOGIN_EXPORT ParseValue(const base::Value* value, int* out_value); 34 bool LOGIN_EXPORT ParseValue(const base::Value* value, int* out_value);
36 bool LOGIN_EXPORT ParseValue(const base::Value* value, double* out_value); 35 bool LOGIN_EXPORT ParseValue(const base::Value* value, double* out_value);
37 bool LOGIN_EXPORT ParseValue(const base::Value* value, std::string* out_value); 36 bool LOGIN_EXPORT ParseValue(const base::Value* value, std::string* out_value);
38 bool LOGIN_EXPORT 37 bool LOGIN_EXPORT
39 ParseValue(const base::Value* value, base::string16* out_value); 38 ParseValue(const base::Value* value, base::string16* out_value);
40 bool LOGIN_EXPORT ParseValue(const base::Value* value, 39 bool LOGIN_EXPORT ParseValue(const base::Value* value,
41 const base::DictionaryValue** out_value); 40 const base::DictionaryValue** out_value);
42 bool LOGIN_EXPORT ParseValue(const base::Value* value, StringList* out_value); 41 bool LOGIN_EXPORT ParseValue(const base::Value* value, StringList* out_value);
43 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value); 42 bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value);
44 bool LOGIN_EXPORT ParseValue(const base::Value* value, AccountId* out_value);
45 43
46 template <typename T> 44 template <typename T>
47 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) { 45 inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) {
48 const base::Value* value; 46 const base::Value* value;
49 if (!args->Get(index, &value)) 47 if (!args->Get(index, &value))
50 return false; 48 return false;
51 return ParseValue(value, out_value); 49 return ParseValue(value, out_value);
52 } 50 }
53 51
54 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v); 52 base::FundamentalValue LOGIN_EXPORT MakeValue(bool v);
55 base::FundamentalValue LOGIN_EXPORT MakeValue(int v); 53 base::FundamentalValue LOGIN_EXPORT MakeValue(int v);
56 base::FundamentalValue LOGIN_EXPORT MakeValue(double v); 54 base::FundamentalValue LOGIN_EXPORT MakeValue(double v);
57 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v); 55 base::StringValue LOGIN_EXPORT MakeValue(const std::string& v);
58 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v); 56 base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v);
59 base::StringValue LOGIN_EXPORT MakeValue(const AccountId& v);
60 57
61 template <typename T> 58 template <typename T>
62 inline const T& MakeValue(const T& v) { 59 inline const T& MakeValue(const T& v) {
63 return v; 60 return v;
64 } 61 }
65 62
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
77 template <typename Arg, size_t index> 63 template <typename Arg, size_t index>
78 typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) { 64 typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) {
79 ParsedValueContainer<typename UnwrapConstRef<Arg>::Type> parsed; 65 typename UnwrapConstRef<Arg>::Type parsed;
80 CHECK(GetArg(args, index, &parsed.value)); 66 CHECK(GetArg(args, index, &parsed));
81 return parsed.value; 67 return parsed;
82 } 68 }
83 69
84 template <typename... Args, size_t... Ns> 70 template <typename... Args, size_t... Ns>
85 inline void DispatchToCallback(const base::Callback<void(Args...)>& callback, 71 inline void DispatchToCallback(const base::Callback<void(Args...)>& callback,
86 const base::ListValue* args, 72 const base::ListValue* args,
87 base::IndexSequence<Ns...> indexes) { 73 base::IndexSequence<Ns...> indexes) {
88 DCHECK(args); 74 DCHECK(args);
89 DCHECK_EQ(sizeof...(Args), args->GetSize()); 75 DCHECK_EQ(sizeof...(Args), args->GetSize());
90 76
91 callback.Run(ParseArg<Args, Ns>(args)...); 77 callback.Run(ParseArg<Args, Ns>(args)...);
92 } 78 }
93 79
94 template <typename... Args> 80 template <typename... Args>
95 void CallbackWrapper(const base::Callback<void(Args...)>& callback, 81 void CallbackWrapper(const base::Callback<void(Args...)>& callback,
96 const base::ListValue* args) { 82 const base::ListValue* args) {
97 DispatchToCallback(callback, args, 83 DispatchToCallback(callback, args,
98 base::MakeIndexSequence<sizeof...(Args)>()); 84 base::MakeIndexSequence<sizeof...(Args)>());
99 } 85 }
100 86
101 87
102 } // namespace login 88 } // namespace login
103 89
104 #endif // COMPONENTS_LOGIN_BASE_SCREEN_HANDLER_UTILS_H_ 90 #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