Commit b70099aa authored by khmel's avatar khmel Committed by Commit bot

arc: Disable shelf item creation when secondary user is active.

This CL prevents appearing an item on the shelf when Arc app gets
active during the secondary user session.

BUG=b/31154158
BUG=644751
BUG=642649
TEST=Manually on device
TEST=Added intial unit_test coverage for Arc multi-user

Review-Url: https://codereview.chromium.org/2325743002
Cr-Commit-Position: refs/heads/master@{#417434}
parent ea99d195
......@@ -299,7 +299,7 @@ void ArcAppWindowLauncherController::OnWindowVisibilityChanging(
aura::Window* window,
bool visible) {
// The application id property should be set at this time.
if (visible)
if (visible && observed_profile_ == owner()->GetProfile())
AttachControllerToWindowIfNeeded(window);
}
......@@ -421,6 +421,10 @@ void ArcAppWindowLauncherController::OnTaskCreated(
task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId(
ArcAppListPrefs::GetAppId(package_name, activity_name));
// Don't create shelf icon for non-primary user.
if (observed_profile_ != owner()->GetProfile())
return;
AttachControllerToWindowsIfNeeded();
}
......
......@@ -50,7 +50,7 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
// Returns Arc app id. Arc platform host app is mapped to Play Store app.
static std::string GetArcAppIdFromShelfAppId(const std::string& shelf_app_id);
// AppWindowLauncherControllre:
// AppWindowLauncherController:
void ActiveUserChanged(const std::string& user_email) override;
void AdditionalUserAddedToSession(Profile* profile) override;
......
......@@ -1595,6 +1595,10 @@ void ChromeLauncherControllerImpl::AttachProfile(Profile* profile) {
app_service->AddObserverAndStart(this);
}
void ChromeLauncherControllerImpl::SetProfileForTest(Profile* profile) {
profile_ = profile;
}
void ChromeLauncherControllerImpl::ReleaseProfile() {
if (app_sync_ui_state_)
app_sync_ui_state_->RemoveObserver(this);
......
......@@ -139,14 +139,17 @@ class ChromeLauncherControllerImpl
void OnUserProfileReadyToSwitch(Profile* profile) override;
ArcAppDeferredLauncherController* GetArcDeferredLauncher() override;
void SetProfileForTest(Profile* profile);
// Access to the BrowserStatusMonitor for tests.
BrowserStatusMonitor* browser_status_monitor_for_test() {
return browser_status_monitor_.get();
}
// Access to the AppWindowLauncherController for tests.
AppWindowLauncherController* app_window_controller_for_test() {
return app_window_controllers_[0].get();
// Access to the AppWindowLauncherController list for tests.
const std::vector<std::unique_ptr<AppWindowLauncherController>>&
app_window_controllers_for_test() {
return app_window_controllers_;
}
// ash::ShelfDelegate:
......@@ -284,7 +287,7 @@ class ChromeLauncherControllerImpl
ash::ShelfItemDelegate* item_delegate);
// Attach to a specific profile.
void AttachProfile(Profile* proifile);
void AttachProfile(Profile* profile);
// Forget the current profile to allow attaching to a new one.
void ReleaseProfile();
......
......@@ -1150,8 +1150,11 @@ class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest
manager->ActiveUserChanged(account_id);
launcher_controller_->browser_status_monitor_for_test()->ActiveUserChanged(
account_id.GetUserEmail());
launcher_controller_->app_window_controller_for_test()->ActiveUserChanged(
account_id.GetUserEmail());
for (const auto& controller :
launcher_controller_->app_window_controllers_for_test()) {
controller->ActiveUserChanged(account_id.GetUserEmail());
}
}
// Creates a browser with a |profile| and load a tab with a |title| and |url|.
......@@ -1178,8 +1181,8 @@ class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest
V1App* v1_app = new V1App(profile, app_name);
// Create a new launcher controller helper and assign it to the launcher so
// that this app gets properly detected.
// TODO(skuhne): Create a more intelligent launcher contrller helper that is
// able to detect all running apps properly.
// TODO(skuhne): Create a more intelligent launcher controller helper that
// is able to detect all running apps properly.
TestLauncherControllerHelper* helper = new TestLauncherControllerHelper;
helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0),
app_name);
......@@ -1223,6 +1226,18 @@ class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest
MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest);
};
class ChromeLauncherControllerImplMultiProfileWithArcTest
: public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest {
protected:
ChromeLauncherControllerImplMultiProfileWithArcTest() {
auto_start_arc_test_ = true;
}
~ChromeLauncherControllerImplMultiProfileWithArcTest() override {}
private:
DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImplMultiProfileWithArcTest);
};
TEST_F(ChromeLauncherControllerImplTest, DefaultApps) {
InitLauncherController();
// Model should only contain the browser shortcut and app list items.
......@@ -1834,6 +1849,67 @@ TEST_F(ChromeLauncherControllerImplWithArcTest, ArcDeferredLaunch) {
(request1->IsForApp(app3) && request2->IsForApp(app2)));
}
TEST_F(ChromeLauncherControllerImplMultiProfileWithArcTest, ArcMultiUser) {
SendListOfArcApps();
InitLauncherController();
SetLauncherControllerHelper(new TestLauncherControllerHelper);
// App1 exists all the time.
// App2 is created when primary user is active and destroyed when secondary
// user is active.
// App3 created when secondary user is active.
const std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
const AccountId account_id(
multi_user_util::GetAccountIdFromProfile(profile()));
const AccountId account_id2(
multi_user_util::GetAccountIdFromProfile(profile2));
const std::string arc_app_id1 =
ArcAppTest::GetAppId(arc_test_.fake_apps()[0]);
const std::string arc_app_id2 =
ArcAppTest::GetAppId(arc_test_.fake_apps()[1]);
const std::string arc_app_id3 =
ArcAppTest::GetAppId(arc_test_.fake_apps()[2]);
std::string window_app_id1("org.chromium.arc.1");
views::Widget* arc_window1 = CreateArcWindow(window_app_id1);
arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0]);
EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1));
std::string window_app_id2("org.chromium.arc.2");
views::Widget* arc_window2 = CreateArcWindow(window_app_id2);
arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[1]);
EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2));
launcher_controller_->SetProfileForTest(profile2);
SwitchActiveUser(account_id2);
EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1));
EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2));
std::string window_app_id3("org.chromium.arc.3");
views::Widget* arc_window3 = CreateArcWindow(window_app_id3);
arc_test_.app_instance()->SendTaskCreated(3, arc_test_.fake_apps()[2]);
EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id3));
arc_window2->CloseNow();
arc_test_.app_instance()->SendTaskDestroyed(2);
launcher_controller_->SetProfileForTest(profile());
SwitchActiveUser(account_id);
EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id1));
EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(arc_app_id2));
EXPECT_NE(0, launcher_controller_->GetShelfIDForAppID(arc_app_id3));
// Close active window to let test passes.
arc_window1->CloseNow();
arc_window3->CloseNow();
}
TEST_F(ChromeLauncherControllerImplWithArcTest, ArcRunningApp) {
InitLauncherController();
......
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