| OLD | NEW |
| 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_application_notifier_source_chromeos.
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 ArcApplicationNotifierSourceChromeOS::ArcApplicationNotifierSourceChromeOS( |
| 21 Observer* observer) |
| 22 : observer_(observer) {} |
| 23 |
| 19 std::vector<std::unique_ptr<message_center::Notifier>> | 24 std::vector<std::unique_ptr<message_center::Notifier>> |
| 20 ArcNotifierManager::GetNotifiers(content::BrowserContext* profile) { | 25 ArcApplicationNotifierSourceChromeOS::GetNotifierList(Profile* profile) { |
| 21 const ArcAppListPrefs* const app_list = ArcAppListPrefs::Get(profile); | 26 const ArcAppListPrefs* const app_list = ArcAppListPrefs::Get(profile); |
| 22 const std::vector<std::string>& app_ids = app_list->GetAppIds(); | 27 const std::vector<std::string>& app_ids = app_list->GetAppIds(); |
| 23 std::set<std::string> added_packages; | 28 std::set<std::string> added_packages; |
| 24 std::vector<std::unique_ptr<message_center::Notifier>> results; | 29 std::vector<std::unique_ptr<message_center::Notifier>> results; |
| 25 | 30 |
| 26 for (const std::string& app_id : app_ids) { | 31 for (const std::string& app_id : app_ids) { |
| 27 const auto app = app_list->GetApp(app_id); | 32 const auto app = app_list->GetApp(app_id); |
| 28 if (!app) | 33 if (!app) |
| 29 continue; | 34 continue; |
| 30 // Handle packages having multiple launcher activities. | 35 // Handle packages having multiple launcher activities. |
| 31 if (added_packages.count(app->package_name)) | 36 if (added_packages.count(app->package_name)) |
| 32 continue; | 37 continue; |
| 33 | 38 |
| 34 added_packages.insert(app->package_name); | 39 added_packages.insert(app->package_name); |
| 35 message_center::NotifierId notifier_id( | 40 message_center::NotifierId notifier_id( |
| 36 message_center::NotifierId::ARC_APPLICATION, app->package_name); | 41 message_center::NotifierId::ARC_APPLICATION, app->package_name); |
| 37 results.emplace_back(new message_center::Notifier( | 42 results.emplace_back( |
| 38 notifier_id, | 43 new message_center::Notifier(notifier_id, base::ASCIIToUTF16(app->name), |
| 39 base::ASCIIToUTF16(app->name), | 44 app->notifications_enabled)); |
| 40 app->notifications_enabled)); | |
| 41 } | 45 } |
| 42 | 46 |
| 43 return results; | 47 return results; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ArcNotifierManager::SetNotifierEnabled(const std::string& package, | 50 void ArcApplicationNotifierSourceChromeOS::SetNotifierEnabled( |
| 47 bool enabled) { | 51 Profile* profile, |
| 52 const message_center::Notifier& notifier, |
| 53 bool enabled) { |
| 48 auto* const service = arc::ArcBridgeService::Get(); | 54 auto* const service = arc::ArcBridgeService::Get(); |
| 49 if (service) { | 55 if (service) { |
| 50 if (service->app_version() >= kSetNotificationsEnabledMinVersion) { | 56 if (service->app_version() >= kSetNotificationsEnabledMinVersion) { |
| 51 service->app_instance()->SetNotificationsEnabled(package, enabled); | 57 service->app_instance()->SetNotificationsEnabled(notifier.notifier_id.id, |
| 58 enabled); |
| 59 observer_->OnNotifierEnabledChanged(notifier.notifier_id, enabled); |
| 52 } | 60 } |
| 53 } | 61 } |
| 54 } | 62 } |
| 55 | 63 |
| 64 message_center::NotifierId::NotifierType |
| 65 ArcApplicationNotifierSourceChromeOS::GetNotifierType() { |
| 66 return message_center::NotifierId::ARC_APPLICATION; |
| 67 } |
| 68 |
| 56 } // namespace arc | 69 } // namespace arc |
| OLD | NEW |