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