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 "components/signin/core/common/signin_switches.h" | 9 #include "components/signin/core/common/signin_switches.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; | 13 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; |
| 14 | 14 |
| 15 bool CheckProfileManagementFlag(std::string command_switch, bool active_state) { | 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. | |
| 18 enum State { | |
| 19 STATE_NONE, | |
| 20 STATE_NEW_PROFILE_MANAGEMENT, | |
| 21 STATE_CONSISTENT_IDENTITY | |
| 22 }; | |
| 23 | |
| 24 State 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::kConsistentIdentity); | |
| 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 } else if (is_new_profile_management) { | |
| 50 return STATE_NEW_PROFILE_MANAGEMENT; | |
| 51 } else if (is_consistent_identity) { | |
| 52 return STATE_CONSISTENT_IDENTITY; | |
| 53 } | |
| 54 | |
| 55 if (state == STATE_NONE && !trial_type.empty()) { | |
| 56 if (trial_type == "Enabled") { | |
| 57 state = STATE_NEW_PROFILE_MANAGEMENT; | |
| 58 } else if (trial_type == "ConsistentIdentity") { | |
| 59 state = STATE_CONSISTENT_IDENTITY; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 return state; | |
| 64 } | |
| 65 | |
| 66 bool CheckFlag(std::string command_switch, State max_state, bool active_state) { | |
|
guohui
2014/05/28 18:27:23
as discussed offline, this should be the min_state
Roger Tawa OOO till Jul 10th
2014/05/29 01:23:12
Yeah, not sure how I reversed the condition. At t
| |
| 16 // Individiual flag settings take precedence. | 67 // Individiual flag settings take precedence. |
| 17 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) { | 68 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) { |
| 18 return true; | 69 return true; |
| 19 } | 70 } |
| 20 | 71 |
| 21 // --new-profile-management flag always affects all switches. | 72 State state = GetProcessState(); |
| 22 if (CommandLine::ForCurrentProcess()->HasSwitch( | 73 return state == STATE_NONE |
| 23 switches::kNewProfileManagement)) { | 74 ? false : (state <= max_state ? active_state : !active_state); |
| 24 return active_state; | |
| 25 } | |
| 26 | |
| 27 // NewProfileManagement experiment acts like above flag. | |
| 28 std::string trial_type = | |
| 29 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | |
| 30 if (!trial_type.empty()) { | |
| 31 if (trial_type == "Enabled") | |
| 32 return active_state; | |
| 33 if (trial_type == "Disabled") | |
| 34 return !active_state; | |
| 35 } | |
| 36 | |
| 37 return false; | |
| 38 } | 75 } |
| 39 | 76 |
| 40 } // namespace | 77 } // namespace |
| 41 | 78 |
| 42 namespace switches { | 79 namespace switches { |
| 43 | 80 |
| 81 bool IsConsistentIdentity() { | |
| 82 return GetProcessState() >= STATE_CONSISTENT_IDENTITY; | |
| 83 } | |
| 84 | |
| 44 bool IsEnableWebBasedSignin() { | 85 bool IsEnableWebBasedSignin() { |
| 45 return CheckProfileManagementFlag(switches::kEnableWebBasedSignin, false); | 86 return CheckFlag(switches::kEnableWebBasedSignin, |
| 87 STATE_NEW_PROFILE_MANAGEMENT, | |
| 88 false); | |
| 46 } | 89 } |
| 47 | 90 |
| 48 bool IsExtensionsMultiAccount() { | 91 bool IsExtensionsMultiAccount() { |
| 49 return CheckProfileManagementFlag(switches::kExtensionsMultiAccount, true); | 92 return CheckFlag(switches::kExtensionsMultiAccount, |
| 93 STATE_NEW_PROFILE_MANAGEMENT, | |
| 94 true); | |
| 50 } | 95 } |
| 51 | 96 |
| 52 bool IsFastUserSwitching() { | 97 bool IsFastUserSwitching() { |
| 53 bool use_mirror_promo_menu = | 98 bool use_mirror_promo_menu = |
| 54 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && | 99 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && |
| 55 !IsNewProfileManagement(); | 100 !IsNewProfileManagement(); |
| 56 return CommandLine::ForCurrentProcess()->HasSwitch( | 101 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 57 switches::kFastUserSwitching) || use_mirror_promo_menu; | 102 switches::kFastUserSwitching) || use_mirror_promo_menu; |
| 58 } | 103 } |
| 59 | 104 |
| 60 bool IsGoogleProfileInfo() { | 105 bool IsGoogleProfileInfo() { |
| 61 return CheckProfileManagementFlag(switches::kGoogleProfileInfo, true); | 106 return CheckFlag(switches::kGoogleProfileInfo, |
| 107 STATE_NEW_PROFILE_MANAGEMENT, | |
| 108 true); | |
| 62 } | 109 } |
| 63 | 110 |
| 64 bool IsNewAvatarMenu() { | 111 bool IsNewAvatarMenu() { |
| 65 bool is_new_avatar_menu = | 112 bool is_new_avatar_menu = |
| 66 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | 113 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); |
| 67 return is_new_avatar_menu || IsNewProfileManagement(); | 114 return is_new_avatar_menu || IsNewProfileManagement(); |
| 68 } | 115 } |
| 69 | 116 |
| 70 bool IsNewProfileManagement() { | 117 bool IsNewProfileManagement() { |
| 71 return CheckProfileManagementFlag(switches::kNewProfileManagement, true); | 118 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
| 72 } | 119 } |
| 73 | 120 |
| 74 bool IsNewProfileManagementPreviewEnabled() { | 121 bool IsNewProfileManagementPreviewEnabled() { |
| 75 bool is_new_avatar_menu = | 122 bool is_new_avatar_menu = |
| 76 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | 123 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); |
| 77 return is_new_avatar_menu && IsNewProfileManagement(); | 124 return is_new_avatar_menu && IsNewProfileManagement(); |
| 78 } | 125 } |
| 79 | 126 |
| 80 } // namespace switches | 127 } // namespace switches |
| OLD | NEW |