Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/ui/extensions/extension_message_bubble_factory.cc

Issue 1125353002: Make extensions developer mode warning controllable by experiments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win compile problem with unreached code Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/install_verifier.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/field_trial.h"
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" 11 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
12 #include "chrome/browser/extensions/install_verifier.h"
10 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" 13 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h"
11 #include "chrome/browser/extensions/settings_api_bubble_controller.h" 14 #include "chrome/browser/extensions/settings_api_bubble_controller.h"
12 #include "chrome/browser/extensions/settings_api_helpers.h" 15 #include "chrome/browser/extensions/settings_api_helpers.h"
13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" 16 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
14 #include "chrome/browser/profiles/profile.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"
15 21
16 namespace { 22 namespace {
17 23
18 // A map of all profiles evaluated, so we can tell if it's the initial check. 24 // A map of all profiles evaluated, so we can tell if it's the initial check.
19 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps 25 // TODO(devlin): It would be nice to coalesce all the "profiles evaluated" maps
20 // that are in the different bubble controllers. 26 // that are in the different bubble controllers.
21 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated = 27 base::LazyInstance<std::set<Profile*> > g_profiles_evaluated =
22 LAZY_INSTANCE_INITIALIZER; 28 LAZY_INSTANCE_INITIALIZER;
23 29
24 // Currently, we only show these bubbles on windows platforms. This can be 30 // This is used to turn on all bubbles for testing.
25 // overridden for testing purposes. 31 bool g_enabled_for_tests = false;
32
33 const char kEnableDevModeWarningExperimentName[] =
34 "ExtensionDeveloperModeWarning";
35
36 const char kEnableProxyWarningExperimentName[] = "ExtensionProxyWarning";
37
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;
46 }
47 return base::FieldTrialList::FindFullName(experiment_name) == "Enabled";
48 }
49
50 bool EnableSuspiciousExtensionsBubble() {
51 return g_enabled_for_tests || extensions::InstallVerifier::ShouldEnforce();
52 }
53
54 bool EnableSettingsApiBubble() {
26 #if defined(OS_WIN) 55 #if defined(OS_WIN)
27 bool g_enabled = true; 56 return true;
28 #else 57 #else
29 bool g_enabled = false; 58 return g_enabled_for_tests;
30 #endif 59 #endif
60 }
61
62 bool EnableProxyOverrideBubble() {
63 #if defined(OS_WIN)
64 return true;
65 #else
66 return g_enabled_for_tests ||
67 IsExperimentEnabled(kEnableProxyWarningExperimentName);
68 #endif
69 }
70
71 bool EnableDevModeBubble() {
72 if (extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled())
73 return true;
74
75 #if defined(OS_WIN)
76 if (chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA)
77 return true;
78 #endif
79
80 return g_enabled_for_tests ||
81 IsExperimentEnabled(kEnableDevModeWarningExperimentName);
82 }
31 83
32 } // namespace 84 } // namespace
33 85
34 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile) 86 ExtensionMessageBubbleFactory::ExtensionMessageBubbleFactory(Profile* profile)
35 : profile_(profile) { 87 : profile_(profile) {
36 } 88 }
37 89
38 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() { 90 ExtensionMessageBubbleFactory::~ExtensionMessageBubbleFactory() {
39 } 91 }
40 92
41 scoped_ptr<extensions::ExtensionMessageBubbleController> 93 scoped_ptr<extensions::ExtensionMessageBubbleController>
42 ExtensionMessageBubbleFactory::GetController() { 94 ExtensionMessageBubbleFactory::GetController() {
43 if (!g_enabled)
44 return scoped_ptr<extensions::ExtensionMessageBubbleController>();
45
46 Profile* original_profile = profile_->GetOriginalProfile(); 95 Profile* original_profile = profile_->GetOriginalProfile();
47 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get(); 96 std::set<Profile*>& profiles_evaluated = g_profiles_evaluated.Get();
48 bool is_initial_check = profiles_evaluated.count(original_profile) == 0; 97 bool is_initial_check = profiles_evaluated.count(original_profile) == 0;
49 profiles_evaluated.insert(original_profile); 98 profiles_evaluated.insert(original_profile);
50 99
51 // The list of suspicious extensions takes priority over the dev mode bubble 100 // The list of suspicious extensions takes priority over the dev mode bubble
52 // and the settings API bubble, since that needs to be shown as soon as we 101 // and the settings API bubble, since that needs to be shown as soon as we
53 // disable something. The settings API bubble is shown on first startup after 102 // disable something. The settings API bubble is shown on first startup after
54 // an extension has changed the startup pages and it is acceptable if that 103 // an extension has changed the startup pages and it is acceptable if that
55 // waits until the next startup because of the suspicious extension bubble. 104 // waits until the next startup because of the suspicious extension bubble.
56 // The dev mode bubble is not time sensitive like the other two so we'll catch 105 // The dev mode bubble is not time sensitive like the other two so we'll catch
57 // the dev mode extensions on the next startup/next window that opens. That 106 // the dev mode extensions on the next startup/next window that opens. That
58 // way, we're not too spammy with the bubbles. 107 // way, we're not too spammy with the bubbles.
59 { 108 if (EnableSuspiciousExtensionsBubble()) {
60 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller( 109 scoped_ptr<extensions::SuspiciousExtensionBubbleController> controller(
61 new extensions::SuspiciousExtensionBubbleController(profile_)); 110 new extensions::SuspiciousExtensionBubbleController(profile_));
62 if (controller->ShouldShow()) 111 if (controller->ShouldShow())
63 return controller.Pass(); 112 return controller.Pass();
64 } 113 }
65 114
66 { 115 if (EnableSettingsApiBubble()) {
67 // No use showing this if it's not the startup of the profile. 116 // No use showing this if it's not the startup of the profile.
68 if (is_initial_check) { 117 if (is_initial_check) {
69 scoped_ptr<extensions::SettingsApiBubbleController> controller( 118 scoped_ptr<extensions::SettingsApiBubbleController> controller(
70 new extensions::SettingsApiBubbleController( 119 new extensions::SettingsApiBubbleController(
71 profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES)); 120 profile_, extensions::BUBBLE_TYPE_STARTUP_PAGES));
72 if (controller->ShouldShow()) 121 if (controller->ShouldShow())
73 return controller.Pass(); 122 return controller.Pass();
74 } 123 }
75 } 124 }
76 125
77 { 126 if (EnableProxyOverrideBubble()) {
78 // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the 127 // TODO(devlin): Move the "GetExtensionOverridingProxy" part into the
79 // proxy bubble controller. 128 // proxy bubble controller.
80 const extensions::Extension* extension = 129 const extensions::Extension* extension =
81 extensions::GetExtensionOverridingProxy(profile_); 130 extensions::GetExtensionOverridingProxy(profile_);
82 if (extension) { 131 if (extension) {
83 scoped_ptr<extensions::ProxyOverriddenBubbleController> controller( 132 scoped_ptr<extensions::ProxyOverriddenBubbleController> controller(
84 new extensions::ProxyOverriddenBubbleController(profile_)); 133 new extensions::ProxyOverriddenBubbleController(profile_));
85 if (controller->ShouldShow(extension->id())) 134 if (controller->ShouldShow(extension->id()))
86 return controller.Pass(); 135 return controller.Pass();
87 } 136 }
88 } 137 }
89 138
90 { 139 if (EnableDevModeBubble()) {
91 scoped_ptr<extensions::DevModeBubbleController> controller( 140 scoped_ptr<extensions::DevModeBubbleController> controller(
92 new extensions::DevModeBubbleController(profile_)); 141 new extensions::DevModeBubbleController(profile_));
93 if (controller->ShouldShow()) 142 if (controller->ShouldShow())
94 return controller.Pass(); 143 return controller.Pass();
95 } 144 }
96 145
97 return scoped_ptr<extensions::ExtensionMessageBubbleController>(); 146 return scoped_ptr<extensions::ExtensionMessageBubbleController>();
98 } 147 }
99 148
100 // static 149 // static
101 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) { 150 void ExtensionMessageBubbleFactory::set_enabled_for_tests(bool enabled) {
102 g_enabled = enabled; 151 g_enabled_for_tests = enabled;
103 } 152 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/install_verifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698