Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / extensions / dev_mode_bubble_controller.cc
blob854dcf77b638e2ef80af5831b28fc10ca2badcac
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
7 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_toolbar_model.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_version_info.h"
16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/feature_switch.h"
21 #include "grit/components_strings.h"
22 #include "ui/base/l10n/l10n_util.h"
24 namespace extensions {
26 namespace {
28 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 LAZY_INSTANCE_INITIALIZER;
31 ////////////////////////////////////////////////////////////////////////////////
32 // DevModeBubbleDelegate
34 class DevModeBubbleDelegate
35 : public ExtensionMessageBubbleController::Delegate {
36 public:
37 explicit DevModeBubbleDelegate(Profile* profile);
38 virtual ~DevModeBubbleDelegate();
40 // ExtensionMessageBubbleController::Delegate methods.
41 virtual bool ShouldIncludeExtension(const std::string& extension_id) override;
42 virtual void AcknowledgeExtension(
43 const std::string& extension_id,
44 ExtensionMessageBubbleController::BubbleAction user_action) override;
45 virtual void PerformAction(const ExtensionIdList& list) override;
46 virtual void OnClose() override;
47 virtual base::string16 GetTitle() const override;
48 virtual base::string16 GetMessageBody(
49 bool anchored_to_browser_action) const override;
50 virtual base::string16 GetOverflowText(
51 const base::string16& overflow_count) const override;
52 virtual GURL GetLearnMoreUrl() const override;
53 virtual base::string16 GetActionButtonLabel() const override;
54 virtual base::string16 GetDismissButtonLabel() const override;
55 virtual bool ShouldShowExtensionList() const override;
56 virtual void LogExtensionCount(size_t count) override;
57 virtual void LogAction(
58 ExtensionMessageBubbleController::BubbleAction action) override;
60 private:
61 // Our extension service. Weak, not owned by us.
62 ExtensionService* service_;
64 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
67 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
68 : ExtensionMessageBubbleController::Delegate(profile),
69 service_(ExtensionSystem::Get(profile)->extension_service()) {
72 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
75 bool DevModeBubbleDelegate::ShouldIncludeExtension(
76 const std::string& extension_id) {
77 const Extension* extension = service_->GetExtensionById(extension_id, false);
78 if (!extension)
79 return false;
80 return DevModeBubbleController::IsDevModeExtension(extension);
83 void DevModeBubbleDelegate::AcknowledgeExtension(
84 const std::string& extension_id,
85 ExtensionMessageBubbleController::BubbleAction user_action) {
88 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
89 for (size_t i = 0; i < list.size(); ++i)
90 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
93 void DevModeBubbleDelegate::OnClose() {
94 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(profile());
95 if (toolbar_model)
96 toolbar_model->StopHighlighting();
99 base::string16 DevModeBubbleDelegate::GetTitle() const {
100 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
103 base::string16 DevModeBubbleDelegate::GetMessageBody(
104 bool anchored_to_browser_action) const {
105 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
108 base::string16 DevModeBubbleDelegate::GetOverflowText(
109 const base::string16& overflow_count) const {
110 return l10n_util::GetStringFUTF16(
111 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
112 overflow_count);
115 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
116 return GURL(chrome::kChromeUIExtensionsURL);
119 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
120 return l10n_util::GetStringUTF16(IDS_DISABLE);
123 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
124 return l10n_util::GetStringUTF16(IDS_CANCEL);
127 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
128 return false;
131 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
132 UMA_HISTOGRAM_COUNTS_100(
133 "ExtensionBubble.ExtensionsInDevModeCount", count);
136 void DevModeBubbleDelegate::LogAction(
137 ExtensionMessageBubbleController::BubbleAction action) {
138 UMA_HISTOGRAM_ENUMERATION(
139 "ExtensionBubble.DevModeUserSelection",
140 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
143 } // namespace
145 ////////////////////////////////////////////////////////////////////////////////
146 // DevModeBubbleController
148 // static
149 void DevModeBubbleController::ClearProfileListForTesting() {
150 g_shown_for_profiles.Get().clear();
153 // static
154 bool DevModeBubbleController::IsDevModeExtension(
155 const Extension* extension) {
156 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
157 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA)
158 return false;
160 return extension->location() == Manifest::UNPACKED ||
161 extension->location() == Manifest::COMMAND_LINE;
164 DevModeBubbleController::DevModeBubbleController(Profile* profile)
165 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
166 profile),
167 profile_(profile) {}
169 DevModeBubbleController::~DevModeBubbleController() {
172 bool DevModeBubbleController::ShouldShow() {
173 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
174 !GetExtensionList().empty();
177 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
178 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
179 ExtensionMessageBubbleController::Show(bubble);
182 } // namespace extensions