OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 5 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "extensions/common/feature_switch.h" | 22 #include "extensions/common/feature_switch.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // A map of all profiles evaluated, so we can tell if it's the initial check. | 26 // A map of all profiles evaluated, so we can tell if it's the initial check. |
27 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps | 27 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps |
28 // that are in the different bubble controllers. | 28 // that are in the different bubble controllers. |
29 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated = | 29 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated = |
30 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
31 | 31 |
32 // This is used to turn on all bubbles for testing. | 32 // This is used to turn on override whether bubbles are enabled or disabled for |
33 bool g_enabled_for_tests = false; | 33 // testing. |
| 34 ExtensionMessageBubbleFactory::OverrideForTesting g_override_for_testing = |
| 35 ExtensionMessageBubbleFactory::NO_OVERRIDE; |
34 | 36 |
35 const char kEnableDevModeWarningExperimentName[] = | 37 const char kEnableDevModeWarningExperimentName[] = |
36 "ExtensionDeveloperModeWarning"; | 38 "ExtensionDeveloperModeWarning"; |
37 | 39 |
38 #if !defined(OS_WIN) | 40 #if !defined(OS_WIN) |
39 const char kEnableProxyWarningExperimentName[] = "ExtensionProxyWarning"; | 41 const char kEnableProxyWarningExperimentName[] = "ExtensionProxyWarning"; |
40 #endif | 42 #endif |
41 | 43 |
42 bool IsExperimentEnabled(const char* experiment_name) { | 44 bool IsExperimentEnabled(const char* experiment_name) { |
43 // Don't allow turning it off via command line. | 45 // Don't allow turning it off via command line. |
44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 46 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
45 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 47 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
46 std::string forced_trials = | 48 std::string forced_trials = |
47 command_line->GetSwitchValueASCII(switches::kForceFieldTrials); | 49 command_line->GetSwitchValueASCII(switches::kForceFieldTrials); |
48 if (forced_trials.find(experiment_name)) | 50 if (forced_trials.find(experiment_name)) |
49 return true; | 51 return true; |
50 } | 52 } |
51 return base::FieldTrialList::FindFullName(experiment_name) == "Enabled"; | 53 return base::FieldTrialList::FindFullName(experiment_name) == "Enabled"; |
52 } | 54 } |
53 | 55 |
54 bool EnableSuspiciousExtensionsBubble() { | 56 bool EnableSuspiciousExtensionsBubble() { |
55 return g_enabled_for_tests || extensions::InstallVerifier::ShouldEnforce(); | 57 return g_override_for_testing == |
| 58 ExtensionMessageBubbleFactory::OVERRIDE_ENABLED || |
| 59 extensions::InstallVerifier::ShouldEnforce(); |
56 } | 60 } |
57 | 61 |
58 bool EnableSettingsApiBubble() { | 62 bool EnableSettingsApiBubble() { |
59 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
60 return true; | 64 return true; |
61 #else | 65 #else |
62 return g_enabled_for_tests; | 66 return g_override_for_testing == |
| 67 ExtensionMessageBubbleFactory::OVERRIDE_ENABLED; |
63 #endif | 68 #endif |
64 } | 69 } |
65 | 70 |
66 bool EnableProxyOverrideBubble() { | 71 bool EnableProxyOverrideBubble() { |
67 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
68 return true; | 73 return true; |
69 #else | 74 #else |
70 return g_enabled_for_tests || | 75 return g_override_for_testing == |
| 76 ExtensionMessageBubbleFactory::OVERRIDE_ENABLED || |
71 IsExperimentEnabled(kEnableProxyWarningExperimentName); | 77 IsExperimentEnabled(kEnableProxyWarningExperimentName); |
72 #endif | 78 #endif |
73 } | 79 } |
74 | 80 |
75 bool EnableDevModeBubble() { | 81 bool EnableDevModeBubble() { |
76 if (extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) | 82 if (extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) |
77 return true; | 83 return true; |
78 | 84 |
79 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
80 if (chrome::GetChannel() >= version_info::Channel::BETA) | 86 if (chrome::GetChannel() >= version_info::Channel::BETA) |
81 return true; | 87 return true; |
82 #endif | 88 #endif |
83 | 89 |
84 return g_enabled_for_tests || | 90 return g_override_for_testing == |
| 91 ExtensionMessageBubbleFactory::OVERRIDE_ENABLED || |
85 IsExperimentEnabled(kEnableDevModeWarningExperimentName); | 92 IsExperimentEnabled(kEnableDevModeWarningExperimentName); |
86 } | 93 } |
87 | 94 |
88 } // namespace | 95 } // namespace |
89 | 96 |
90 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Browser* browser) | 97 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Browser* browser) |
91 : browser_(browser) { | 98 : browser_(browser) { |
92 } | 99 } |
93 | 100 |
94 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { | 101 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { |
95 } | 102 } |
96 | 103 |
97 scoped_ptr<extensions::ExtensionMessageBubbleController> | 104 scoped_ptr<extensions::ExtensionMessageBubbleController> |
98 ExtensionMessageBubbleFactory::GetController() { | 105 ExtensionMessageBubbleFactory::GetController() { |
99 Profile* original_profile = browser_->profile()->GetOriginalProfile(); | 106 Profile* original_profile = browser_->profile()->GetOriginalProfile(); |
100 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get(); | 107 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get(); |
101 bool is_initial_check = profiles_evaluated.count(original_profile) == 0; | 108 bool is_initial_check = profiles_evaluated.count(original_profile) == 0; |
102 profiles_evaluated.insert(original_profile); | 109 profiles_evaluated.insert(original_profile); |
103 | 110 |
| 111 if (g_override_for_testing == OVERRIDE_DISABLED) |
| 112 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); |
| 113 |
104 // The list of suspicious extensions takes priority over the dev mode bubble | 114 // The list of suspicious extensions takes priority over the dev mode bubble |
105 // and the settings API bubble, since that needs to be shown as soon as we | 115 // and the settings API bubble, since that needs to be shown as soon as we |
106 // disable something. The settings API bubble is shown on first startup after | 116 // disable something. The settings API bubble is shown on first startup after |
107 // an extension has changed the startup pages and it is acceptable if that | 117 // an extension has changed the startup pages and it is acceptable if that |
108 // waits until the next startup because of the suspicious extension bubble. | 118 // waits until the next startup because of the suspicious extension bubble. |
109 // The dev mode bubble is not time sensitive like the other two so we'll catch | 119 // The dev mode bubble is not time sensitive like the other two so we'll catch |
110 // the dev mode extensions on the next startup/next window that opens. That | 120 // the dev mode extensions on the next startup/next window that opens. That |
111 // way, we're not too spammy with the bubbles. | 121 // way, we're not too spammy with the bubbles. |
112 if (EnableSuspiciousExtensionsBubble()) { | 122 if (EnableSuspiciousExtensionsBubble()) { |
113 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller( | 123 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller( |
(...skipping 30 matching lines...) Expand all Loading... |
144 scoped_ptr<extensions::DevModeBubbleController> controller( | 154 scoped_ptr<extensions::DevModeBubbleController> controller( |
145 new extensions::DevModeBubbleController(browser_)); | 155 new extensions::DevModeBubbleController(browser_)); |
146 if (controller->ShouldShow()) | 156 if (controller->ShouldShow()) |
147 return controller.Pass(); | 157 return controller.Pass(); |
148 } | 158 } |
149 | 159 |
150 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); | 160 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); |
151 } | 161 } |
152 | 162 |
153 // static | 163 // static |
154 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) { | 164 void ExtensionMessageBubbleFactory::set_override_for_tests( |
155 g_enabled_for_tests = enabled; | 165 OverrideForTesting override) { |
| 166 g_override_for_testing = override; |
156 } | 167 } |
OLD | NEW |