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
3 // found in the LICENSE file.
5 #include "components/signin/core/common/profile_management_switches.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "build/build_config.h"
10 #include "components/signin/core/common/signin_switches.h"
14 const char kNewProfileManagementFieldTrialName
[] = "NewProfileManagement";
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
18 // management is included in consistent identity.
20 STATE_OLD_AVATAR_MENU
,
21 STATE_NEW_AVATAR_MENU
,
22 STATE_NEW_PROFILE_MANAGEMENT
,
23 STATE_ACCOUNT_CONSISTENCY
,
26 State
GetProcessState() {
27 // Disables the new avatar menu if the web-based signin is turned on, because
28 // the new avatar menu always uses the inline signin, which may break some
30 if (switches::IsEnableWebBasedSignin())
31 return STATE_OLD_AVATAR_MENU
;
33 // Find the state of both command line args.
34 bool is_new_avatar_menu
=
35 CommandLine::ForCurrentProcess()->HasSwitch(
36 switches::kEnableNewAvatarMenu
);
37 bool is_new_profile_management
=
38 CommandLine::ForCurrentProcess()->HasSwitch(
39 switches::kEnableNewProfileManagement
);
40 bool is_consistent_identity
=
41 CommandLine::ForCurrentProcess()->HasSwitch(
42 switches::kEnableAccountConsistency
);
43 bool not_new_avatar_menu
=
44 CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kDisableNewAvatarMenu
);
46 bool not_new_profile_management
=
47 CommandLine::ForCurrentProcess()->HasSwitch(
48 switches::kDisableNewProfileManagement
);
49 bool not_consistent_identity
=
50 CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kDisableAccountConsistency
);
52 int count_args
= (is_new_avatar_menu
? 1 : 0) +
53 (is_new_profile_management
? 1 : 0) +
54 (is_consistent_identity
? 1 : 0) +
55 (not_new_avatar_menu
? 1 : 0) +
56 (not_new_profile_management
? 1 : 0) +
57 (not_consistent_identity
? 1 : 0);
58 bool invalid_commandline
= count_args
> 1;
60 // At most only one of the command line args should be specified, otherwise
61 // the finch group assignment is undefined. If this is the case, disable
62 // the field trial so that data is not collected in the wrong group.
63 std::string trial_type
;
64 if (invalid_commandline
) {
65 base::FieldTrial
* field_trial
=
66 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName
);
68 field_trial
->Disable();
72 // Since the experiment is not being disabled, get the full name of the
73 // field trial which will initialize the underlying mechanism.
75 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName
);
78 // Forcing the old avatar menu takes precedent over other args.
79 // Enable command line args take precedent over disable command line args.
80 // Consistent identity args take precedent over new profile management args.
81 if (not_new_avatar_menu
) {
82 return STATE_OLD_AVATAR_MENU
;
83 } else if (is_consistent_identity
) {
84 return STATE_ACCOUNT_CONSISTENCY
;
85 } else if (is_new_profile_management
) {
86 return STATE_NEW_PROFILE_MANAGEMENT
;
87 } else if (is_new_avatar_menu
) {
88 return STATE_NEW_AVATAR_MENU
;
89 } else if (not_new_profile_management
) {
90 return STATE_OLD_AVATAR_MENU
;
91 } else if (not_consistent_identity
) {
92 return STATE_OLD_AVATAR_MENU
;
95 // Set the default state
96 #if defined(OS_ANDROID)
97 State state
= STATE_ACCOUNT_CONSISTENCY
;
99 State state
= STATE_OLD_AVATAR_MENU
;
102 if (!trial_type
.empty()) {
103 if (trial_type
== "Enabled") {
104 state
= STATE_NEW_PROFILE_MANAGEMENT
;
105 } else if (trial_type
== "AccountConsistency") {
106 state
= STATE_ACCOUNT_CONSISTENCY
;
107 } else if (trial_type
== "NewAvatarMenu") {
108 state
= STATE_NEW_AVATAR_MENU
;
110 state
= STATE_OLD_AVATAR_MENU
;
117 bool CheckFlag(std::string command_switch
, State min_state
) {
118 // Individiual flag settings take precedence.
119 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch
))
122 return GetProcessState() >= min_state
;
129 bool IsEnableAccountConsistency() {
130 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY
;
133 bool IsEnableWebBasedSignin() {
134 return CommandLine::ForCurrentProcess()->HasSwitch(
135 switches::kEnableWebBasedSignin
) && !IsEnableWebviewBasedSignin();
138 bool IsEnableWebviewBasedSignin() {
139 return CommandLine::ForCurrentProcess()->HasSwitch(
140 switches::kEnableWebviewBasedSignin
);
143 bool IsExtensionsMultiAccount() {
144 return CheckFlag(switches::kExtensionsMultiAccount
,
145 STATE_NEW_PROFILE_MANAGEMENT
);
148 bool IsFastUserSwitching() {
149 return CommandLine::ForCurrentProcess()->HasSwitch(
150 switches::kFastUserSwitching
);
153 bool IsGoogleProfileInfo() {
154 return CheckFlag(switches::kGoogleProfileInfo
, STATE_NEW_AVATAR_MENU
);
157 bool IsNewAvatarMenu() {
158 // NewAvatarMenu is only available on desktop.
159 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
162 return GetProcessState() >= STATE_NEW_AVATAR_MENU
;
166 bool IsNewProfileManagement() {
167 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT
;
170 bool IsNewProfileManagementPreviewEnabled() {
171 // No promotion to Enable Account Consistency.
175 void EnableNewAvatarMenuForTesting(base::CommandLine
* command_line
) {
176 command_line
->AppendSwitch(switches::kEnableNewAvatarMenu
);
177 DCHECK(!command_line
->HasSwitch(switches::kDisableNewAvatarMenu
));
180 void DisableNewAvatarMenuForTesting(base::CommandLine
* command_line
) {
181 command_line
->AppendSwitch(switches::kDisableNewAvatarMenu
);
182 DCHECK(!command_line
->HasSwitch(switches::kEnableNewAvatarMenu
));
185 void EnableNewProfileManagementForTesting(base::CommandLine
* command_line
) {
186 command_line
->AppendSwitch(switches::kEnableNewProfileManagement
);
187 DCHECK(!command_line
->HasSwitch(switches::kDisableNewProfileManagement
));
190 void EnableAccountConsistencyForTesting(base::CommandLine
* command_line
) {
191 command_line
->AppendSwitch(switches::kEnableAccountConsistency
);
192 DCHECK(!command_line
->HasSwitch(switches::kDisableAccountConsistency
));
195 } // namespace switches