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. 4 5 #include "components/signin/core/common/profile_management_switches.h" 6 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" 11 12 namespace { 13 14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; 15 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. 19 enum State { 20 STATE_NONE, 21 STATE_NEW_PROFILE_MANAGEMENT, 22 STATE_ACCOUNT_CONSISTENCY 23 }; 24 GetProcessState()25State GetProcessState() { 26 // Get the full name of the field trial so that the underlying mechanism 27 // is properly initialized. 28 std::string trial_type = 29 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); 30 31 // Find the state of both command line args. 32 bool is_new_profile_management = 33 CommandLine::ForCurrentProcess()->HasSwitch( 34 switches::kEnableNewProfileManagement); 35 bool is_consistent_identity = 36 CommandLine::ForCurrentProcess()->HasSwitch( 37 switches::kEnableAccountConsistency); 38 bool not_new_profile_management = 39 CommandLine::ForCurrentProcess()->HasSwitch( 40 switches::kDisableNewProfileManagement); 41 bool not_consistent_identity = 42 CommandLine::ForCurrentProcess()->HasSwitch( 43 switches::kDisableAccountConsistency); 44 int count_args = (is_new_profile_management ? 1 : 0) + 45 (is_consistent_identity ? 1 : 0) + 46 (not_new_profile_management ? 1 : 0) + 47 (not_consistent_identity ? 1 : 0); 48 bool invalid_commandline = count_args > 1; 49 50 // At most only one of the command line args should be specified, otherwise 51 // the finch group assignment is undefined. If this is the case, disable 52 // the field trial so that data is not collected in the wrong group. 53 if (invalid_commandline) { 54 base::FieldTrial* field_trial = 55 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); 56 if (field_trial) 57 field_trial->Disable(); 58 59 trial_type.clear(); 60 } 61 62 // Enable command line args take precedent over disable command line args. 63 // Consistent identity args take precedent over new profile management args. 64 if (is_consistent_identity) { 65 return STATE_ACCOUNT_CONSISTENCY; 66 } else if (is_new_profile_management) { 67 return STATE_NEW_PROFILE_MANAGEMENT; 68 } else if (not_new_profile_management) { 69 return STATE_NONE; 70 } else if (not_consistent_identity) { 71 return STATE_NEW_PROFILE_MANAGEMENT; 72 } 73 74 #if defined(OS_ANDROID) 75 State state = STATE_ACCOUNT_CONSISTENCY; 76 #else 77 State state = STATE_NONE; 78 #endif 79 80 if (!trial_type.empty()) { 81 if (trial_type == "Enabled") { 82 state = STATE_NEW_PROFILE_MANAGEMENT; 83 } else if (trial_type == "AccountConsistency") { 84 state = STATE_ACCOUNT_CONSISTENCY; 85 } else { 86 state = STATE_NONE; 87 } 88 } 89 90 return state; 91 } 92 CheckFlag(std::string command_switch,State min_state)93bool CheckFlag(std::string command_switch, State min_state) { 94 // Individiual flag settings take precedence. 95 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) 96 return true; 97 98 return GetProcessState() >= min_state; 99 } 100 101 } // namespace 102 103 namespace switches { 104 IsEnableAccountConsistency()105bool IsEnableAccountConsistency() { 106 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY; 107 } 108 IsEnableWebBasedSignin()109bool IsEnableWebBasedSignin() { 110 return CommandLine::ForCurrentProcess()->HasSwitch( 111 switches::kEnableWebBasedSignin) && !IsNewProfileManagement(); 112 } 113 IsExtensionsMultiAccount()114bool IsExtensionsMultiAccount() { 115 return CheckFlag(switches::kExtensionsMultiAccount, 116 STATE_NEW_PROFILE_MANAGEMENT); 117 } 118 IsFastUserSwitching()119bool IsFastUserSwitching() { 120 bool use_mirror_promo_menu = 121 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && 122 !IsNewProfileManagement(); 123 return CommandLine::ForCurrentProcess()->HasSwitch( 124 switches::kFastUserSwitching) || use_mirror_promo_menu; 125 } 126 IsGoogleProfileInfo()127bool IsGoogleProfileInfo() { 128 return CheckFlag(switches::kGoogleProfileInfo, 129 STATE_NEW_PROFILE_MANAGEMENT); 130 } 131 IsNewAvatarMenu()132bool IsNewAvatarMenu() { 133 bool is_new_avatar_menu = 134 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); 135 return is_new_avatar_menu || IsNewProfileManagement(); 136 } 137 IsNewProfileManagement()138bool IsNewProfileManagement() { 139 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; 140 } 141 IsNewProfileManagementPreviewEnabled()142bool IsNewProfileManagementPreviewEnabled() { 143 bool is_new_avatar_menu = 144 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); 145 return is_new_avatar_menu && IsNewProfileManagement(); 146 } 147 EnableNewProfileManagementForTesting(base::CommandLine * command_line)148void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { 149 command_line->AppendSwitch(switches::kEnableNewProfileManagement); 150 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); 151 } 152 EnableAccountConsistencyForTesting(base::CommandLine * command_line)153void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { 154 command_line->AppendSwitch(switches::kEnableAccountConsistency); 155 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); 156 } 157 158 } // namespace switches 159