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 "components/signin/core/common/signin_switches.h" | 10 #include "components/signin/core/common/signin_switches.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; | 14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement"; |
14 | 15 |
15 // Different state of new profile management/identity consistency. The code | 16 // 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 // below assumes the order of the values in this enum. That is, new profile |
17 // management is included in consistent identity. | 18 // management is included in consistent identity. |
18 enum State { | 19 enum State { |
19 STATE_NONE, | 20 STATE_NONE, |
20 STATE_NEW_PROFILE_MANAGEMENT, | 21 STATE_NEW_PROFILE_MANAGEMENT, |
21 STATE_ACCOUNT_CONSISTENCY | 22 STATE_ACCOUNT_CONSISTENCY |
22 }; | 23 }; |
23 | 24 |
24 State GetProcessState() { | 25 State GetProcessState() { |
25 // Get the full name of the field trial so that the underlying mechanism | 26 // Get the full name of the field trial so that the underlying mechanism |
26 // is properly initialize. | 27 // is properly initialized. |
27 std::string trial_type = | 28 std::string trial_type = |
28 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); | 29 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName); |
29 | 30 |
30 // Find the state of both command line args. | 31 // Find the state of both command line args. |
31 bool is_new_profile_management = | 32 bool is_new_profile_management = |
32 CommandLine::ForCurrentProcess()->HasSwitch( | 33 CommandLine::ForCurrentProcess()->HasSwitch( |
33 switches::kNewProfileManagement); | 34 switches::kEnableNewProfileManagement); |
34 bool is_consistent_identity = | 35 bool is_consistent_identity = |
35 CommandLine::ForCurrentProcess()->HasSwitch( | 36 CommandLine::ForCurrentProcess()->HasSwitch( |
36 switches::kEnableAccountConsistency); | 37 switches::kEnableAccountConsistency); |
| 38 bool not_new_profile_management = |
| 39 CommandLine::ForCurrentProcess()->HasSwitch( |
| 40 switches::kDisableNewProfileManagement); |
| 41 bool not_consistent_identity = |
| 42 CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kDisableAccountConsistency); |
| 44 int count_args = (is_new_profile_management ? 1 : 0) + |
| 45 (is_consistent_identity ? 1 : 0) + |
| 46 (not_new_profile_management ? 1 : 0) + |
| 47 (not_consistent_identity ? 1 : 0); |
| 48 bool invalid_commandline = count_args > 1; |
37 | 49 |
38 State state = STATE_NONE; | 50 // At most only one of the command line args should be specified, otherwise |
39 | 51 // the finch group assignment is undefined. If this is the case, disable |
40 // If both command line args are set, disable the field trial completely | 52 // the field trial so that data is not collected in the wrong group. |
41 // since the assigned group is undefined. Otherwise use the state of the | 53 if (invalid_commandline) { |
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 = | 54 base::FieldTrial* field_trial = |
46 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); | 55 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName); |
47 if (field_trial) | 56 if (field_trial) |
48 field_trial->Disable(); | 57 field_trial->Disable(); |
49 | 58 |
| 59 trial_type.clear(); |
| 60 } |
| 61 |
| 62 // Enable command line args take precedent over disable command line args. |
| 63 // Consistent identity args take precedent over new profile management args. |
| 64 if (is_consistent_identity) { |
50 return STATE_ACCOUNT_CONSISTENCY; | 65 return STATE_ACCOUNT_CONSISTENCY; |
51 } else if (is_new_profile_management) { | 66 } else if (is_new_profile_management) { |
52 return STATE_NEW_PROFILE_MANAGEMENT; | 67 return STATE_NEW_PROFILE_MANAGEMENT; |
53 } else if (is_consistent_identity) { | 68 } else if (not_new_profile_management) { |
54 return STATE_ACCOUNT_CONSISTENCY; | 69 return STATE_NONE; |
| 70 } else if (not_consistent_identity) { |
| 71 return STATE_NEW_PROFILE_MANAGEMENT; |
55 } | 72 } |
56 | 73 |
57 if (state == STATE_NONE && !trial_type.empty()) { | 74 #if defined(OS_ANDROID) |
| 75 State state = STATE_ACCOUNT_CONSISTENCY; |
| 76 #else |
| 77 State state = STATE_NONE; |
| 78 #endif |
| 79 |
| 80 if (!trial_type.empty()) { |
58 if (trial_type == "Enabled") { | 81 if (trial_type == "Enabled") { |
59 state = STATE_NEW_PROFILE_MANAGEMENT; | 82 state = STATE_NEW_PROFILE_MANAGEMENT; |
60 } else if (trial_type == "AccountConsistency") { | 83 } else if (trial_type == "AccountConsistency") { |
61 state = STATE_ACCOUNT_CONSISTENCY; | 84 state = STATE_ACCOUNT_CONSISTENCY; |
| 85 } else { |
| 86 state = STATE_NONE; |
62 } | 87 } |
63 } | 88 } |
64 | 89 |
65 return state; | 90 return state; |
66 } | 91 } |
67 | 92 |
68 bool CheckFlag(std::string command_switch, State min_state) { | 93 bool CheckFlag(std::string command_switch, State min_state) { |
69 // Individiual flag settings take precedence. | 94 // Individiual flag settings take precedence. |
70 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) | 95 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch)) |
71 return true; | 96 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 bool IsNewProfileManagement() { | 138 bool IsNewProfileManagement() { |
114 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; | 139 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT; |
115 } | 140 } |
116 | 141 |
117 bool IsNewProfileManagementPreviewEnabled() { | 142 bool IsNewProfileManagementPreviewEnabled() { |
118 bool is_new_avatar_menu = | 143 bool is_new_avatar_menu = |
119 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); | 144 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewAvatarMenu); |
120 return is_new_avatar_menu && IsNewProfileManagement(); | 145 return is_new_avatar_menu && IsNewProfileManagement(); |
121 } | 146 } |
122 | 147 |
| 148 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) { |
| 149 command_line->AppendSwitch(switches::kEnableNewProfileManagement); |
| 150 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement)); |
| 151 } |
| 152 |
| 153 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) { |
| 154 command_line->AppendSwitch(switches::kEnableAccountConsistency); |
| 155 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency)); |
| 156 } |
| 157 |
123 } // namespace switches | 158 } // namespace switches |
OLD | NEW |