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 // Individiual flag settings take precedence. | 16 // below assumes the order of the values in this enum. That is, new profile |
17 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) { | 17 // management is included in consistent identity. |
18 return true; | 18 enum State { |
| 19 STATE_NONE, |
| 20 STATE_NEW_PROFILE_MANAGEMENT, |
| 21 STATE_ACCOUNT_CONSISTENCY |
| 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::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; |
19 } | 55 } |
20 | 56 |
21 // --new-profile-management flag always affects all switches. | 57 if (state == STATE_NONE && !trial_type.empty()) { |
22 if (CommandLine::ForCurrentProcess()->HasSwitch( | 58 if (trial_type == "Enabled") { |
23 switches::kNewProfileManagement)) { | 59 state = STATE_NEW_PROFILE_MANAGEMENT; |
24 return active_state; | 60 } else if (trial_type == "AccountConsistency") { |
| 61 state = STATE_ACCOUNT_CONSISTENCY; |
| 62 } |
25 } | 63 } |
26 | 64 |
27 // NewProfileManagement experiment acts like above flag. | 65 return state; |
28 std::string trial_type = | 66 } |
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 | 67 |
37 return false; | 68 bool 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; |
38 } | 74 } |
39 | 75 |
40 } // namespace | 76 } // namespace |
41 | 77 |
42 namespace switches { | 78 namespace switches { |
43 | 79 |
| 80 bool IsEnableAccountConsistency() { |
| 81 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY; |
| 82 } |
| 83 |
44 bool IsEnableWebBasedSignin() { | 84 bool IsEnableWebBasedSignin() { |
45 return CheckProfileManagementFlag(switches::kEnableWebBasedSignin, false); | 85 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 switches::kEnableWebBasedSignin) && !IsNewProfileManagement(); |
46 } | 87 } |
47 | 88 |
48 bool IsExtensionsMultiAccount() { | 89 bool IsExtensionsMultiAccount() { |
49 return CheckProfileManagementFlag(switches::kExtensionsMultiAccount, true); | 90 return CheckFlag(switches::kExtensionsMultiAccount, |
| 91 STATE_NEW_PROFILE_MANAGEMENT); |
50 } | 92 } |
51 | 93 |
52 bool IsFastUserSwitching() { | 94 bool IsFastUserSwitching() { |
53 bool use_mirror_promo_menu = | 95 bool use_mirror_promo_menu = |
54 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && | 96 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu) && |
55 !IsNewProfileManagement(); | 97 !IsNewProfileManagement(); |
56 return CommandLine::ForCurrentProcess()->HasSwitch( | 98 return CommandLine::ForCurrentProcess()->HasSwitch( |
57 switches::kFastUserSwitching) || use_mirror_promo_menu; | 99 switches::kFastUserSwitching) || use_mirror_promo_menu; |
58 } | 100 } |
59 | 101 |
60 bool IsGoogleProfileInfo() { | 102 bool IsGoogleProfileInfo() { |
61 return CheckProfileManagementFlag(switches::kGoogleProfileInfo, true); | 103 return CheckFlag(switches::kGoogleProfileInfo, |
| 104 STATE_NEW_PROFILE_MANAGEMENT); |
62 } | 105 } |
63 | 106 |
64 bool IsNewAvatarMenu() { | 107 bool IsNewAvatarMenu() { |
65 bool is_new_avatar_menu = | 108 bool is_new_avatar_menu = |
66 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | 109 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); |
67 return is_new_avatar_menu || IsNewProfileManagement(); | 110 return is_new_avatar_menu || IsNewProfileManagement(); |
68 } | 111 } |
69 | 112 |
70 bool IsNewProfileManagement() { | 113 bool IsNewProfileManagement() { |
71 return CheckProfileManagementFlag(switches::kNewProfileManagement, true); | 114 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
72 } | 115 } |
73 | 116 |
74 bool IsNewProfileManagementPreviewEnabled() { | 117 bool IsNewProfileManagementPreviewEnabled() { |
75 bool is_new_avatar_menu = | 118 bool is_new_avatar_menu = |
76 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | 119 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); |
77 return is_new_avatar_menu && IsNewProfileManagement(); | 120 return is_new_avatar_menu && IsNewProfileManagement(); |
78 } | 121 } |
79 | 122 |
80 } // namespace switches | 123 } // namespace switches |
OLD | NEW |