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 |
msw
2014/08/01 16:45:14
nit: trailing comma
Mike Lerman
2014/08/01 19:15:00
Done.
| |
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 // is properly initialized. | |
28 std::string trial_type = | |
29 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | |
30 | |
31 // Find the state of both command line args. | 27 // Find the state of both command line args. |
28 bool is_new_avatar_menu = | |
29 CommandLine::ForCurrentProcess()->HasSwitch( | |
30 switches::kEnableNewAvatarMenu); | |
32 bool is_new_profile_management = | 31 bool is_new_profile_management = |
33 CommandLine::ForCurrentProcess()->HasSwitch( | 32 CommandLine::ForCurrentProcess()->HasSwitch( |
34 switches::kEnableNewProfileManagement); | 33 switches::kEnableNewProfileManagement); |
35 bool is_consistent_identity = | 34 bool is_consistent_identity = |
36 CommandLine::ForCurrentProcess()->HasSwitch( | 35 CommandLine::ForCurrentProcess()->HasSwitch( |
37 switches::kEnableAccountConsistency); | 36 switches::kEnableAccountConsistency); |
37 bool not_new_avatar_menu = | |
38 CommandLine::ForCurrentProcess()->HasSwitch( | |
39 switches::kDisableNewAvatarMenu); | |
38 bool not_new_profile_management = | 40 bool not_new_profile_management = |
39 CommandLine::ForCurrentProcess()->HasSwitch( | 41 CommandLine::ForCurrentProcess()->HasSwitch( |
40 switches::kDisableNewProfileManagement); | 42 switches::kDisableNewProfileManagement); |
41 bool not_consistent_identity = | 43 bool not_consistent_identity = |
42 CommandLine::ForCurrentProcess()->HasSwitch( | 44 CommandLine::ForCurrentProcess()->HasSwitch( |
43 switches::kDisableAccountConsistency); | 45 switches::kDisableAccountConsistency); |
44 int count_args = (is_new_profile_management ? 1 : 0) + | 46 int count_args = (is_new_avatar_menu ? 1 : 0) + |
47 (is_new_profile_management ? 1 : 0) + | |
45 (is_consistent_identity ? 1 : 0) + | 48 (is_consistent_identity ? 1 : 0) + |
49 (not_new_avatar_menu ? 1 : 0) + | |
46 (not_new_profile_management ? 1 : 0) + | 50 (not_new_profile_management ? 1 : 0) + |
47 (not_consistent_identity ? 1 : 0); | 51 (not_consistent_identity ? 1 : 0); |
48 bool invalid_commandline = count_args > 1; | 52 bool invalid_commandline = count_args > 1; |
49 | 53 |
54 | |
msw
2014/08/01 16:45:15
nit: remove extra blank line
Mike Lerman
2014/08/01 19:15:00
Done.
| |
50 // At most only one of the command line args should be specified, otherwise | 55 // 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 | 56 // 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. | 57 // the field trial so that data is not collected in the wrong group. |
58 std::string trial_type; | |
53 if (invalid_commandline) { | 59 if (invalid_commandline) { |
54 base::FieldTrial* field_trial = | 60 base::FieldTrial* field_trial = |
55 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); | 61 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); |
56 if (field_trial) | 62 if (field_trial) |
57 field_trial->Disable(); | 63 field_trial->Disable(); |
58 | 64 |
59 trial_type.clear(); | 65 trial_type.clear(); |
66 } else { | |
67 // Since the experiment is not being disabled, get the full name of the | |
68 // field trial which will initialize the underlying mechanism. | |
69 trial_type = | |
70 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | |
60 } | 71 } |
61 | 72 |
73 // Forcing the old avatar menu takes precedent over other args. | |
62 // Enable command line args take precedent over disable command line args. | 74 // Enable command line args take precedent over disable command line args. |
63 // Consistent identity args take precedent over new profile management args. | 75 // Consistent identity args take precedent over new profile management args. |
64 if (is_consistent_identity) { | 76 if (not_new_avatar_menu) { |
77 return STATE_OLD_AVATAR_MENU; | |
78 } else if (is_consistent_identity) { | |
65 return STATE_ACCOUNT_CONSISTENCY; | 79 return STATE_ACCOUNT_CONSISTENCY; |
66 } else if (is_new_profile_management) { | 80 } else if (is_new_profile_management) { |
67 return STATE_NEW_PROFILE_MANAGEMENT; | 81 return STATE_NEW_PROFILE_MANAGEMENT; |
68 } else if (not_new_profile_management) { | 82 } else if (not_new_profile_management) { |
69 return STATE_NONE; | 83 return STATE_NEW_AVATAR_MENU; |
70 } else if (not_consistent_identity) { | 84 } else if (not_consistent_identity) { |
71 return STATE_NEW_PROFILE_MANAGEMENT; | 85 return STATE_NEW_AVATAR_MENU; |
72 } | 86 } |
73 | 87 |
88 // Set the default state | |
74 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
75 State state = STATE_ACCOUNT_CONSISTENCY; | 90 State state = STATE_ACCOUNT_CONSISTENCY; |
76 #else | 91 #else |
77 State state = STATE_NONE; | 92 State state = STATE_NEW_AVATAR_MENU; |
78 #endif | 93 #endif |
79 | 94 |
80 if (!trial_type.empty()) { | 95 if (!trial_type.empty()) { |
81 if (trial_type == "Enabled") { | 96 if (trial_type == "Enabled") { |
82 state = STATE_NEW_PROFILE_MANAGEMENT; | 97 state = STATE_NEW_PROFILE_MANAGEMENT; |
83 } else if (trial_type == "AccountConsistency") { | 98 } else if (trial_type == "AccountConsistency") { |
84 state = STATE_ACCOUNT_CONSISTENCY; | 99 state = STATE_ACCOUNT_CONSISTENCY; |
85 } else { | 100 } else { |
86 state = STATE_NONE; | 101 state = STATE_NEW_AVATAR_MENU; |
87 } | 102 } |
88 } | 103 } |
89 | 104 |
90 return state; | 105 return state; |
91 } | 106 } |
92 | 107 |
93 bool CheckFlag(std::string command_switch, State min_state) { | 108 bool CheckFlag(std::string command_switch, State min_state) { |
94 // Individiual flag settings take precedence. | 109 // Individiual flag settings take precedence. |
95 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) | 110 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) |
96 return true; | 111 return true; |
(...skipping 23 matching lines...) Expand all Loading... | |
120 return CommandLine::ForCurrentProcess()->HasSwitch( | 135 return CommandLine::ForCurrentProcess()->HasSwitch( |
121 switches::kFastUserSwitching); | 136 switches::kFastUserSwitching); |
122 } | 137 } |
123 | 138 |
124 bool IsGoogleProfileInfo() { | 139 bool IsGoogleProfileInfo() { |
125 return CheckFlag(switches::kGoogleProfileInfo, | 140 return CheckFlag(switches::kGoogleProfileInfo, |
126 STATE_NEW_PROFILE_MANAGEMENT); | 141 STATE_NEW_PROFILE_MANAGEMENT); |
127 } | 142 } |
128 | 143 |
129 bool IsNewAvatarMenu() { | 144 bool IsNewAvatarMenu() { |
130 bool is_new_avatar_menu = | 145 return GetProcessState() >= STATE_NEW_AVATAR_MENU; |
131 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | |
132 return is_new_avatar_menu || IsNewProfileManagement(); | |
133 } | 146 } |
134 | 147 |
135 bool IsNewProfileManagement() { | 148 bool IsNewProfileManagement() { |
136 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; | 149 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
137 } | 150 } |
138 | 151 |
139 bool IsNewProfileManagementPreviewEnabled() { | 152 bool IsNewProfileManagementPreviewEnabled() { |
140 // No promotion to Enable Account Consistency. | 153 // No promotion to Enable Account Consistency. |
141 return false; | 154 return false; |
142 } | 155 } |
143 | 156 |
144 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { | 157 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) { |
145 command_line->AppendSwitch(switches::kNewAvatarMenu); | 158 command_line->AppendSwitch(switches::kEnableNewAvatarMenu); |
159 DCHECK(!command_line->HasSwitch(switches::kDisableNewAvatarMenu)); | |
146 } | 160 } |
147 | 161 |
148 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { | 162 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { |
149 command_line->AppendSwitch(switches::kEnableNewProfileManagement); | 163 command_line->AppendSwitch(switches::kEnableNewProfileManagement); |
150 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); | 164 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); |
151 } | 165 } |
152 | 166 |
153 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { | 167 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { |
154 command_line->AppendSwitch(switches::kEnableAccountConsistency); | 168 command_line->AppendSwitch(switches::kEnableAccountConsistency); |
155 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); | 169 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); |
156 } | 170 } |
157 | 171 |
158 } // namespace switches | 172 } // namespace switches |
OLD | NEW |