Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / dev_mode_bubble_controller.cc
blob7f4a3e79fe951b20da318d9ec8023e40f20adc4e
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/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/browser/extension_system.h"
18 #include "grit/components_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
21 namespace extensions {
23 namespace {
25 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
26 LAZY_INSTANCE_INITIALIZER;
28 ////////////////////////////////////////////////////////////////////////////////
29 // DevModeBubbleDelegate
31 class DevModeBubbleDelegate
32 : public ExtensionMessageBubbleController::Delegate {
33 public:
34 explicit DevModeBubbleDelegate(Profile* profile);
35 ~DevModeBubbleDelegate() override;
37 // ExtensionMessageBubbleController::Delegate methods.
38 bool ShouldIncludeExtension(const std::string& extension_id) override;
39 void AcknowledgeExtension(
40 const std::string& extension_id,
41 ExtensionMessageBubbleController::BubbleAction user_action) override;
42 void PerformAction(const ExtensionIdList& list) override;
43 base::string16 GetTitle() const override;
44 base::string16 GetMessageBody(bool anchored_to_browser_action,
45 int extension_count) const override;
46 base::string16 GetOverflowText(
47 const base::string16& overflow_count) const override;
48 GURL GetLearnMoreUrl() const override;
49 base::string16 GetActionButtonLabel() const override;
50 base::string16 GetDismissButtonLabel() const override;
51 bool ShouldShowExtensionList() const override;
52 bool ShouldHighlightExtensions() const override;
53 void LogExtensionCount(size_t count) override;
54 void LogAction(
55 ExtensionMessageBubbleController::BubbleAction action) override;
57 private:
58 // Our extension service. Weak, not owned by us.
59 ExtensionService* service_;
61 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
64 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
65 : ExtensionMessageBubbleController::Delegate(profile),
66 service_(ExtensionSystem::Get(profile)->extension_service()) {
69 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
72 bool DevModeBubbleDelegate::ShouldIncludeExtension(
73 const std::string& extension_id) {
74 const Extension* extension = service_->GetExtensionById(extension_id, false);
75 if (!extension)
76 return false;
77 return (extension->location() == Manifest::UNPACKED ||
78 extension->location() == Manifest::COMMAND_LINE);
81 void DevModeBubbleDelegate::AcknowledgeExtension(
82 const std::string& extension_id,
83 ExtensionMessageBubbleController::BubbleAction user_action) {
86 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
87 for (size_t i = 0; i < list.size(); ++i)
88 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
91 base::string16 DevModeBubbleDelegate::GetTitle() const {
92 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
95 base::string16 DevModeBubbleDelegate::GetMessageBody(
96 bool anchored_to_browser_action,
97 int extension_count) const {
98 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
101 base::string16 DevModeBubbleDelegate::GetOverflowText(
102 const base::string16& overflow_count) const {
103 return l10n_util::GetStringFUTF16(
104 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
105 overflow_count);
108 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
109 return GURL(chrome::kChromeUIExtensionsURL);
112 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
113 return l10n_util::GetStringUTF16(IDS_DISABLE);
116 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
117 return l10n_util::GetStringUTF16(IDS_CANCEL);
120 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
121 return false;
124 bool DevModeBubbleDelegate::ShouldHighlightExtensions() const {
125 return true;
128 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
129 UMA_HISTOGRAM_COUNTS_100(
130 "ExtensionBubble.ExtensionsInDevModeCount", count);
133 void DevModeBubbleDelegate::LogAction(
134 ExtensionMessageBubbleController::BubbleAction action) {
135 UMA_HISTOGRAM_ENUMERATION(
136 "ExtensionBubble.DevModeUserSelection",
137 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
140 } // namespace
142 ////////////////////////////////////////////////////////////////////////////////
143 // DevModeBubbleController
145 // static
146 void DevModeBubbleController::ClearProfileListForTesting() {
147 g_shown_for_profiles.Get().clear();
150 DevModeBubbleController::DevModeBubbleController(Profile* profile)
151 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
152 profile),
153 profile_(profile) {}
155 DevModeBubbleController::~DevModeBubbleController() {
158 bool DevModeBubbleController::ShouldShow() {
159 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
160 !GetExtensionList().empty();
163 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
164 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
165 ExtensionMessageBubbleController::Show(bubble);
168 } // namespace extensions