Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / signin / core / common / profile_management_switches.cc
blobe51c77e79dfb238216904bb3cfacebf5885d480e
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
3 // found in the LICENSE file.
5 #include "components/signin/core/common/profile_management_switches.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "build/build_config.h"
10 #include "components/signin/core/common/signin_switches.h"
12 namespace {
14 const char kNewProfileManagementFieldTrialName[] = "NewProfileManagement";
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
18 // management is included in consistent identity.
19 enum State {
20 STATE_OLD_AVATAR_MENU,
21 STATE_NEW_AVATAR_MENU,
22 STATE_NEW_PROFILE_MANAGEMENT,
23 STATE_ACCOUNT_CONSISTENCY,
26 State GetProcessState() {
27 // Find the state of both command line args.
28 bool is_new_avatar_menu =
29 CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kEnableNewAvatarMenu);
31 bool is_new_profile_management =
32 CommandLine::ForCurrentProcess()->HasSwitch(
33 switches::kEnableNewProfileManagement);
34 bool is_consistent_identity =
35 CommandLine::ForCurrentProcess()->HasSwitch(
36 switches::kEnableAccountConsistency);
37 bool not_new_avatar_menu =
38 CommandLine::ForCurrentProcess()->HasSwitch(
39 switches::kDisableNewAvatarMenu);
40 bool not_new_profile_management =
41 CommandLine::ForCurrentProcess()->HasSwitch(
42 switches::kDisableNewProfileManagement);
43 bool not_consistent_identity =
44 CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kDisableAccountConsistency);
46 int count_args = (is_new_avatar_menu ? 1 : 0) +
47 (is_new_profile_management ? 1 : 0) +
48 (is_consistent_identity ? 1 : 0) +
49 (not_new_avatar_menu ? 1 : 0) +
50 (not_new_profile_management ? 1 : 0) +
51 (not_consistent_identity ? 1 : 0);
52 bool invalid_commandline = count_args > 1;
54 // At most only one of the command line args should be specified, otherwise
55 // the finch group assignment is undefined. If this is the case, disable
56 // the field trial so that data is not collected in the wrong group.
57 std::string trial_type;
58 if (invalid_commandline) {
59 base::FieldTrial* field_trial =
60 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName);
61 if (field_trial)
62 field_trial->Disable();
64 trial_type.clear();
65 } else {
66 // Since the experiment is not being disabled, get the full name of the
67 // field trial which will initialize the underlying mechanism.
68 trial_type =
69 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName);
72 // Forcing the old avatar menu takes precedent over other args.
73 // Enable command line args take precedent over disable command line args.
74 // Consistent identity args take precedent over new profile management args.
75 if (not_new_avatar_menu) {
76 return STATE_OLD_AVATAR_MENU;
77 } else if (is_consistent_identity) {
78 return STATE_ACCOUNT_CONSISTENCY;
79 } else if (is_new_profile_management) {
80 return STATE_NEW_PROFILE_MANAGEMENT;
81 } else if (is_new_avatar_menu) {
82 return STATE_NEW_AVATAR_MENU;
83 } else if (not_new_profile_management) {
84 return STATE_OLD_AVATAR_MENU;
85 } else if (not_consistent_identity) {
86 return STATE_OLD_AVATAR_MENU;
89 // Set the default state
90 #if defined(OS_ANDROID)
91 State state = STATE_ACCOUNT_CONSISTENCY;
92 #else
93 State state = STATE_OLD_AVATAR_MENU;
94 #endif
96 if (!trial_type.empty()) {
97 if (trial_type == "Enabled") {
98 state = STATE_NEW_PROFILE_MANAGEMENT;
99 } else if (trial_type == "AccountConsistency") {
100 state = STATE_ACCOUNT_CONSISTENCY;
101 } else if (trial_type == "NewAvatarMenu") {
102 state = STATE_NEW_AVATAR_MENU;
103 } else {
104 state = STATE_OLD_AVATAR_MENU;
108 return state;
111 bool CheckFlag(std::string command_switch, State min_state) {
112 // Individiual flag settings take precedence.
113 if (CommandLine::ForCurrentProcess()->HasSwitch(command_switch))
114 return true;
116 return GetProcessState() >= min_state;
119 } // namespace
121 namespace switches {
123 bool IsEnableAccountConsistency() {
124 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY;
127 bool IsEnableWebBasedSignin() {
128 return CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kEnableWebBasedSignin) && !IsNewProfileManagement();
132 bool IsExtensionsMultiAccount() {
133 return CheckFlag(switches::kExtensionsMultiAccount,
134 STATE_NEW_PROFILE_MANAGEMENT);
137 bool IsFastUserSwitching() {
138 return CommandLine::ForCurrentProcess()->HasSwitch(
139 switches::kFastUserSwitching);
142 bool IsGoogleProfileInfo() {
143 return CheckFlag(switches::kGoogleProfileInfo, STATE_NEW_AVATAR_MENU);
146 bool IsNewAvatarMenu() {
147 return GetProcessState() >= STATE_NEW_AVATAR_MENU;
150 bool IsNewProfileManagement() {
151 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT;
154 bool IsNewProfileManagementPreviewEnabled() {
155 // No promotion to Enable Account Consistency.
156 return false;
159 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) {
160 command_line->AppendSwitch(switches::kEnableNewAvatarMenu);
161 DCHECK(!command_line->HasSwitch(switches::kDisableNewAvatarMenu));
164 void DisableNewAvatarMenuForTesting(base::CommandLine* command_line) {
165 command_line->AppendSwitch(switches::kDisableNewAvatarMenu);
166 DCHECK(!command_line->HasSwitch(switches::kEnableNewAvatarMenu));
169 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) {
170 command_line->AppendSwitch(switches::kEnableNewProfileManagement);
171 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement));
174 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) {
175 command_line->AppendSwitch(switches::kEnableAccountConsistency);
176 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency));
179 } // namespace switches