Commit 3bc00036 authored by nancy's avatar nancy Committed by Commit Bot

Add active user changed handling for App Service app window.

Update AppServiceProxy when the user is switched because
AppServiceProxy is based on profile.

Add MultiProfileBrowserStatusMonitor to ChromeLauncherController when
kAppServiceInstanceRegistry flag is enabled.

BUG=1011235

Change-Id: Id46f72d2334b94f601275560088112180c5bfc87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1940314
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720789}
parent 80ad0b6f
......@@ -10,6 +10,7 @@
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/launcher/app_window_base.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
......@@ -41,6 +42,22 @@ AppServiceAppWindowLauncherController::
aura::Env::GetInstance()->RemoveObserver(this);
}
void AppServiceAppWindowLauncherController::ActiveUserChanged(
const std::string& user_email) {
if (proxy_)
Observe(nullptr);
// TODO(crbug.com/1011235): Inactive the running app windows in
// InstanceRegistry for the inactive user, and active the app windows for the
// active user.
proxy_ = apps::AppServiceProxyFactory::GetForProfile(owner()->profile());
DCHECK(proxy_);
Observe(&proxy_->InstanceRegistry());
app_service_instance_helper_->ActiveUserChanged();
}
void AppServiceAppWindowLauncherController::OnWindowInitialized(
aura::Window* window) {
// An app window has type WINDOW_TYPE_NORMAL, a WindowDelegate and
......
......@@ -40,6 +40,9 @@ class AppServiceAppWindowLauncherController
ChromeLauncherController* owner);
~AppServiceAppWindowLauncherController() override;
// AppWindowLauncherController:
void ActiveUserChanged(const std::string& user_email) override;
// aura::EnvObserver:
void OnWindowInitialized(aura::Window* window) override;
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_features.h"
#include "chrome/services/app_service/public/cpp/instance_update.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
......@@ -24,6 +25,14 @@ AppServiceInstanceRegistryHelper::AppServiceInstanceRegistryHelper(
AppServiceInstanceRegistryHelper::~AppServiceInstanceRegistryHelper() = default;
void AppServiceInstanceRegistryHelper::ActiveUserChanged() {
if (!base::FeatureList::IsEnabled(features::kAppServiceInstanceRegistry))
return;
proxy_ = apps::AppServiceProxyFactory::GetForProfile(
ProfileManager::GetActiveUserProfile());
}
void AppServiceInstanceRegistryHelper::OnActiveTabChanged(
content::WebContents* old_contents,
content::WebContents* new_contents) {
......
......@@ -30,6 +30,8 @@ class AppServiceInstanceRegistryHelper {
explicit AppServiceInstanceRegistryHelper(Profile* profile);
~AppServiceInstanceRegistryHelper();
void ActiveUserChanged();
// Notifies the AppService InstanceRegistry that active tabs are changed.
void OnActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents);
......
......@@ -80,6 +80,10 @@ class BrowserStatusMonitor : public BrowserTabStripTrackerDelegate,
bool IsV1AppInShelf(Browser* browser);
bool IsV1AppInShelfWithAppId(const std::string& app_id);
AppServiceInstanceRegistryHelper* app_service_instance_helper() const {
return app_service_instance_helper_.get();
}
private:
class LocalWebContentsObserver;
......
......@@ -258,8 +258,18 @@ ChromeLauncherController::ChromeLauncherController(Profile* profile,
}
if (base::FeatureList::IsEnabled(features::kAppServiceInstanceRegistry)) {
if (SessionControllerClientImpl::IsMultiProfileAvailable()) {
// If running in separated destkop mode, we create the multi profile
// version of status monitor.
browser_status_monitor_ =
std::make_unique<MultiProfileBrowserStatusMonitor>(this);
browser_status_monitor_->Initialize();
} else {
// Create our v1/v2 application / browser monitors which will inform the
// launcher of status changes.
browser_status_monitor_ = std::make_unique<BrowserStatusMonitor>(this);
browser_status_monitor_->Initialize();
}
app_window_controllers_.push_back(
std::make_unique<AppServiceAppWindowLauncherController>(this));
return;
......
......@@ -27,6 +27,8 @@ MultiProfileBrowserStatusMonitor::~MultiProfileBrowserStatusMonitor() {}
void MultiProfileBrowserStatusMonitor::ActiveUserChanged(
const std::string& user_email) {
app_service_instance_helper()->ActiveUserChanged();
// Handle windowed apps.
for (AppList::iterator it = app_list_.begin(); it != app_list_.end(); ++it) {
bool owned = multi_user_util::IsProfileFromActiveUser((*it)->profile());
......
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