Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / ntp_overridden_bubble_controller.cc
blob183f0dc6c61fab4a3d16eef52248ca9e715b37fb
1 // Copyright (c) 2014 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/ntp_overridden_bubble_controller.h"
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/url_constants.h"
11 #include "extensions/browser/extension_registry.h"
12 #include "extensions/browser/extension_system.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
16 using extensions::ExtensionMessageBubbleController;
17 using extensions::NtpOverriddenBubbleController;
19 namespace {
21 ////////////////////////////////////////////////////////////////////////////////
22 // NtpOverriddenBubbleDelegate
24 class NtpOverriddenBubbleDelegate
25 : public extensions::ExtensionMessageBubbleController::Delegate {
26 public:
27 NtpOverriddenBubbleDelegate(ExtensionService* service, Profile* profile);
28 virtual ~NtpOverriddenBubbleDelegate();
30 // ExtensionMessageBubbleController::Delegate methods.
31 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE;
32 virtual void AcknowledgeExtension(
33 const std::string& extension_id,
34 extensions::ExtensionMessageBubbleController::BubbleAction
35 user_action) OVERRIDE;
36 virtual void PerformAction(const extensions::ExtensionIdList& list) OVERRIDE;
37 virtual base::string16 GetTitle() const OVERRIDE;
38 virtual base::string16 GetMessageBody() const OVERRIDE;
39 virtual base::string16 GetOverflowText(
40 const base::string16& overflow_count) const OVERRIDE;
41 virtual base::string16 GetLearnMoreLabel() const OVERRIDE;
42 virtual GURL GetLearnMoreUrl() const OVERRIDE;
43 virtual base::string16 GetActionButtonLabel() const OVERRIDE;
44 virtual base::string16 GetDismissButtonLabel() const OVERRIDE;
45 virtual bool ShouldShowExtensionList() const OVERRIDE;
46 virtual void RestrictToSingleExtension(
47 const std::string& extension_id) OVERRIDE;
48 virtual void LogExtensionCount(size_t count) OVERRIDE;
49 virtual void LogAction(
50 extensions::ExtensionMessageBubbleController::BubbleAction
51 action) OVERRIDE;
53 private:
54 // Our extension service. Weak, not owned by us.
55 ExtensionService* service_;
57 // A weak pointer to the profile we are associated with. Not owned by us.
58 Profile* profile_;
60 // The ID of the extension we are showing the bubble for.
61 std::string extension_id_;
63 DISALLOW_COPY_AND_ASSIGN(NtpOverriddenBubbleDelegate);
66 NtpOverriddenBubbleDelegate::NtpOverriddenBubbleDelegate(
67 ExtensionService* service,
68 Profile* profile)
69 : service_(service), profile_(profile) {}
71 NtpOverriddenBubbleDelegate::~NtpOverriddenBubbleDelegate() {}
73 bool NtpOverriddenBubbleDelegate::ShouldIncludeExtension(
74 const std::string& extension_id) {
75 if (!extension_id_.empty() && extension_id_ != extension_id)
76 return false;
78 using extensions::ExtensionRegistry;
79 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
80 const extensions::Extension* extension =
81 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
82 if (!extension)
83 return false; // The extension provided is no longer enabled.
85 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
86 if (prefs->HasNtpOverriddenBubbleBeenAcknowledged(extension_id))
87 return false;
89 return true;
92 void NtpOverriddenBubbleDelegate::AcknowledgeExtension(
93 const std::string& extension_id,
94 ExtensionMessageBubbleController::BubbleAction user_action) {
95 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) {
96 extensions::ExtensionPrefs* prefs =
97 extensions::ExtensionPrefs::Get(profile_);
98 prefs->SetNtpOverriddenBubbleBeenAcknowledged(extension_id, true);
102 void NtpOverriddenBubbleDelegate::PerformAction(
103 const extensions::ExtensionIdList& list) {
104 for (size_t i = 0; i < list.size(); ++i) {
105 service_->DisableExtension(list[i],
106 extensions::Extension::DISABLE_USER_ACTION);
110 base::string16 NtpOverriddenBubbleDelegate::GetTitle() const {
111 return l10n_util::GetStringUTF16(
112 IDS_EXTENSIONS_NTP_CONTROLLED_TITLE_HOME_PAGE_BUBBLE);
115 base::string16 NtpOverriddenBubbleDelegate::GetMessageBody() const {
116 base::string16 body =
117 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NTP_CONTROLLED_FIRST_LINE);
118 body += l10n_util::GetStringUTF16(
119 IDS_EXTENSIONS_SETTINGS_API_THIRD_LINE_CONFIRMATION);
120 return body;
123 base::string16 NtpOverriddenBubbleDelegate::GetOverflowText(
124 const base::string16& overflow_count) const {
125 // Does not have more than one extension in the list at a time.
126 NOTREACHED();
127 return base::string16();
130 base::string16 NtpOverriddenBubbleDelegate::GetLearnMoreLabel() const {
131 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
134 GURL NtpOverriddenBubbleDelegate::GetLearnMoreUrl() const {
135 // TODO(finnur): Rename the const when things settle down (since it is used in
136 // more places than for the Settings API bubble now).
137 return GURL(chrome::kSettingsApiLearnMoreURL);
140 base::string16 NtpOverriddenBubbleDelegate::GetActionButtonLabel() const {
141 // TODO(finnur): Rename the const when things settle down (since it is used in
142 // more places than for the Settings API bubble now).
143 return l10n_util::GetStringUTF16(
144 IDS_EXTENSIONS_SETTINGS_API_RESTORE_SETTINGS);
147 base::string16 NtpOverriddenBubbleDelegate::GetDismissButtonLabel() const {
148 // TODO(finnur): Rename the const when things settle down (since it is used in
149 // more places than for the Settings API bubble now).
150 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SETTINGS_API_KEEP_CHANGES);
153 bool NtpOverriddenBubbleDelegate::ShouldShowExtensionList() const {
154 return false;
157 void NtpOverriddenBubbleDelegate::RestrictToSingleExtension(
158 const std::string& extension_id) {
159 extension_id_ = extension_id;
162 void NtpOverriddenBubbleDelegate::LogExtensionCount(size_t count) {
163 UMA_HISTOGRAM_COUNTS_100("NtpOverriddenBubble.ExtensionCount", count);
166 void NtpOverriddenBubbleDelegate::LogAction(
167 ExtensionMessageBubbleController::BubbleAction action) {
168 UMA_HISTOGRAM_ENUMERATION("NtpOverriddenBubble.UserSelection",
169 action,
170 ExtensionMessageBubbleController::ACTION_BOUNDARY);
173 } // namespace
175 namespace extensions {
177 ////////////////////////////////////////////////////////////////////////////////
178 // NtpOverriddenBubbleController
180 NtpOverriddenBubbleController::NtpOverriddenBubbleController(Profile* profile)
181 : ExtensionMessageBubbleController(
182 new NtpOverriddenBubbleDelegate(
183 ExtensionSystem::Get(profile)->extension_service(),
184 profile),
185 profile),
186 profile_(profile) {}
188 NtpOverriddenBubbleController::~NtpOverriddenBubbleController() {}
190 bool NtpOverriddenBubbleController::ShouldShow(
191 const std::string& extension_id) {
192 if (!delegate()->ShouldIncludeExtension(extension_id))
193 return false;
195 delegate()->RestrictToSingleExtension(extension_id);
196 return true;
199 bool NtpOverriddenBubbleController::CloseOnDeactivate() {
200 return true;
203 } // namespace extensions