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 // 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
=
31 base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kEnableNewProfileManagement
);
33 bool is_consistent_identity
=
34 base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kEnableAccountConsistency
);
36 bool not_new_avatar_menu
= base::CommandLine::ForCurrentProcess()->HasSwitch(
37 switches::kDisableNewAvatarMenu
);
38 bool not_new_profile_management
=
39 base::CommandLine::ForCurrentProcess()->HasSwitch(
40 switches::kDisableNewProfileManagement
);
41 bool not_consistent_identity
=
42 base::CommandLine::ForCurrentProcess()->HasSwitch(
43 switches::kDisableAccountConsistency
);
44 int count_args
= (is_new_avatar_menu
? 1 : 0) +
45 (is_new_profile_management
? 1 : 0) +
46 (is_consistent_identity
? 1 : 0) +
47 (not_new_avatar_menu
? 1 : 0) +
48 (not_new_profile_management
? 1 : 0) +
49 (not_consistent_identity
? 1 : 0);
50 bool invalid_commandline
= count_args
> 1;
52 // 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
54 // the field trial so that data is not collected in the wrong group.
55 std::string trial_type
;
56 if (invalid_commandline
) {
57 base::FieldTrial
* field_trial
=
58 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName
);
60 field_trial
->Disable();
64 // Since the experiment is not being disabled, get the full name of the
65 // field trial which will initialize the underlying mechanism.
67 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName
);
70 // Forcing the old avatar menu takes precedent over other args.
71 // Enable command line args take precedent over disable command line args.
72 // Consistent identity args take precedent over new profile management args.
73 if (not_new_avatar_menu
) {
74 return STATE_OLD_AVATAR_MENU
;
75 } else if (is_consistent_identity
) {
76 return STATE_ACCOUNT_CONSISTENCY
;
77 } else if (is_new_profile_management
) {
78 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
) {
82 return STATE_OLD_AVATAR_MENU
;
83 } else if (not_consistent_identity
) {
84 return STATE_OLD_AVATAR_MENU
;
87 // Set the default state
88 #if defined(OS_ANDROID) || defined(OS_IOS)
89 State state
= STATE_ACCOUNT_CONSISTENCY
;
91 State state
= STATE_OLD_AVATAR_MENU
;
94 if (!trial_type
.empty()) {
95 if (trial_type
== "Enabled") {
96 state
= STATE_NEW_PROFILE_MANAGEMENT
;
97 } else if (trial_type
== "AccountConsistency") {
98 state
= STATE_ACCOUNT_CONSISTENCY
;
99 } else if (trial_type
== "NewAvatarMenu") {
100 state
= STATE_NEW_AVATAR_MENU
;
102 state
= STATE_OLD_AVATAR_MENU
;
109 bool CheckFlag(std::string command_switch
, State min_state
) {
110 // Individiual flag settings take precedence.
111 if (base::CommandLine::ForCurrentProcess()->HasSwitch(command_switch
))
114 return GetProcessState() >= min_state
;
121 bool IsEnableAccountConsistency() {
122 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY
;
125 bool IsEnableWebviewBasedSignin() {
126 // For now, the webview is enabled only for desktop.
127 #if defined(OS_CHROMEOS)
130 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
131 switches::kEnableIframeBasedSignin
);
135 bool IsExtensionsMultiAccount() {
136 return CheckFlag(switches::kExtensionsMultiAccount
,
137 STATE_NEW_PROFILE_MANAGEMENT
);
140 bool IsFastUserSwitching() {
141 return base::CommandLine::ForCurrentProcess()->HasSwitch(
142 switches::kFastUserSwitching
);
145 bool IsGoogleProfileInfo() {
146 return CheckFlag(switches::kGoogleProfileInfo
, STATE_NEW_AVATAR_MENU
);
149 bool IsNewAvatarMenu() {
150 // NewAvatarMenu is only available on desktop.
151 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
154 return GetProcessState() >= STATE_NEW_AVATAR_MENU
;
158 bool IsNewProfileManagement() {
159 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT
;
162 bool IsNewProfileManagementPreviewEnabled() {
163 // No promotion to Enable Account Consistency.
167 void EnableNewAvatarMenuForTesting(base::CommandLine
* command_line
) {
168 command_line
->AppendSwitch(switches::kEnableNewAvatarMenu
);
169 DCHECK(!command_line
->HasSwitch(switches::kDisableNewAvatarMenu
));
172 void DisableNewAvatarMenuForTesting(base::CommandLine
* command_line
) {
173 command_line
->AppendSwitch(switches::kDisableNewAvatarMenu
);
174 DCHECK(!command_line
->HasSwitch(switches::kEnableNewAvatarMenu
));
177 void EnableNewProfileManagementForTesting(base::CommandLine
* command_line
) {
178 command_line
->AppendSwitch(switches::kEnableNewProfileManagement
);
179 DCHECK(!command_line
->HasSwitch(switches::kDisableNewProfileManagement
));
182 void EnableAccountConsistencyForTesting(base::CommandLine
* command_line
) {
183 command_line
->AppendSwitch(switches::kEnableAccountConsistency
);
184 DCHECK(!command_line
->HasSwitch(switches::kDisableAccountConsistency
));
187 } // namespace switches