profile_management_switches.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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 "components/signin/core/common/signin_switches.h" 10 11namespace { 12 13const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; 14 15// Different state of new profile management/identity consistency. The code 16// below assumes the order of the values in this enum. That is, new profile 17// management is included in consistent identity. 18enum State { 19 STATE_NONE, 20 STATE_NEW_PROFILE_MANAGEMENT, 21 STATE_ACCOUNT_CONSISTENCY 22}; 23 24State GetProcessState() { 25 // Get the full name of the field trial so that the underlying mechanism 26 // is properly initialize. 27 std::string trial_type = 28 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); 29 30 // Find the state of both command line args. 31 bool is_new_profile_management = 32 CommandLine::ForCurrentProcess()->HasSwitch( 33 switches::kNewProfileManagement); 34 bool is_consistent_identity = 35 CommandLine::ForCurrentProcess()->HasSwitch( 36 switches::kEnableAccountConsistency); 37 38 State state = STATE_NONE; 39 40 // If both command line args are set, disable the field trial completely 41 // since the assigned group is undefined. Otherwise use the state of the 42 // command line flag specified. If neither command line arg is specified, 43 // see if the group was set from the server. 44 if (is_new_profile_management && is_consistent_identity) { 45 base::FieldTrial* field_trial = 46 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); 47 if (field_trial) 48 field_trial->Disable(); 49 50 return STATE_ACCOUNT_CONSISTENCY; 51 } else if (is_new_profile_management) { 52 return STATE_NEW_PROFILE_MANAGEMENT; 53 } else if (is_consistent_identity) { 54 return STATE_ACCOUNT_CONSISTENCY; 55 } 56 57 if (state == STATE_NONE && !trial_type.empty()) { 58 if (trial_type == "Enabled") { 59 state = STATE_NEW_PROFILE_MANAGEMENT; 60 } else if (trial_type == "AccountConsistency") { 61 state = STATE_ACCOUNT_CONSISTENCY; 62 } 63 } 64 65 return state; 66} 67 68bool CheckFlag(std::string command_switch, State min_state) { 69 // Individiual flag settings take precedence. 70 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) 71 return true; 72 73 return GetProcessState() >= min_state; 74} 75 76} // namespace 77 78namespace switches { 79 80bool IsEnableAccountConsistency() { 81 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY; 82} 83 84bool IsEnableWebBasedSignin() { 85 return CommandLine::ForCurrentProcess()->HasSwitch( 86 switches::kEnableWebBasedSignin) && !IsNewProfileManagement(); 87} 88 89bool IsExtensionsMultiAccount() { 90 return CheckFlag(switches::kExtensionsMultiAccount, 91 STATE_NEW_PROFILE_MANAGEMENT); 92} 93 94bool IsFastUserSwitching() { 95 bool use_mirror_promo_menu = 96 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && 97 !IsNewProfileManagement(); 98 return CommandLine::ForCurrentProcess()->HasSwitch( 99 switches::kFastUserSwitching) || use_mirror_promo_menu; 100} 101 102bool IsGoogleProfileInfo() { 103 return CheckFlag(switches::kGoogleProfileInfo, 104 STATE_NEW_PROFILE_MANAGEMENT); 105} 106 107bool IsNewAvatarMenu() { 108 bool is_new_avatar_menu = 109 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); 110 return is_new_avatar_menu || IsNewProfileManagement(); 111} 112 113bool IsNewProfileManagement() { 114 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; 115} 116 117bool IsNewProfileManagementPreviewEnabled() { 118 bool is_new_avatar_menu = 119 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); 120 return is_new_avatar_menu && IsNewProfileManagement(); 121} 122 123} // namespace switches 124