| 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 8ccca6d8158d98a048a1e4b2c52d4bb0da445ccf..74569ea5d719c7df59f59998a9c740092ba864af 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
|
| @@ -247,15 +247,6 @@ 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)
|
| @@ -298,7 +289,7 @@ void ArcAppWindowLauncherController::ActiveUserChanged(
|
| .GetUserEmail()) {
|
| RegisterApp(app_window);
|
| } else {
|
| - UnregisterApp(app_window);
|
| + UnregisterApp(app_window, true);
|
| }
|
| }
|
| }
|
| @@ -331,11 +322,17 @@ void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
|
| observed_windows_.erase(it);
|
| window->RemoveObserver(this);
|
|
|
| - for (auto& it : task_id_to_app_window_) {
|
| - if (it.second->GetNativeWindow() == window) {
|
| - OnTaskDestroyed(it.second->task_id());
|
| - break;
|
| - }
|
| + auto it_app_window =
|
| + std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(),
|
| + [window](const TaskIdToAppWindow::value_type& pair) {
|
| + return pair.second->GetNativeWindow() == window;
|
| + });
|
| + if (it_app_window != task_id_to_app_window_.end()) {
|
| + // Note, window may be recreated in some cases, so do not close controller
|
| + // on window destroying. Controller will be closed onTaskDestroyed event
|
| + // which is generated when actual task is destroyed.
|
| + UnregisterApp(it_app_window->second.get(), false);
|
| + task_id_to_app_window_.erase(it_app_window);
|
| }
|
| }
|
|
|
| @@ -373,14 +370,11 @@ void ArcAppWindowLauncherController::MayAttachContollerToWindow(
|
| 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())
|
| + TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
|
| + if (it == task_id_to_shelf_app_id_.end())
|
| return;
|
|
|
| - const TaskInfo& task_info = *it->second;
|
| - const std::string app_id =
|
| - GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId(
|
| - task_info.package_name, task_info.activity_name));
|
| + const std::string& app_id = it->second;
|
|
|
| std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this));
|
| app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window));
|
| @@ -396,9 +390,6 @@ void ArcAppWindowLauncherController::MayAttachContollerToWindow(
|
| 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(
|
| @@ -434,25 +425,36 @@ 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);
|
| + task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId(
|
| + ArcAppListPrefs::GetAppId(package_name, activity_name));
|
|
|
| for (auto* window : observed_windows_)
|
| MayAttachContollerToWindow(window);
|
| }
|
|
|
| void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
|
| - task_id_to_task_info_.erase(task_id);
|
| + auto it = task_id_to_app_window_.find(task_id);
|
| + if (it != task_id_to_app_window_.end()) {
|
| + AppWindow* app_window = it->second.get();
|
| + UnregisterApp(app_window, true);
|
| + task_id_to_app_window_.erase(it);
|
| + }
|
|
|
| - TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id);
|
| - if (it == task_id_to_app_window_.end())
|
| + // Check if we may close controller now, at this point we can safely remove
|
| + // controllers without window.
|
| + auto it_app_id = task_id_to_shelf_app_id_.find(task_id);
|
| + if (it_app_id == task_id_to_shelf_app_id_.end())
|
| return;
|
|
|
| - AppWindow* app_window = it->second.get();
|
| - UnregisterApp(app_window);
|
| + const std::string& app_id = it_app_id->second;
|
| + AppControllerMap::iterator it_controller = app_controller_map_.find(app_id);
|
| + if (it_controller != app_controller_map_.end() &&
|
| + !it_controller->second->window_count()) {
|
| + owner()->CloseLauncherItem(it_controller->second->shelf_id());
|
| + app_controller_map_.erase(it_controller);
|
| + }
|
|
|
| - task_id_to_app_window_.erase(it);
|
| + task_id_to_shelf_app_id_.erase(it_app_id);
|
| }
|
|
|
| void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
|
| @@ -592,7 +594,8 @@ void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) {
|
| app_window->set_shelf_id(shelf_id);
|
| }
|
|
|
| -void ArcAppWindowLauncherController::UnregisterApp(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);
|
| @@ -600,7 +603,7 @@ void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window) {
|
|
|
| ArcAppWindowLauncherItemController* controller = it->second;
|
| controller->RemoveWindow(app_window);
|
| - if (!controller->window_count()) {
|
| + if (close_controller && !controller->window_count()) {
|
| ash::ShelfID shelf_id = app_window->shelf_id();
|
| owner()->CloseLauncherItem(shelf_id);
|
| app_controller_map_.erase(it);
|
|
|