Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc |
| diff --git a/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc |
| index c110d1c8ffc0adddda3cf99530196b2d041d44ed..36691d61d4761d3af45a4fa95d11cadd4c6a2509 100644 |
| --- a/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc |
| +++ b/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc |
| @@ -262,17 +262,19 @@ std::string ArcAppWindowLauncherController::GetArcAppIdFromShelfAppId( |
| void ArcAppWindowLauncherController::ActiveUserChanged( |
| const std::string& user_email) { |
| - for (auto& it : task_id_to_app_window_) { |
| - AppWindow* app_window = it.second.get(); |
| - if (user_email == |
| - user_manager::UserManager::Get() |
| - ->GetPrimaryUser() |
| - ->GetAccountId() |
| - .GetUserEmail()) { |
| - RegisterApp(app_window); |
| - } else { |
| + const std::string& primary_user_email = user_manager::UserManager::Get() |
| + ->GetPrimaryUser() |
| + ->GetAccountId() |
| + .GetUserEmail(); |
| + if (user_email == primary_user_email) { |
| + MaybeAttachContollerToWindows(); |
| + OnTaskSetActive(active_task_id_); |
| + } else { |
| + for (auto& it : task_id_to_app_window_) { |
| + AppWindow* app_window = it.second.get(); |
| UnregisterApp(app_window, true); |
| } |
| + task_id_to_app_window_.clear(); |
|
khmel
2016/09/06 20:46:13
It is not safe to keep mapping to AppWindow when c
Mr4D (OOO till 08-26)
2016/09/07 20:17:34
Can you please add a comment here to state this?
khmel
2016/09/07 21:01:47
Done.
|
| } |
| } |
| @@ -294,7 +296,7 @@ void ArcAppWindowLauncherController::OnWindowVisibilityChanging( |
| bool visible) { |
| // The application id property should be set at this time. |
| if (visible) |
| - MayAttachContollerToWindow(window); |
| + MaybeAttachContollerToWindow(window); |
| } |
| void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| @@ -326,7 +328,12 @@ ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| return it->second.get(); |
| } |
| -void ArcAppWindowLauncherController::MayAttachContollerToWindow( |
| +void ArcAppWindowLauncherController::MaybeAttachContollerToWindows() { |
| + for (auto* window : observed_windows_) |
| + MaybeAttachContollerToWindow(window); |
| +} |
| + |
| +void ArcAppWindowLauncherController::MaybeAttachContollerToWindow( |
| aura::Window* window) { |
| const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); |
| if (window_app_id.empty()) |
| @@ -410,8 +417,7 @@ void ArcAppWindowLauncherController::OnTaskCreated( |
| task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId( |
| ArcAppListPrefs::GetAppId(package_name, activity_name)); |
| - for (auto* window : observed_windows_) |
| - MayAttachContollerToWindow(window); |
| + MaybeAttachContollerToWindows(); |
| } |
| void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| @@ -443,8 +449,10 @@ void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| } |
| void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { |
| - if (observed_profile_ != owner()->GetProfile()) |
| + if (observed_profile_ != owner()->GetProfile()) { |
| + active_task_id_ = task_id; |
| return; |
| + } |
| TaskIdToAppWindow::iterator previous_active_app_it = |
| task_id_to_app_window_.find(active_task_id_); |
| @@ -583,9 +591,10 @@ void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, |
| bool close_controller) { |
| const std::string app_id = app_window->app_id(); |
| + |
| DCHECK(!app_id.empty()); |
| AppControllerMap::iterator it = app_controller_map_.find(app_id); |
| - DCHECK(it != app_controller_map_.end()); |
| + CHECK(it != app_controller_map_.end()); |
| ArcAppWindowLauncherItemController* controller = it->second; |
| controller->RemoveWindow(app_window); |