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 1ed66e16908e7454429df9c17f1fca860ad2fc1c..af304775a7bad41b9f6425ec39d8d0e1f8ebfd76 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 |
| @@ -246,6 +246,15 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
| DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| }; |
| +struct ArcAppWindowLauncherController::TaskInfo { |
| + TaskInfo(const std::string& package_name, const std::string& activity_name) |
| + : package_name(package_name), activity_name(activity_name) {} |
| + ~TaskInfo() {} |
| + |
| + std::string package_name; |
| + std::string activity_name; |
| +}; |
| + |
| ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| ChromeLauncherController* owner, |
| ash::ShelfDelegate* shelf_delegate) |
| @@ -261,6 +270,13 @@ ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
| StopObserving(observed_profile_); |
| if (observing_shell_) |
| ash::WmShell::Get()->RemoveShellObserver(this); |
| + |
| + // Special for M53 branch. Due different deletion order of the shell |
|
khmel
2016/08/19 21:00:12
patch for M53
|
| + // and shelf launcher controllers we have to care about pending Arc |
| + // items because we cannot observe window detroying events anymore. |
| + // This is the reason of crashing unit_tests: ArcOrientationLock |
| + for (auto& it : task_id_to_app_window_) |
| + UnregisterApp(it.second.get()); |
| } |
| // static |
| @@ -311,7 +327,7 @@ void ArcAppWindowLauncherController::OnWindowVisibilityChanging( |
| bool visible) { |
| // The application id property should be set at this time. |
| if (visible) |
| - CheckForAppWindowWidget(window); |
| + MayAttachContollerToWindow(window); |
| } |
| void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| @@ -335,39 +351,58 @@ ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| return it->second.get(); |
| } |
| -void ArcAppWindowLauncherController::CheckForAppWindowWidget( |
| +void ArcAppWindowLauncherController::MayAttachContollerToWindow( |
| aura::Window* window) { |
| - const std::string app_id = exo::ShellSurface::GetApplicationId(window); |
| - if (app_id.empty()) |
| + const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); |
| + if (window_app_id.empty()) |
| return; |
| int task_id = -1; |
| - if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| + if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| return; |
| - if (task_id) { |
| - // We need to add the observer after exo started observing shell |
| - // because we want to update the orientation after exo send |
| - // the layout switch information. |
| - if (!observing_shell_) { |
| - observing_shell_ = true; |
| - ash::WmShell::Get()->AddShellObserver(this); |
| - } |
| + if (!task_id) |
| + return; |
| - AppWindow* app_window = GetAppWindowForTask(task_id); |
| - if (app_window) { |
| - app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); |
| - ash::SetShelfIDForWindow(app_window->shelf_id(), window); |
| - chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| - window, |
| - user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| - if (ash::Shell::GetInstance() |
| - ->maximize_mode_controller() |
| - ->IsMaximizeModeWindowManagerEnabled()) { |
| - SetOrientationLockForAppWindow(app_window); |
| - } |
| - } |
| + // We need to add the observer after exo started observing shell |
| + // because we want to update the orientation after exo send |
| + // the layout switch information. |
| + if (!observing_shell_) { |
| + observing_shell_ = true; |
| + ash::WmShell::Get()->AddShellObserver(this); |
| + } |
| + |
| + // Check if we have controller for this task. |
| + if (GetAppWindowForTask(task_id)) |
| + return; |
| + |
| + // Create controller if we have task info. |
| + TaskIdToTaskInfoMap::iterator it = task_id_to_task_info_.find(task_id); |
| + if (it == task_id_to_task_info_.end()) |
| + return; |
| + |
| + const TaskInfo& task_info = *it->second; |
| + const std::string app_id = |
| + GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId( |
| + task_info.package_name, task_info.activity_name)); |
| + |
| + std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); |
| + app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); |
| + RegisterApp(app_window.get()); |
| + DCHECK(app_window->controller()); |
| + ash::SetShelfIDForWindow(app_window->shelf_id(), window); |
| + chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| + window, |
| + user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| + if (ash::Shell::GetInstance() |
| + ->maximize_mode_controller() |
| + ->IsMaximizeModeWindowManagerEnabled()) { |
| + SetOrientationLockForAppWindow(app_window.get()); |
| } |
| + task_id_to_app_window_[task_id] = std::move(app_window); |
| + |
| + // TaskInfo is no longer needed. Discard it. |
| + task_id_to_task_info_.erase(task_id); |
| } |
| void ArcAppWindowLauncherController::OnAppReadyChanged( |
| @@ -403,20 +438,17 @@ void ArcAppWindowLauncherController::OnTaskCreated( |
| const std::string& package_name, |
| const std::string& activity_name) { |
| DCHECK(!GetAppWindowForTask(task_id)); |
| + std::unique_ptr<TaskInfo> task_info( |
| + new TaskInfo(package_name, activity_name)); |
| + task_id_to_task_info_[task_id] = std::move(task_info); |
| - const std::string app_id = GetShelfAppIdFromArcAppId( |
| - ArcAppListPrefs::GetAppId(package_name, activity_name)); |
| - |
| - std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); |
| - RegisterApp(app_window.get()); |
| - |
| - task_id_to_app_window_[task_id] = std::move(app_window); |
| - |
| - for (auto window : observed_windows_) |
| - CheckForAppWindowWidget(window); |
| + for (auto* window : observed_windows_) |
| + MayAttachContollerToWindow(window); |
| } |
| void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| + task_id_to_task_info_.erase(task_id); |
| + |
| TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
| if (it == task_id_to_app_window_.end()) |
| return; |