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

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

Issue 2064363002: Refactor MessageCenterSettingsController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto associated CL. 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/notifications/arc_notifier_manager.h" 5 #include "chrome/browser/notifications/arc_notifier_source.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 11 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
11 #include "ui/message_center/notifier_settings.h" 12 #include "ui/message_center/notifier_settings.h"
12 13
13 namespace arc { 14 namespace arc {
14 15
15 namespace { 16 namespace {
16 constexpr int kSetNotificationsEnabledMinVersion = 6; 17 constexpr int kSetNotificationsEnabledMinVersion = 6;
17 } // namespace 18 } // namespace
18 19
20 ArcNotifierSource::ArcNotifierSource(
21 message_center::NotifierSettingsObserver* parent)
22 : NotifierSource(parent) {}
23
24 ArcNotifierSource::~ArcNotifierSource() {}
25
19 std::vector<std::unique_ptr<message_center::Notifier>> 26 std::vector<std::unique_ptr<message_center::Notifier>>
20 ArcNotifierManager::GetNotifiers(content::BrowserContext* profile) { 27 ArcNotifierSource::GetNotifierList(Profile* profile) {
21 const ArcAppListPrefs* const app_list = ArcAppListPrefs::Get(profile); 28 const ArcAppListPrefs* const app_list = ArcAppListPrefs::Get(profile);
22 const std::vector<std::string>& app_ids = app_list->GetAppIds(); 29 const std::vector<std::string>& app_ids = app_list->GetAppIds();
23 std::set<std::string> added_packages; 30 std::set<std::string> added_packages;
24 std::vector<std::unique_ptr<message_center::Notifier>> results; 31 std::vector<std::unique_ptr<message_center::Notifier>> results;
25 32
26 for (const std::string& app_id : app_ids) { 33 for (const std::string& app_id : app_ids) {
27 const auto app = app_list->GetApp(app_id); 34 const auto app = app_list->GetApp(app_id);
28 if (!app) 35 if (!app)
29 continue; 36 continue;
30 // Handle packages having multiple launcher activities. 37 // Handle packages having multiple launcher activities.
31 if (added_packages.count(app->package_name)) 38 if (added_packages.count(app->package_name))
32 continue; 39 continue;
33 40
34 added_packages.insert(app->package_name); 41 added_packages.insert(app->package_name);
35 message_center::NotifierId notifier_id( 42 message_center::NotifierId notifier_id(
36 message_center::NotifierId::ARC_APPLICATION, app->package_name); 43 message_center::NotifierId::ARC_APPLICATION, app->package_name);
37 results.emplace_back(new message_center::Notifier( 44 results.emplace_back(
38 notifier_id, 45 new message_center::Notifier(notifier_id, base::ASCIIToUTF16(app->name),
39 base::ASCIIToUTF16(app->name), 46 app->notifications_enabled));
40 app->notifications_enabled));
41 } 47 }
42 48
43 return results; 49 return results;
44 } 50 }
45 51
46 void ArcNotifierManager::SetNotifierEnabled(const std::string& package, 52 void ArcNotifierSource::SetNotifierEnabled(
47 bool enabled) { 53 Profile* profile,
54 const message_center::Notifier& notifier,
55 bool enabled) {
48 auto* const service = arc::ArcBridgeService::Get(); 56 auto* const service = arc::ArcBridgeService::Get();
49 if (service) { 57 if (service) {
50 if (service->app_version() >= kSetNotificationsEnabledMinVersion) { 58 if (service->app_version() >= kSetNotificationsEnabledMinVersion) {
51 service->app_instance()->SetNotificationsEnabled(package, enabled); 59 service->app_instance()->SetNotificationsEnabled(notifier.notifier_id.id,
60 enabled);
61 parent_->NotifierEnabledChanged(notifier.notifier_id, enabled);
52 } 62 }
53 } 63 }
54 } 64 }
55 65
66 message_center::NotifierId::NotifierType ArcNotifierSource::GetNotifierType() {
67 return message_center::NotifierId::ARC_APPLICATION;
68 }
69
56 } // namespace arc 70 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698