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

Side by Side Diff: chrome/browser/notifications/application_notifier_source.cc

Issue 2064363002: Refactor MessageCenterSettingsController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix misspell. Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 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.
4
5 #include "chrome/browser/notifications/application_notifier_source.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/notifications/notifier_state_tracker.h"
9 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension_set.h"
13 #include "extensions/common/permissions/api_permission.h"
14 #include "extensions/common/permissions/permissions_data.h"
15 #include "ui/message_center/notifier_settings.h"
16
17 ApplicationNotifierSource::ApplicationNotifierSource(Observer* observer)
18 : observer_(observer) {}
19
20 ApplicationNotifierSource::~ApplicationNotifierSource() {}
21
22 std::vector<std::unique_ptr<message_center::Notifier>>
23 ApplicationNotifierSource::GetNotifierList(Profile* profile) {
24 std::vector<std::unique_ptr<message_center::Notifier>> notifiers;
25 const extensions::ExtensionSet& extension_set =
26 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
27 // The extension icon size has to be 32x32 at least to load bigger icons if
28 // the icon doesn't exist for the specified size, and in that case it falls
29 // back to the default icon. The fetched icon will be resized in the
30 // settings dialog. See chrome/browser/extensions/extension_icon_image.cc
31 // and crbug.com/222931
32 app_icon_loader_.reset(new extensions::ExtensionAppIconLoader(
33 profile, extension_misc::EXTENSION_ICON_SMALL, this));
34 for (extensions::ExtensionSet::const_iterator iter = extension_set.begin();
35 iter != extension_set.end(); ++iter) {
36 const extensions::Extension* extension = iter->get();
37 if (!extension->permissions_data()->HasAPIPermission(
38 extensions::APIPermission::kNotifications)) {
39 continue;
40 }
41
42 // Hosted apps are no longer able to affect the notifications permission
43 // state for web notifications.
44 // TODO(dewittj): Deprecate the 'notifications' permission for hosted
45 // apps.
46 if (extension->is_hosted_app())
47 continue;
48
49 message_center::NotifierId notifier_id(
50 message_center::NotifierId::APPLICATION, extension->id());
51 NotifierStateTracker* const notifier_state_tracker =
52 NotifierStateTrackerFactory::GetForProfile(profile);
53 notifiers.emplace_back(new message_center::Notifier(
54 notifier_id, base::UTF8ToUTF16(extension->name()),
55 notifier_state_tracker->IsNotifierEnabled(notifier_id)));
56 app_icon_loader_->FetchImage(extension->id());
57 }
58
59 return notifiers;
60 }
61
62 void ApplicationNotifierSource::SetNotifierEnabled(
63 Profile* profile,
64 const message_center::Notifier& notifier,
65 bool enabled) {
66 NotifierStateTrackerFactory::GetForProfile(profile)->SetNotifierEnabled(
67 notifier.notifier_id, enabled);
68 observer_->OnNotifierEnabledChanged(notifier.notifier_id, enabled);
69 }
70
71 message_center::NotifierId::NotifierType
72 ApplicationNotifierSource::GetNotifierType() {
73 return message_center::NotifierId::APPLICATION;
74 }
75
76 void ApplicationNotifierSource::OnAppImageUpdated(const std::string& id,
77 const gfx::ImageSkia& image) {
78 observer_->OnIconImageUpdated(
79 message_center::NotifierId(message_center::NotifierId::APPLICATION, id),
80 gfx::Image(image));
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698