Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / extensions / extension_message_bubble_factory.cc
blobf079253088747dac81796a9dc7021a2ac5aa9947
1 // Copyright 2015 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 "chrome/browser/ui/extensions/extension_message_bubble_factory.h"
7 #include "base/command_line.h"
8 #include "base/lazy_instance.h"
9 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
11 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
12 #include "chrome/browser/extensions/install_verifier.h"
13 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h"
14 #include "chrome/browser/extensions/settings_api_bubble_controller.h"
15 #include "chrome/browser/extensions/settings_api_helpers.h"
16 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_version_info.h"
20 #include "extensions/common/feature_switch.h"
22 namespace {
24 // A map of all profiles evaluated, so we can tell if it's the initial check.
25 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps
26 // that are in the different bubble controllers.
27 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated =
28 LAZY_INSTANCE_INITIALIZER;
30 // This is used to turn on all bubbles for testing.
31 bool g_enabled_for_tests = false;
33 const char kEnableDevModeWarningExperimentName[] =
34 "ExtensionDeveloperModeWarning";
36 const char kEnableProxyWarningExperimentName[] = "ExtensionProxyWarning";
38 bool IsExperimentEnabled(const char* experiment_name) {
39 // Don't allow turning it off via command line.
40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
41 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
42 std::string forced_trials =
43 command_line->GetSwitchValueASCII(switches::kForceFieldTrials);
44 if (forced_trials.find(experiment_name))
45 return true;
47 return base::FieldTrialList::FindFullName(experiment_name) == "Enabled";
50 bool EnableSuspiciousExtensionsBubble() {
51 return g_enabled_for_tests || extensions::InstallVerifier::ShouldEnforce();
54 bool EnableSettingsApiBubble() {
55 #if defined(OS_WIN)
56 return true;
57 #else
58 return g_enabled_for_tests;
59 #endif
62 bool EnableProxyOverrideBubble() {
63 #if defined(OS_WIN)
64 return true;
65 #else
66 return g_enabled_for_tests ||
67 IsExperimentEnabled(kEnableProxyWarningExperimentName);
68 #endif
71 bool EnableDevModeBubble() {
72 if (extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled())
73 return true;
75 #if defined(OS_WIN)
76 if (chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA)
77 return true;
78 #endif
80 return g_enabled_for_tests ||
81 IsExperimentEnabled(kEnableDevModeWarningExperimentName);
84 } // namespace
86 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile)
87 : profile_(profile) {
90 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() {
93 scoped_ptr<extensions::ExtensionMessageBubbleController>
94 ExtensionMessageBubbleFactory::GetController() {
95 Profile* original_profile = profile_->GetOriginalProfile();
96 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get();
97 bool is_initial_check = profiles_evaluated.count(original_profile) == 0;
98 profiles_evaluated.insert(original_profile);
100 // The list of suspicious extensions takes priority over the dev mode bubble
101 // and the settings API bubble, since that needs to be shown as soon as we
102 // disable something. The settings API bubble is shown on first startup after
103 // an extension has changed the startup pages and it is acceptable if that
104 // waits until the next startup because of the suspicious extension bubble.
105 // The dev mode bubble is not time sensitive like the other two so we'll catch
106 // the dev mode extensions on the next startup/next window that opens. That
107 // way, we're not too spammy with the bubbles.
108 if (EnableSuspiciousExtensionsBubble()) {
109 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller(
110 new extensions::SuspiciousExtensionBubbleController(profile_));
111 if (controller->ShouldShow())
112 return controller.Pass();
115 if (EnableSettingsApiBubble()) {
116 // No use showing this if it's not the startup of the profile.
117 if (is_initial_check) {
118 scoped_ptr<extensions::SettingsApiBubbleController> controller(
119 new extensions::SettingsApiBubbleController(
120 profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES));
121 if (controller->ShouldShow())
122 return controller.Pass();
126 if (EnableProxyOverrideBubble()) {
127 // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the
128 // proxy bubble controller.
129 const extensions::Extension* extension =
130 extensions::GetExtensionOverridingProxy(profile_);
131 if (extension) {
132 scoped_ptr<extensions::ProxyOverriddenBubbleController> controller(
133 new extensions::ProxyOverriddenBubbleController(profile_));
134 if (controller->ShouldShow(extension->id()))
135 return controller.Pass();
139 if (EnableDevModeBubble()) {
140 scoped_ptr<extensions::DevModeBubbleController> controller(
141 new extensions::DevModeBubbleController(profile_));
142 if (controller->ShouldShow())
143 return controller.Pass();
146 return scoped_ptr<extensions::ExtensionMessageBubbleController>();
149 // static
150 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) {
151 g_enabled_for_tests = enabled;