Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / signin / core / common / profile_management_switches.cc
blob6d58837d6524fffdfd513194ed88e1a5fb44aeb4
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 = base::CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kEnableNewAvatarMenu);
30 bool is_new_profile_management =
31 base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kEnableNewProfileManagement);
33 bool is_consistent_identity =
34 base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kEnableAccountConsistency);
36 bool not_new_avatar_menu = base::CommandLine::ForCurrentProcess()->HasSwitch(
37 switches::kDisableNewAvatarMenu);
38 bool not_new_profile_management =
39 base::CommandLine::ForCurrentProcess()->HasSwitch(
40 switches::kDisableNewProfileManagement);
41 bool not_consistent_identity =
42 base::CommandLine::ForCurrentProcess()->HasSwitch(
43 switches::kDisableAccountConsistency);
44 int count_args = (is_new_avatar_menu ? 1 : 0) +
45 (is_new_profile_management ? 1 : 0) +
46 (is_consistent_identity ? 1 : 0) +
47 (not_new_avatar_menu ? 1 : 0) +
48 (not_new_profile_management ? 1 : 0) +
49 (not_consistent_identity ? 1 : 0);
50 bool invalid_commandline = count_args > 1;
52 // At most only one of the command line args should be specified, otherwise
53 // the finch group assignment is undefined. If this is the case, disable
54 // the field trial so that data is not collected in the wrong group.
55 std::string trial_type;
56 if (invalid_commandline) {
57 base::FieldTrial* field_trial =
58 base::FieldTrialList::Find(kNewProfileManagementFieldTrialName);
59 if (field_trial)
60 field_trial->Disable();
62 trial_type.clear();
63 } else {
64 // Since the experiment is not being disabled, get the full name of the
65 // field trial which will initialize the underlying mechanism.
66 trial_type =
67 base::FieldTrialList::FindFullName(kNewProfileManagementFieldTrialName);
70 // Forcing the old avatar menu takes precedent over other args.
71 // Enable command line args take precedent over disable command line args.
72 // Consistent identity args take precedent over new profile management args.
73 if (not_new_avatar_menu) {
74 return STATE_OLD_AVATAR_MENU;
75 } else if (is_consistent_identity) {
76 return STATE_ACCOUNT_CONSISTENCY;
77 } else if (is_new_profile_management) {
78 return STATE_NEW_PROFILE_MANAGEMENT;
79 } else if (is_new_avatar_menu) {
80 return STATE_NEW_AVATAR_MENU;
81 } else if (not_new_profile_management) {
82 return STATE_NEW_AVATAR_MENU;
83 } else if (not_consistent_identity) {
84 return STATE_NEW_PROFILE_MANAGEMENT;
87 // Set the default state
88 #if defined(OS_ANDROID) || defined(OS_IOS)
89 State state = STATE_ACCOUNT_CONSISTENCY;
90 #else
91 State state = STATE_NEW_PROFILE_MANAGEMENT;
92 #endif
94 if (!trial_type.empty()) {
95 if (trial_type == "Enabled") {
96 state = STATE_NEW_PROFILE_MANAGEMENT;
97 } else if (trial_type == "AccountConsistency") {
98 state = STATE_ACCOUNT_CONSISTENCY;
99 } else if (trial_type == "NewAvatarMenu") {
100 state = STATE_NEW_AVATAR_MENU;
101 } else {
102 state = STATE_NEW_PROFILE_MANAGEMENT;
106 return state;
109 bool CheckFlag(std::string command_switch, State min_state) {
110 // Individiual flag settings take precedence.
111 if (base::CommandLine::ForCurrentProcess()->HasSwitch(command_switch))
112 return true;
114 return GetProcessState() >= min_state;
117 } // namespace
119 namespace switches {
121 bool IsEnableAccountConsistency() {
122 return GetProcessState() >= STATE_ACCOUNT_CONSISTENCY;
125 bool IsEnableWebviewBasedSignin() {
126 // For now, the webview is enabled only for desktop.
127 #if defined(OS_CHROMEOS)
128 return false;
129 #else
130 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
131 switches::kEnableIframeBasedSignin);
132 #endif
135 bool IsExtensionsMultiAccount() {
136 return CheckFlag(switches::kExtensionsMultiAccount,
137 STATE_ACCOUNT_CONSISTENCY);
140 bool IsGoogleProfileInfo() {
141 return CheckFlag(switches::kGoogleProfileInfo, STATE_NEW_AVATAR_MENU);
144 bool IsNewAvatarMenu() {
145 // NewAvatarMenu is only available on desktop.
146 #if defined(OS_ANDROID) || defined(OS_IOS) || defined(OS_CHROMEOS)
147 return false;
148 #else
149 return GetProcessState() >= STATE_NEW_AVATAR_MENU;
150 #endif
153 bool IsNewProfileManagement() {
154 return GetProcessState() >= STATE_NEW_PROFILE_MANAGEMENT;
157 bool IsNewProfileManagementPreviewEnabled() {
158 // No promotion to Enable Account Consistency.
159 return false;
162 void EnableNewAvatarMenuForTesting(base::CommandLine* command_line) {
163 command_line->AppendSwitch(switches::kEnableNewAvatarMenu);
164 DCHECK(!command_line->HasSwitch(switches::kDisableNewAvatarMenu));
167 void DisableNewAvatarMenuForTesting(base::CommandLine* command_line) {
168 command_line->AppendSwitch(switches::kDisableNewAvatarMenu);
169 DCHECK(!command_line->HasSwitch(switches::kEnableNewAvatarMenu));
172 void EnableNewProfileManagementForTesting(base::CommandLine* command_line) {
173 command_line->AppendSwitch(switches::kEnableNewProfileManagement);
174 DCHECK(!command_line->HasSwitch(switches::kDisableNewProfileManagement));
177 void EnableAccountConsistencyForTesting(base::CommandLine* command_line) {
178 command_line->AppendSwitch(switches::kEnableAccountConsistency);
179 DCHECK(!command_line->HasSwitch(switches::kDisableAccountConsistency));
182 } // namespace switches