OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/signin/core/common/profile_management_switches.h" | 5 #include "components/signin/core/common/profile_management_switches.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "components/signin/core/common/signin_switches.h" | 10 #include "components/signin/core/common/signin_switches.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; | 14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; |
15 | 15 |
16 // Different state of new profile management/identity consistency. The code | 16 // Different state of new profile management/identity consistency. The code |
17 // below assumes the order of the values in this enum. That is, new profile | 17 // below assumes the order of the values in this enum. That is, new profile |
18 // management is included in consistent identity. | 18 // management is included in consistent identity. |
19 enum State { | 19 enum State { |
20 STATE_OLD_AVATAR_MENU, | |
21 STATE_NEW_AVATAR_MENU, | 20 STATE_NEW_AVATAR_MENU, |
22 STATE_NEW_PROFILE_MANAGEMENT, | 21 STATE_NEW_PROFILE_MANAGEMENT, |
23 STATE_ACCOUNT_CONSISTENCY, | 22 STATE_ACCOUNT_CONSISTENCY, |
24 }; | 23 }; |
25 | 24 |
26 State GetProcessState() { | 25 State GetProcessState() { |
27 // Find the state of both command line args. | 26 // Find the state of both command line args. |
28 bool is_new_avatar_menu = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
29 switches::kEnableNewAvatarMenu); | |
30 bool is_new_profile_management = | 27 bool is_new_profile_management = |
31 base::CommandLine::ForCurrentProcess()->HasSwitch( | 28 base::CommandLine::ForCurrentProcess()->HasSwitch( |
32 switches::kEnableNewProfileManagement); | 29 switches::kEnableNewProfileManagement); |
33 bool is_consistent_identity = | 30 bool is_consistent_identity = |
34 base::CommandLine::ForCurrentProcess()->HasSwitch( | 31 base::CommandLine::ForCurrentProcess()->HasSwitch( |
35 switches::kEnableAccountConsistency); | 32 switches::kEnableAccountConsistency); |
36 bool not_new_avatar_menu = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
37 switches::kDisableNewAvatarMenu); | |
38 bool not_new_profile_management = | 33 bool not_new_profile_management = |
39 base::CommandLine::ForCurrentProcess()->HasSwitch( | 34 base::CommandLine::ForCurrentProcess()->HasSwitch( |
40 switches::kDisableNewProfileManagement); | 35 switches::kDisableNewProfileManagement); |
41 bool not_consistent_identity = | 36 bool not_consistent_identity = |
42 base::CommandLine::ForCurrentProcess()->HasSwitch( | 37 base::CommandLine::ForCurrentProcess()->HasSwitch( |
43 switches::kDisableAccountConsistency); | 38 switches::kDisableAccountConsistency); |
44 int count_args = (is_new_avatar_menu ? 1 : 0) + | 39 int count_args = (is_new_profile_management ? 1 : 0) + |
45 (is_new_profile_management ? 1 : 0) + | |
46 (is_consistent_identity ? 1 : 0) + | 40 (is_consistent_identity ? 1 : 0) + |
47 (not_new_avatar_menu ? 1 : 0) + | |
48 (not_new_profile_management ? 1 : 0) + | 41 (not_new_profile_management ? 1 : 0) + |
49 (not_consistent_identity ? 1 : 0); | 42 (not_consistent_identity ? 1 : 0); |
50 bool invalid_commandline = count_args > 1; | 43 bool invalid_commandline = count_args > 1; |
51 | 44 |
52 // At most only one of the command line args should be specified, otherwise | 45 // At most only one of the command line args should be specified, otherwise |
53 // the finch group assignment is undefined. If this is the case, disable | 46 // the finch group assignment is undefined. If this is the case, disable |
54 // the field trial so that data is not collected in the wrong group. | 47 // the field trial so that data is not collected in the wrong group. |
55 std::string trial_type; | 48 std::string trial_type; |
56 if (invalid_commandline) { | 49 if (invalid_commandline) { |
57 base::FieldTrial* field_trial = | 50 base::FieldTrial* field_trial = |
58 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); | 51 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); |
59 if (field_trial) | 52 if (field_trial) |
60 field_trial->Disable(); | 53 field_trial->Disable(); |
61 | 54 |
62 trial_type.clear(); | 55 trial_type.clear(); |
63 } else { | 56 } else { |
64 // Since the experiment is not being disabled, get the full name of the | 57 // Since the experiment is not being disabled, get the full name of the |
65 // field trial which will initialize the underlying mechanism. | 58 // field trial which will initialize the underlying mechanism. |
66 trial_type = | 59 trial_type = |
67 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | 60 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); |
68 } | 61 } |
69 | 62 |
70 // Forcing the old avatar menu takes precedent over other args. | |
71 // Enable command line args take precedent over disable command line args. | 63 // Enable command line args take precedent over disable command line args. |
72 // Consistent identity args take precedent over new profile management args. | 64 // Consistent identity args take precedent over new profile management args. |
73 if (not_new_avatar_menu) { | 65 if (is_consistent_identity) { |
74 return STATE_OLD_AVATAR_MENU; | |
75 } else if (is_consistent_identity) { | |
76 return STATE_ACCOUNT_CONSISTENCY; | 66 return STATE_ACCOUNT_CONSISTENCY; |
77 } else if (is_new_profile_management) { | 67 } else if (is_new_profile_management) { |
78 return STATE_NEW_PROFILE_MANAGEMENT; | 68 return STATE_NEW_PROFILE_MANAGEMENT; |
79 } else if (is_new_avatar_menu) { | |
80 return STATE_NEW_AVATAR_MENU; | |
81 } else if (not_new_profile_management) { | 69 } else if (not_new_profile_management) { |
82 return STATE_NEW_AVATAR_MENU; | 70 return STATE_NEW_AVATAR_MENU; |
83 } else if (not_consistent_identity) { | 71 } else if (not_consistent_identity) { |
84 return STATE_NEW_PROFILE_MANAGEMENT; | 72 return STATE_NEW_PROFILE_MANAGEMENT; |
85 } | 73 } |
86 | 74 |
87 // Set the default state | 75 // Set the default state |
88 #if defined(OS_ANDROID) || defined(OS_IOS) | 76 #if defined(OS_ANDROID) || defined(OS_IOS) |
89 State state = STATE_ACCOUNT_CONSISTENCY; | 77 State state = STATE_ACCOUNT_CONSISTENCY; |
90 #else | 78 #else |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 122 |
135 bool IsExtensionsMultiAccount() { | 123 bool IsExtensionsMultiAccount() { |
136 return CheckFlag(switches::kExtensionsMultiAccount, | 124 return CheckFlag(switches::kExtensionsMultiAccount, |
137 STATE_ACCOUNT_CONSISTENCY); | 125 STATE_ACCOUNT_CONSISTENCY); |
138 } | 126 } |
139 | 127 |
140 bool IsGoogleProfileInfo() { | 128 bool IsGoogleProfileInfo() { |
141 return CheckFlag(switches::kGoogleProfileInfo, STATE_NEW_AVATAR_MENU); | 129 return CheckFlag(switches::kGoogleProfileInfo, STATE_NEW_AVATAR_MENU); |
142 } | 130 } |
143 | 131 |
144 bool IsNewAvatarMenu() { | |
145 // NewAvatarMenu is only available on desktop. | |
146 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS) | |
147 return false; | |
148 #else | |
149 return GetProcessState() >= STATE_NEW_AVATAR_MENU; | |
150 #endif | |
151 } | |
152 | |
153 bool IsNewProfileManagement() { | 132 bool IsNewProfileManagement() { |
154 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; | 133 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
155 } | 134 } |
156 | 135 |
157 bool IsNewProfileManagementPreviewEnabled() { | 136 bool IsNewProfileManagementPreviewEnabled() { |
158 // No promotion to Enable Account Consistency. | 137 // No promotion to Enable Account Consistency. |
159 return false; | 138 return false; |
160 } | 139 } |
161 | 140 |
162 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { | |
163 command_line->AppendSwitch(switches::kEnableNewAvatarMenu); | |
164 DCHECK(!command_line->HasSwitch(switches::kDisableNewAvatarMenu)); | |
165 } | |
166 | |
167 void DisableNewAvatarMenuForTesting(base::CommandLine* command_line) { | |
168 command_line->AppendSwitch(switches::kDisableNewAvatarMenu); | |
169 DCHECK(!command_line->HasSwitch(switches::kEnableNewAvatarMenu)); | |
170 } | |
171 | |
172 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { | 141 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { |
173 command_line->AppendSwitch(switches::kEnableNewProfileManagement); | 142 command_line->AppendSwitch(switches::kEnableNewProfileManagement); |
174 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); | 143 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); |
175 } | 144 } |
176 | 145 |
177 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { | 146 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { |
178 command_line->AppendSwitch(switches::kEnableAccountConsistency); | 147 command_line->AppendSwitch(switches::kEnableAccountConsistency); |
179 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); | 148 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); |
180 } | 149 } |
181 | 150 |
182 } // namespace switches | 151 } // namespace switches |
OLD | NEW |