Commit 10061b18 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by Commit Bot

Wait for profile to load in ChromeAshMessageCenterClient

Delay fetching the notifiers until the profile is fully loaded.

Bug: 957121
Test: manual
Change-Id: Ib62c9b144a49ea18bf508cbb0e26df47b0a03e9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636284
Commit-Queue: Vladislav Kaznacheev <kaznacheev@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665298}
parent fb204ae5
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/public/interfaces/constants.mojom.h" #include "ash/public/interfaces/constants.mojom.h"
#include "base/i18n/string_compare.h" #include "base/i18n/string_compare.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/notifications/arc_application_notifier_controller.h" #include "chrome/browser/notifications/arc_application_notifier_controller.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "chrome/browser/ui/settings_window_manager_chromeos.h" #include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
...@@ -33,7 +35,6 @@ ChromeAshMessageCenterClient* g_chrome_ash_message_center_client = nullptr; ...@@ -33,7 +35,6 @@ ChromeAshMessageCenterClient* g_chrome_ash_message_center_client = nullptr;
// profile, so this just returns the active profile. // profile, so this just returns the active profile.
Profile* GetProfileForNotifiers() { Profile* GetProfileForNotifiers() {
const auto* user = user_manager::UserManager::Get()->GetActiveUser(); const auto* user = user_manager::UserManager::Get()->GetActiveUser();
CHECK(user->is_profile_created());
return chromeos::ProfileHelper::Get()->GetProfileByUser(user); return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
} }
...@@ -92,6 +93,10 @@ ChromeAshMessageCenterClient::ChromeAshMessageCenterClient( ...@@ -92,6 +93,10 @@ ChromeAshMessageCenterClient::ChromeAshMessageCenterClient(
ChromeAshMessageCenterClient::~ChromeAshMessageCenterClient() { ChromeAshMessageCenterClient::~ChromeAshMessageCenterClient() {
DCHECK_EQ(this, g_chrome_ash_message_center_client); DCHECK_EQ(this, g_chrome_ash_message_center_client);
g_chrome_ash_message_center_client = nullptr; g_chrome_ash_message_center_client = nullptr;
if (deferred_notifier_list_callback_) {
std::move(deferred_notifier_list_callback_)
.Run(std::vector<ash::mojom::NotifierUiDataPtr>());
}
} }
void ChromeAshMessageCenterClient::Display( void ChromeAshMessageCenterClient::Display(
...@@ -159,7 +164,26 @@ void ChromeAshMessageCenterClient::SetNotifierEnabled( ...@@ -159,7 +164,26 @@ void ChromeAshMessageCenterClient::SetNotifierEnabled(
void ChromeAshMessageCenterClient::GetNotifierList( void ChromeAshMessageCenterClient::GetNotifierList(
GetNotifierListCallback callback) { GetNotifierListCallback callback) {
if (deferred_notifier_list_callback_) {
std::move(deferred_notifier_list_callback_)
.Run(std::vector<ash::mojom::NotifierUiDataPtr>());
registrar_.RemoveAll();
}
Profile* profile = GetProfileForNotifiers(); Profile* profile = GetProfileForNotifiers();
if (profile) {
RespondWithNotifierList(profile, std::move(callback));
} else {
LOG(ERROR) << "GetNotifierList called before profile fully loaded, see "
"https://crbug.com/968825";
deferred_notifier_list_callback_ = std::move(callback);
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources());
}
}
void ChromeAshMessageCenterClient::RespondWithNotifierList(
Profile* profile,
GetNotifierListCallback callback) const {
CHECK(profile); CHECK(profile);
std::vector<ash::mojom::NotifierUiDataPtr> notifiers; std::vector<ash::mojom::NotifierUiDataPtr> notifiers;
for (auto& source : sources_) { for (auto& source : sources_) {
...@@ -177,6 +201,26 @@ void ChromeAshMessageCenterClient::GetNotifierList( ...@@ -177,6 +201,26 @@ void ChromeAshMessageCenterClient::GetNotifierList(
std::move(callback).Run(std::move(notifiers)); std::move(callback).Run(std::move(notifiers));
} }
void ChromeAshMessageCenterClient::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_ADDED: {
Profile* profile = GetProfileForNotifiers();
if (profile) {
CHECK(deferred_notifier_list_callback_);
RespondWithNotifierList(profile,
std::move(deferred_notifier_list_callback_));
registrar_.RemoveAll();
}
break;
}
default:
NOTREACHED();
}
}
void ChromeAshMessageCenterClient::GetArcAppIdByPackageName( void ChromeAshMessageCenterClient::GetArcAppIdByPackageName(
const std::string& package_name, const std::string& package_name,
GetArcAppIdByPackageNameCallback callback) { GetArcAppIdByPackageNameCallback callback) {
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "chrome/browser/notifications/notification_platform_bridge.h" #include "chrome/browser/notifications/notification_platform_bridge.h"
#include "chrome/browser/notifications/notification_platform_bridge_chromeos.h" #include "chrome/browser/notifications/notification_platform_bridge_chromeos.h"
#include "chrome/browser/notifications/notifier_controller.h" #include "chrome/browser/notifications/notifier_controller.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
...@@ -19,7 +21,8 @@ ...@@ -19,7 +21,8 @@
// NotifierControllers to provide notifier settings information to Ash (visible // NotifierControllers to provide notifier settings information to Ash (visible
// in NotifierSettingsView). // in NotifierSettingsView).
class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient, class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient,
public NotifierController::Observer { public NotifierController::Observer,
public content::NotificationObserver {
public: public:
explicit ChromeAshMessageCenterClient( explicit ChromeAshMessageCenterClient(
NotificationPlatformBridgeDelegate* delegate); NotificationPlatformBridgeDelegate* delegate);
...@@ -57,6 +60,14 @@ class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient, ...@@ -57,6 +60,14 @@ class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient,
static void FlushForTesting(); static void FlushForTesting();
private: private:
void RespondWithNotifierList(Profile* profile,
GetNotifierListCallback callback) const;
// content::NotificationObserver override.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
NotificationPlatformBridgeDelegate* delegate_; NotificationPlatformBridgeDelegate* delegate_;
// A mapping from display token to notification ID. The display token is // A mapping from display token to notification ID. The display token is
...@@ -73,6 +84,8 @@ class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient, ...@@ -73,6 +84,8 @@ class ChromeAshMessageCenterClient : public ash::mojom::AshMessageCenterClient,
ash::mojom::AshMessageCenterControllerPtr controller_; ash::mojom::AshMessageCenterControllerPtr controller_;
mojo::AssociatedBinding<ash::mojom::AshMessageCenterClient> binding_; mojo::AssociatedBinding<ash::mojom::AshMessageCenterClient> binding_;
content::NotificationRegistrar registrar_;
GetNotifierListCallback deferred_notifier_list_callback_;
DISALLOW_COPY_AND_ASSIGN(ChromeAshMessageCenterClient); DISALLOW_COPY_AND_ASSIGN(ChromeAshMessageCenterClient);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment