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

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

Issue 134103002: Refactor the extension message bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile errors on non-Win platform Created 6 years, 11 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 | Annotate | Revision Log
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/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_message_bubble.h" 13 #include "chrome/browser/extensions/extension_message_bubble.h"
13 #include "chrome/browser/extensions/extension_prefs.h" 14 #include "chrome/browser/extensions/extension_prefs.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h" 17 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/user_metrics.h" 21 #include "content/public/browser/user_metrics.h"
21 #include "extensions/common/feature_switch.h" 22 #include "extensions/common/feature_switch.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 26
26 namespace { 27 namespace {
27 28
28 static base::LazyInstance<extensions::ProfileKeyedAPIFactory< 29 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 extensions::DevModeBubbleController> > 30 LAZY_INSTANCE_INITIALIZER;
30 g_factory = LAZY_INSTANCE_INITIALIZER;
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
37 // DevModeBubbleController 37 // DevModeBubbleDelegate
38
39 DevModeBubbleController::DevModeBubbleController(
40 Profile* profile)
41 : ExtensionMessageBubbleController(this, profile),
42 service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
43 profile_(profile) {
44 }
45
46 DevModeBubbleController::~DevModeBubbleController() {
47 }
48 38
49 // static 39 // static
50 ProfileKeyedAPIFactory<DevModeBubbleController>* 40 bool DevModeBubbleDelegate::IsDevModeExtension(const Extension* extension) {
51 DevModeBubbleController::GetFactoryInstance() {
52 return &g_factory.Get();
53 }
54
55 // static
56 DevModeBubbleController* DevModeBubbleController::Get(
57 Profile* profile) {
58 return ProfileKeyedAPIFactory<
59 DevModeBubbleController>::GetForProfile(profile);
60 }
61
62 bool DevModeBubbleController::IsDevModeExtension(
63 const Extension* extension) const {
64 if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { 41 if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
65 if (chrome::VersionInfo::GetChannel() < 42 if (chrome::VersionInfo::GetChannel() <
66 chrome::VersionInfo::CHANNEL_BETA) 43 chrome::VersionInfo::CHANNEL_BETA)
67 return false; 44 return false;
68 } 45 }
69 return extension->location() == Manifest::UNPACKED || 46 return extension->location() == Manifest::UNPACKED ||
70 extension->location() == Manifest::COMMAND_LINE; 47 extension->location() == Manifest::COMMAND_LINE;
71 } 48 }
72 49
73 bool DevModeBubbleController::ShouldIncludeExtension( 50 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
51 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()) {
not at google - send to devlin 2014/01/10 21:28:43 perhaps just pass in the ExtensionService directly
Finnur 2014/01/13 15:36:32 Done.
52 }
53
54 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
55 }
56
57 bool DevModeBubbleDelegate::ShouldIncludeExtension(
74 const std::string& extension_id) { 58 const std::string& extension_id) {
75 const Extension* extension = service_->GetExtensionById(extension_id, false); 59 const Extension* extension = service_->GetExtensionById(extension_id, false);
76 if (!extension) 60 if (!extension)
77 return false; 61 return false;
78 return IsDevModeExtension(extension); 62 return IsDevModeExtension(extension);
79 } 63 }
80 64
81 void DevModeBubbleController::AcknowledgeExtension( 65 void DevModeBubbleDelegate::AcknowledgeExtension(
82 const std::string& extension_id, 66 const std::string& extension_id,
83 ExtensionMessageBubbleController::BubbleAction user_action) { 67 ExtensionMessageBubbleController::BubbleAction user_action) {
84 } 68 }
85 69
86 void DevModeBubbleController::PerformAction( 70 void DevModeBubbleDelegate::PerformAction(
87 const ExtensionIdList& list) { 71 const ExtensionIdList& list) {
88 for (size_t i = 0; i < list.size(); ++i) 72 for (size_t i = 0; i < list.size(); ++i)
89 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); 73 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
90 } 74 }
91 75
92 base::string16 DevModeBubbleController::GetTitle() const { 76 base::string16 DevModeBubbleDelegate::GetTitle() const {
93 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); 77 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
94 } 78 }
95 79
96 base::string16 DevModeBubbleController::GetMessageBody() const { 80 base::string16 DevModeBubbleDelegate::GetMessageBody() const {
97 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); 81 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
98 } 82 }
99 83
100 base::string16 DevModeBubbleController::GetOverflowText( 84 base::string16 DevModeBubbleDelegate::GetOverflowText(
101 const base::string16& overflow_count) const { 85 const base::string16& overflow_count) const {
102 return l10n_util::GetStringFUTF16( 86 return l10n_util::GetStringFUTF16(
103 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, 87 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
104 overflow_count); 88 overflow_count);
105 } 89 }
106 90
107 base::string16 DevModeBubbleController::GetLearnMoreLabel() const { 91 base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
108 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 92 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
109 } 93 }
110 94
111 GURL DevModeBubbleController::GetLearnMoreUrl() const { 95 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
112 return GURL(chrome::kChromeUIExtensionsURL); 96 return GURL(chrome::kChromeUIExtensionsURL);
113 } 97 }
114 98
115 base::string16 DevModeBubbleController::GetActionButtonLabel() const { 99 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
116 return l10n_util::GetStringUTF16(IDS_DISABLE); 100 return l10n_util::GetStringUTF16(IDS_DISABLE);
117 } 101 }
118 102
119 base::string16 DevModeBubbleController::GetDismissButtonLabel() const { 103 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
120 return l10n_util::GetStringUTF16(IDS_CANCEL); 104 return l10n_util::GetStringUTF16(IDS_CANCEL);
121 } 105 }
122 106
123 bool DevModeBubbleController::ShouldShowExtensionList() const { 107 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
124 return false; 108 return false;
125 } 109 }
126 110
127 std::vector<base::string16> DevModeBubbleController::GetExtensions() { 111 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
128 return GetExtensionList();
129 }
130
131 void DevModeBubbleController::LogExtensionCount(size_t count) {
132 UMA_HISTOGRAM_COUNTS_100( 112 UMA_HISTOGRAM_COUNTS_100(
133 "DevModeExtensionBubble.ExtensionsInDevModeCount", count); 113 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
134 } 114 }
135 115
136 void DevModeBubbleController::LogAction( 116 void DevModeBubbleDelegate::LogAction(
137 ExtensionMessageBubbleController::BubbleAction action) { 117 ExtensionMessageBubbleController::BubbleAction action) {
138 UMA_HISTOGRAM_ENUMERATION( 118 UMA_HISTOGRAM_ENUMERATION(
139 "DevModeExtensionBubble.UserSelection", 119 "DevModeExtensionBubble.UserSelection",
140 action, ExtensionMessageBubbleController::ACTION_BOUNDARY); 120 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
141 } 121 }
142 122
143 template <> 123 ////////////////////////////////////////////////////////////////////////////////
144 void ProfileKeyedAPIFactory< 124 // DevModeBubbleController
145 DevModeBubbleController>::DeclareFactoryDependencies() { 125
146 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); 126 DevModeBubbleController::DevModeBubbleController(Profile* profile)
127 : ExtensionMessageBubbleController(
128 new DevModeBubbleDelegate(profile), profile),
129 profile_(profile) {
130 }
131
132 DevModeBubbleController::~DevModeBubbleController() {
133 }
134
135 bool DevModeBubbleController::ShouldShow() {
136 return !g_shown_for_profiles.Get().count(profile_) &&
137 !GetExtensionList().empty();
138 }
139
140 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
141 g_shown_for_profiles.Get().insert(profile_);
142 ExtensionMessageBubbleController::Show(bubble);
143 }
144
145 void DevModeBubbleController::ClearProfileListForTesting() {
146 g_shown_for_profiles.Get().clear();
147 } 147 }
148 148
149 } // namespace extensions 149 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698