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

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

Issue 134103002: Refactor the extension message bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments 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/extension_message_bubble_controller.h" 5 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h" 10 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/user_metrics.h" 16 #include "content/public/browser/user_metrics.h"
17 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 //////////////////////////////////////////////////////////////////////////////// 23 ////////////////////////////////////////////////////////////////////////////////
24 // ExtensionMessageBubbleController::Delegate
25
26 ExtensionMessageBubbleController::Delegate::Delegate() {
27 }
28
29 ExtensionMessageBubbleController::Delegate::~Delegate() {
30 }
31
32 ////////////////////////////////////////////////////////////////////////////////
24 // ExtensionMessageBubbleController 33 // ExtensionMessageBubbleController
25 34
26 ExtensionMessageBubbleController::ExtensionMessageBubbleController( 35 ExtensionMessageBubbleController::ExtensionMessageBubbleController(
27 Delegate* delegate, Profile* profile) 36 Delegate* delegate, Profile* profile)
28 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()), 37 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
29 profile_(profile), 38 profile_(profile),
30 user_action_(ACTION_BOUNDARY), 39 user_action_(ACTION_BOUNDARY),
31 delegate_(delegate), 40 delegate_(delegate),
32 initialized_(false), 41 initialized_(false) {
33 has_notified_(false) {
34 } 42 }
35 43
36 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() { 44 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() {
37 } 45 }
38 46
39 bool ExtensionMessageBubbleController::ShouldShow() {
40 if (has_notified_)
41 return false;
42
43 has_notified_ = true;
44 return !GetOrCreateExtensionList()->empty();
45 }
46
47 std::vector<base::string16> 47 std::vector<base::string16>
48 ExtensionMessageBubbleController::GetExtensionList() { 48 ExtensionMessageBubbleController::GetExtensionList() {
49 ExtensionIdList* list = GetOrCreateExtensionList(); 49 ExtensionIdList* list = GetOrCreateExtensionList();
50 if (list->empty()) 50 if (list->empty())
51 return std::vector<base::string16>(); 51 return std::vector<base::string16>();
52 52
53 std::vector<base::string16> return_value; 53 std::vector<base::string16> return_value;
54 for (ExtensionIdList::const_iterator it = list->begin(); 54 for (ExtensionIdList::const_iterator it = list->begin();
55 it != list->end(); ++it) { 55 it != list->end(); ++it) {
56 const Extension* extension = service_->GetInstalledExtension(*it); 56 const Extension* extension = service_->GetInstalledExtension(*it);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 void ExtensionMessageBubbleController::AcknowledgeExtensions() { 125 void ExtensionMessageBubbleController::AcknowledgeExtensions() {
126 ExtensionIdList* list = GetOrCreateExtensionList(); 126 ExtensionIdList* list = GetOrCreateExtensionList();
127 for (ExtensionIdList::const_iterator it = list->begin(); 127 for (ExtensionIdList::const_iterator it = list->begin();
128 it != list->end(); ++it) 128 it != list->end(); ++it)
129 delegate_->AcknowledgeExtension(*it, user_action_); 129 delegate_->AcknowledgeExtension(*it, user_action_);
130 } 130 }
131 131
132 ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() { 132 ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() {
133 if (!service_)
134 return &extension_list_; // Can occur during testing.
135
136 if (!initialized_) { 133 if (!initialized_) {
137 scoped_ptr<const ExtensionSet> extension_set( 134 scoped_ptr<const ExtensionSet> extension_set(
138 service_->GenerateInstalledExtensionsSet()); 135 service_->GenerateInstalledExtensionsSet());
139 for (ExtensionSet::const_iterator it = extension_set->begin(); 136 for (ExtensionSet::const_iterator it = extension_set->begin();
140 it != extension_set->end(); ++it) { 137 it != extension_set->end(); ++it) {
141 std::string id = (*it)->id(); 138 std::string id = (*it)->id();
142 if (!delegate_->ShouldIncludeExtension(id)) 139 if (!delegate_->ShouldIncludeExtension(id))
143 continue; 140 continue;
144 extension_list_.push_back(id); 141 extension_list_.push_back(id);
145 } 142 }
146 143
147 delegate_->LogExtensionCount(extension_list_.size()); 144 delegate_->LogExtensionCount(extension_list_.size());
148 initialized_ = true; 145 initialized_ = true;
149 } 146 }
150 147
151 return &extension_list_; 148 return &extension_list_;
152 } 149 }
153 150
154 } // namespace extensions 151 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698