profile_management_switches.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
10529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 50529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/signin/core/common/profile_management_switches.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/command_line.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/field_trial.h" 9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "build/build_config.h" 100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/signin/core/common/signin_switches.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Different state of new profile management/identity consistency. The code 17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// below assumes the order of the values in this enum. That is, new profile 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// management is included in consistent identity. 19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)enum State { 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) STATE_OLD_AVATAR_MENU, 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) STATE_NEW_AVATAR_MENU, 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) STATE_NEW_PROFILE_MANAGEMENT, 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) STATE_ACCOUNT_CONSISTENCY, 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}; 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)State GetProcessState() { 27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Find the state of both command line args. 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool is_new_avatar_menu = 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::kEnableNewAvatarMenu); 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool is_new_profile_management = 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 33f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) switches::kEnableNewProfileManagement); 34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool is_consistent_identity = 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) switches::kEnableAccountConsistency); 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool not_new_avatar_menu = 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::kDisableNewAvatarMenu); 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) bool not_new_profile_management = 41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) switches::kDisableNewProfileManagement); 43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) bool not_consistent_identity = 44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) CommandLine::ForCurrentProcess()->HasSwitch( 45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) switches::kDisableAccountConsistency); 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int count_args = (is_new_avatar_menu ? 1 : 0) + 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) (is_new_profile_management ? 1 : 0) + 48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) (is_consistent_identity ? 1 : 0) + 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) (not_new_avatar_menu ? 1 : 0) + 50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) (not_new_profile_management ? 1 : 0) + 51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) (not_consistent_identity ? 1 : 0); 52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) bool invalid_commandline = count_args > 1; 53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 54f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // At most only one of the command line args should be specified, otherwise 55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // the finch group assignment is undefined. If this is the case, disable 56f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // the field trial so that data is not collected in the wrong group. 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string trial_type; 58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (invalid_commandline) { 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FieldTrial* field_trial = 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (field_trial) 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) field_trial->Disable(); 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 64f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) trial_type.clear(); 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else { 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Since the experiment is not being disabled, get the full name of the 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // field trial which will initialize the underlying mechanism. 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) trial_type = 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); 70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 71f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Forcing the old avatar menu takes precedent over other args. 73f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Enable command line args take precedent over disable command line args. 74f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Consistent identity args take precedent over new profile management args. 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (not_new_avatar_menu) { 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return STATE_OLD_AVATAR_MENU; 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (is_consistent_identity) { 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return STATE_ACCOUNT_CONSISTENCY; 79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } else if (is_new_profile_management) { 80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return STATE_NEW_PROFILE_MANAGEMENT; 815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (is_new_avatar_menu) { 825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return STATE_NEW_AVATAR_MENU; 83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } else if (not_new_profile_management) { 846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return STATE_OLD_AVATAR_MENU; 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } else if (not_consistent_identity) { 866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return STATE_OLD_AVATAR_MENU; 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Set the default state 90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#if defined(OS_ANDROID) 91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) State state = STATE_ACCOUNT_CONSISTENCY; 92f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#else 935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) State state = STATE_OLD_AVATAR_MENU; 94f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif 95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (!trial_type.empty()) { 97cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (trial_type == "Enabled") { 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) state = STATE_NEW_PROFILE_MANAGEMENT; 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } else if (trial_type == "AccountConsistency") { 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) state = STATE_ACCOUNT_CONSISTENCY; 1016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } else if (trial_type == "NewAvatarMenu") { 1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) state = STATE_NEW_AVATAR_MENU; 103f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } else { 1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) state = STATE_OLD_AVATAR_MENU; 105cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return state; 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool CheckFlag(std::string command_switch, State min_state) { 112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Individiual flag settings take precedence. 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) 114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return true; 115cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 116cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return GetProcessState() >= min_state; 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace switches { 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool IsEnableAccountConsistency() { 124cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY; 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool IsEnableWebBasedSignin() { 128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return CommandLine::ForCurrentProcess()->HasSwitch( 129cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) switches::kEnableWebBasedSignin) && !IsNewProfileManagement(); 130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 132cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool IsExtensionsMultiAccount() { 133cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return CheckFlag(switches::kExtensionsMultiAccount, 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) STATE_NEW_PROFILE_MANAGEMENT); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbool IsFastUserSwitching() { 1380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return CommandLine::ForCurrentProcess()->HasSwitch( 1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::kFastUserSwitching); 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbool IsGoogleProfileInfo() { 1436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return CheckFlag(switches::kGoogleProfileInfo, STATE_NEW_AVATAR_MENU); 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 146a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool IsNewAvatarMenu() { 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return GetProcessState() >= STATE_NEW_AVATAR_MENU; 148a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 149a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbool IsNewProfileManagement() { 151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; 1520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 1530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 154a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool IsNewProfileManagementPreviewEnabled() { 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // No promotion to Enable Account Consistency. 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return false; 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { 1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) command_line->AppendSwitch(switches::kEnableNewAvatarMenu); 1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DCHECK(!command_line->HasSwitch(switches::kDisableNewAvatarMenu)); 162a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 163a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void DisableNewAvatarMenuForTesting(base::CommandLine* command_line) { 1656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) command_line->AppendSwitch(switches::kDisableNewAvatarMenu); 1666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DCHECK(!command_line->HasSwitch(switches::kEnableNewAvatarMenu)); 1676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 169f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { 170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) command_line->AppendSwitch(switches::kEnableNewProfileManagement); 171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); 172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { 175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) command_line->AppendSwitch(switches::kEnableAccountConsistency); 176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); 177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace switches 180