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

Side by Side Diff: chrome/browser/extensions/dev_mode_bubble_controller.cc

Issue 1125353002: Make extensions developer mode warning controllable by experiments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/dev_mode_bubble_controller.h" 5 #include "chrome/browser/extensions/dev_mode_bubble_controller.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 "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
9 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h" 12 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_toolbar_model.h" 14 #include "chrome/browser/extensions/extension_toolbar_model.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/chrome_version_info.h"
16 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
18 #include "extensions/browser/extension_prefs.h" 21 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/feature_switch.h" 23 #include "extensions/common/feature_switch.h"
21 #include "grit/components_strings.h" 24 #include "grit/components_strings.h"
22 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
23 26
24 namespace extensions { 27 namespace extensions {
25 28
26 namespace { 29 namespace {
27 30
28 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = 31 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 LAZY_INSTANCE_INITIALIZER; 32 LAZY_INSTANCE_INITIALIZER;
30 33
34 const char kEnableDevModeWarningExperimentName[] =
35 "ExtensionDeveloperModeWarning";
36
37 bool ShouldEnableBubble() {
38 if (FeatureSwitch::force_dev_mode_highlighting()->IsEnabled())
39 return true;
40
41 // Don't allow turning it off via command line.
42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
44 std::string forced_trials =
45 command_line->GetSwitchValueASCII(switches::kForceFieldTrials);
46 if (forced_trials.find(kEnableDevModeWarningExperimentName))
47 return true;
48 }
49
50 const std::string group = base::FieldTrialList::FindFullName(
51 kEnableDevModeWarningExperimentName);
52 return group == "Enabled";
53 }
54
31 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
32 // DevModeBubbleDelegate 56 // DevModeBubbleDelegate
33 57
34 class DevModeBubbleDelegate 58 class DevModeBubbleDelegate
35 : public ExtensionMessageBubbleController::Delegate { 59 : public ExtensionMessageBubbleController::Delegate {
36 public: 60 public:
37 explicit DevModeBubbleDelegate(Profile* profile); 61 explicit DevModeBubbleDelegate(Profile* profile);
38 ~DevModeBubbleDelegate() override; 62 ~DevModeBubbleDelegate() override;
39 63
40 // ExtensionMessageBubbleController::Delegate methods. 64 // ExtensionMessageBubbleController::Delegate methods.
(...skipping 29 matching lines...) Expand all
70 } 94 }
71 95
72 DevModeBubbleDelegate::~DevModeBubbleDelegate() { 96 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
73 } 97 }
74 98
75 bool DevModeBubbleDelegate::ShouldIncludeExtension( 99 bool DevModeBubbleDelegate::ShouldIncludeExtension(
76 const std::string& extension_id) { 100 const std::string& extension_id) {
77 const Extension* extension = service_->GetExtensionById(extension_id, false); 101 const Extension* extension = service_->GetExtensionById(extension_id, false);
78 if (!extension) 102 if (!extension)
79 return false; 103 return false;
80 return DevModeBubbleController::IsDevModeExtension(extension); 104 return (extension->location() == Manifest::UNPACKED ||
105 extension->location() == Manifest::COMMAND_LINE);
81 } 106 }
82 107
83 void DevModeBubbleDelegate::AcknowledgeExtension( 108 void DevModeBubbleDelegate::AcknowledgeExtension(
84 const std::string& extension_id, 109 const std::string& extension_id,
85 ExtensionMessageBubbleController::BubbleAction user_action) { 110 ExtensionMessageBubbleController::BubbleAction user_action) {
86 } 111 }
87 112
88 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { 113 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
89 for (size_t i = 0; i < list.size(); ++i) 114 for (size_t i = 0; i < list.size(); ++i)
90 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); 115 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } // namespace 172 } // namespace
148 173
149 //////////////////////////////////////////////////////////////////////////////// 174 ////////////////////////////////////////////////////////////////////////////////
150 // DevModeBubbleController 175 // DevModeBubbleController
151 176
152 // static 177 // static
153 void DevModeBubbleController::ClearProfileListForTesting() { 178 void DevModeBubbleController::ClearProfileListForTesting() {
154 g_shown_for_profiles.Get().clear(); 179 g_shown_for_profiles.Get().clear();
155 } 180 }
156 181
157 // static
158 bool DevModeBubbleController::IsDevModeExtension(
159 const Extension* extension) {
160 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
161 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA)
162 return false;
163 }
164 return extension->location() == Manifest::UNPACKED ||
165 extension->location() == Manifest::COMMAND_LINE;
166 }
167
168 DevModeBubbleController::DevModeBubbleController(Profile* profile) 182 DevModeBubbleController::DevModeBubbleController(Profile* profile)
169 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), 183 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
170 profile), 184 profile),
171 profile_(profile) {} 185 profile_(profile) {}
172 186
173 DevModeBubbleController::~DevModeBubbleController() { 187 DevModeBubbleController::~DevModeBubbleController() {
174 } 188 }
175 189
176 bool DevModeBubbleController::ShouldShow() { 190 bool DevModeBubbleController::ShouldShow() {
191 if (!ShouldEnableBubble())
192 return false;
193
177 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && 194 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
178 !GetExtensionList().empty(); 195 !GetExtensionList().empty();
179 } 196 }
180 197
181 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { 198 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
182 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); 199 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
183 ExtensionMessageBubbleController::Show(bubble); 200 ExtensionMessageBubbleController::Show(bubble);
184 } 201 }
185 202
186 } // namespace extensions 203 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698