Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/signin/core/common/profile_management_switches.h" | 5 #include "components/signin/core/common/profile_management_switches.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "components/signin/core/common/signin_switches.h" | 10 #include "components/signin/core/common/signin_switches.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; | 14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; |
| 15 | 15 |
| 16 // Different state of new profile management/identity consistency. The code | 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 | 17 // below assumes the order of the values in this enum. That is, new profile |
| 18 // management is included in consistent identity. | 18 // management is included in consistent identity. |
| 19 enum State { | 19 enum State { |
| 20 STATE_NONE, | 20 STATE_OLD_AVATAR_MENU, |
| 21 STATE_NEW_AVATAR_MENU, | |
| 21 STATE_NEW_PROFILE_MANAGEMENT, | 22 STATE_NEW_PROFILE_MANAGEMENT, |
| 22 STATE_ACCOUNT_CONSISTENCY | 23 STATE_ACCOUNT_CONSISTENCY |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 State GetProcessState() { | 26 State GetProcessState() { |
| 26 // Get the full name of the field trial so that the underlying mechanism | 27 // Get the full name of the field trial so that the underlying mechanism |
| 27 // is properly initialized. | 28 // is properly initialized. |
| 28 std::string trial_type = | 29 std::string trial_type = |
| 29 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | 30 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); |
| 30 | 31 |
| 31 // Find the state of both command line args. | 32 // Find the state of both command line args. |
| 33 bool is_new_avatar_menu = | |
| 34 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 35 switches::kEnableNewAvatarMenu); | |
| 32 bool is_new_profile_management = | 36 bool is_new_profile_management = |
| 33 CommandLine::ForCurrentProcess()->HasSwitch( | 37 CommandLine::ForCurrentProcess()->HasSwitch( |
| 34 switches::kEnableNewProfileManagement); | 38 switches::kEnableNewProfileManagement); |
| 35 bool is_consistent_identity = | 39 bool is_consistent_identity = |
| 36 CommandLine::ForCurrentProcess()->HasSwitch( | 40 CommandLine::ForCurrentProcess()->HasSwitch( |
| 37 switches::kEnableAccountConsistency); | 41 switches::kEnableAccountConsistency); |
| 42 bool not_new_avatar_menu = | |
| 43 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 44 switches::kDisableNewAvatarMenu); | |
| 38 bool not_new_profile_management = | 45 bool not_new_profile_management = |
| 39 CommandLine::ForCurrentProcess()->HasSwitch( | 46 CommandLine::ForCurrentProcess()->HasSwitch( |
| 40 switches::kDisableNewProfileManagement); | 47 switches::kDisableNewProfileManagement); |
| 41 bool not_consistent_identity = | 48 bool not_consistent_identity = |
| 42 CommandLine::ForCurrentProcess()->HasSwitch( | 49 CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kDisableAccountConsistency); | 50 switches::kDisableAccountConsistency); |
| 44 int count_args = (is_new_profile_management ? 1 : 0) + | 51 int count_args = (is_new_avatar_menu ? 1 : 0) + |
| 52 (is_new_profile_management ? 1 : 0) + | |
| 45 (is_consistent_identity ? 1 : 0) + | 53 (is_consistent_identity ? 1 : 0) + |
| 54 (not_new_avatar_menu ? 1 : 0) + | |
| 46 (not_new_profile_management ? 1 : 0) + | 55 (not_new_profile_management ? 1 : 0) + |
| 47 (not_consistent_identity ? 1 : 0); | 56 (not_consistent_identity ? 1 : 0); |
| 48 bool invalid_commandline = count_args > 1; | 57 bool invalid_commandline = count_args > 1; |
| 49 | 58 |
| 50 // At most only one of the command line args should be specified, otherwise | 59 // 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 | 60 // 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. | 61 // the field trial so that data is not collected in the wrong group. |
| 53 if (invalid_commandline) { | 62 if (invalid_commandline) { |
| 54 base::FieldTrial* field_trial = | 63 base::FieldTrial* field_trial = |
| 55 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); | 64 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); |
| 56 if (field_trial) | 65 if (field_trial) |
| 57 field_trial->Disable(); | 66 field_trial->Disable(); |
| 58 | 67 |
| 59 trial_type.clear(); | 68 trial_type.clear(); |
| 60 } | 69 } |
| 61 | 70 |
| 71 // Forcing the old avatar menu takes precedent over other args. | |
| 62 // Enable command line args take precedent over disable command line args. | 72 // Enable command line args take precedent over disable command line args. |
| 63 // Consistent identity args take precedent over new profile management args. | 73 // Consistent identity args take precedent over new profile management args. |
| 64 if (is_consistent_identity) { | 74 if (not_new_avatar_menu) { |
| 75 return STATE_OLD_AVATAR_MENU; | |
| 76 } else if (is_consistent_identity) { | |
| 65 return STATE_ACCOUNT_CONSISTENCY; | 77 return STATE_ACCOUNT_CONSISTENCY; |
| 66 } else if (is_new_profile_management) { | 78 } else if (is_new_profile_management) { |
| 67 return STATE_NEW_PROFILE_MANAGEMENT; | 79 return STATE_NEW_PROFILE_MANAGEMENT; |
| 68 } else if (not_new_profile_management) { | 80 } else if (not_new_profile_management) { |
| 69 return STATE_NONE; | 81 return STATE_NEW_AVATAR_MENU; |
| 70 } else if (not_consistent_identity) { | 82 } else if (not_consistent_identity) { |
| 71 return STATE_NEW_PROFILE_MANAGEMENT; | 83 return STATE_NEW_AVATAR_MENU; |
| 72 } | 84 } |
| 73 | 85 |
| 74 #if defined(OS_ANDROID) | 86 #if defined(OS_ANDROID) |
| 75 State state = STATE_ACCOUNT_CONSISTENCY; | 87 State state = STATE_ACCOUNT_CONSISTENCY; |
| 76 #else | 88 #else |
| 77 State state = STATE_NONE; | 89 State state = STATE_NEW_AVATAR_MENU; |
| 78 #endif | 90 #endif |
| 79 | 91 |
| 80 if (!trial_type.empty()) { | 92 if (!trial_type.empty()) { |
| 81 if (trial_type == "Enabled") { | 93 if (trial_type == "Enabled") { |
| 82 state = STATE_NEW_PROFILE_MANAGEMENT; | 94 state = STATE_NEW_PROFILE_MANAGEMENT; |
| 83 } else if (trial_type == "AccountConsistency") { | 95 } else if (trial_type == "AccountConsistency") { |
| 84 state = STATE_ACCOUNT_CONSISTENCY; | 96 state = STATE_ACCOUNT_CONSISTENCY; |
| 85 } else { | 97 } else { |
| 86 state = STATE_NONE; | 98 state = STATE_NEW_AVATAR_MENU; |
| 87 } | 99 } |
| 88 } | 100 } |
| 89 | 101 |
| 90 return state; | 102 return state; |
| 91 } | 103 } |
| 92 | 104 |
| 93 bool CheckFlag(std::string command_switch, State min_state) { | 105 bool CheckFlag(std::string command_switch, State min_state) { |
| 94 // Individiual flag settings take precedence. | 106 // Individiual flag settings take precedence. |
| 95 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) | 107 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) |
| 96 return true; | 108 return true; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 120 return CommandLine::ForCurrentProcess()->HasSwitch( | 132 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 121 switches::kFastUserSwitching); | 133 switches::kFastUserSwitching); |
| 122 } | 134 } |
| 123 | 135 |
| 124 bool IsGoogleProfileInfo() { | 136 bool IsGoogleProfileInfo() { |
| 125 return CheckFlag(switches::kGoogleProfileInfo, | 137 return CheckFlag(switches::kGoogleProfileInfo, |
| 126 STATE_NEW_PROFILE_MANAGEMENT); | 138 STATE_NEW_PROFILE_MANAGEMENT); |
| 127 } | 139 } |
| 128 | 140 |
| 129 bool IsNewAvatarMenu() { | 141 bool IsNewAvatarMenu() { |
| 130 bool is_new_avatar_menu = | 142 return GetProcessState() >= STATE_NEW_AVATAR_MENU; |
| 131 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | |
| 132 return is_new_avatar_menu || IsNewProfileManagement(); | |
| 133 } | 143 } |
| 134 | 144 |
| 135 bool IsNewProfileManagement() { | 145 bool IsNewProfileManagement() { |
| 136 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; | 146 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
| 137 } | 147 } |
| 138 | 148 |
| 139 bool IsNewProfileManagementPreviewEnabled() { | 149 bool IsNewProfileManagementPreviewEnabled() { |
| 140 // No promotion to Enable Account Consistency. | 150 // No promotion to Enable Account Consistency. |
| 141 return false; | 151 return false; |
| 142 } | 152 } |
| 143 | 153 |
| 144 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { | 154 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { |
| 145 command_line->AppendSwitch(switches::kNewAvatarMenu); | 155 command_line->AppendSwitch(switches::kEnableNewAvatarMenu); |
| 146 } | 156 } |
|
Roger Tawa OOO till Jul 10th
2014/08/01 13:45:52
Add DCHECK that disable is not set, similar to the
| |
| 147 | 157 |
| 148 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { | 158 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { |
| 149 command_line->AppendSwitch(switches::kEnableNewProfileManagement); | 159 command_line->AppendSwitch(switches::kEnableNewProfileManagement); |
| 150 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); | 160 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); |
| 151 } | 161 } |
| 152 | 162 |
| 153 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { | 163 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { |
| 154 command_line->AppendSwitch(switches::kEnableAccountConsistency); | 164 command_line->AppendSwitch(switches::kEnableAccountConsistency); |
| 155 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); | 165 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); |
| 156 } | 166 } |
| 157 | 167 |
| 158 } // namespace switches | 168 } // namespace switches |
| OLD | NEW |