| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/arc_notifier_manager.h" | |
| 6 | |
| 7 #include <set> | |
| 8 | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | |
| 11 #include "ui/message_center/notifier_settings.h" | |
| 12 | |
| 13 namespace arc { | |
| 14 | |
| 15 namespace { | |
| 16 constexpr int kSetNotificationsEnabledMinVersion = 6; | |
| 17 } // namespace | |
| 18 | |
| 19 std::vector<std::unique_ptr<message_center::Notifier>> | |
| 20 ArcNotifierManager::GetNotifiers(content::BrowserContext* profile) { | |
| 21 const ArcAppListPrefs* const app_list = ArcAppListPrefs::Get(profile); | |
| 22 const std::vector<std::string>& app_ids = app_list->GetAppIds(); | |
| 23 std::set<std::string> added_packages; | |
| 24 std::vector<std::unique_ptr<message_center::Notifier>> results; | |
| 25 | |
| 26 for (const std::string& app_id : app_ids) { | |
| 27 const auto app = app_list->GetApp(app_id); | |
| 28 if (!app) | |
| 29 continue; | |
| 30 // Handle packages having multiple launcher activities. | |
| 31 if (added_packages.count(app->package_name)) | |
| 32 continue; | |
| 33 | |
| 34 added_packages.insert(app->package_name); | |
| 35 message_center::NotifierId notifier_id( | |
| 36 message_center::NotifierId::ARC_APPLICATION, app->package_name); | |
| 37 results.emplace_back(new message_center::Notifier( | |
| 38 notifier_id, | |
| 39 base::ASCIIToUTF16(app->name), | |
| 40 app->notifications_enabled)); | |
| 41 } | |
| 42 | |
| 43 return results; | |
| 44 } | |
| 45 | |
| 46 void ArcNotifierManager::SetNotifierEnabled(const std::string& package, | |
| 47 bool enabled) { | |
| 48 auto* const service = arc::ArcBridgeService::Get(); | |
| 49 if (service) { | |
| 50 if (service->app_version() >= kSetNotificationsEnabledMinVersion) { | |
| 51 service->app_instance()->SetNotificationsEnabled(package, enabled); | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 } // namespace arc | |
| OLD | NEW |