| Index: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc
|
| diff --git a/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc
|
| index 1e0671732cdbb1c0120906da54121007be8f9530..2060935035a032cf6d0cbfd9817a89945ed700f6 100644
|
| --- a/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc
|
| +++ b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc
|
| @@ -4,8 +4,9 @@
|
|
|
| #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.h"
|
|
|
| +#include "ash/public/cpp/shelf_types.h"
|
| +#include "ash/public/cpp/window_properties.h"
|
| #include "ash/shelf/shelf_model.h"
|
| -#include "ash/wm/window_properties.h"
|
| #include "ash/wm/window_util.h"
|
| #include "ash/wm_window.h"
|
| #include "base/stl_util.h"
|
| @@ -25,7 +26,8 @@ using extensions::AppWindowRegistry;
|
|
|
| namespace {
|
|
|
| -std::string GetLaunchId(AppWindow* app_window) {
|
| +// Get the ShelfID for a given |app_window|.
|
| +ash::ShelfID GetShelfId(AppWindow* app_window) {
|
| // Set launch_id default value to an empty string. If showInShelf parameter
|
| // is true or the window type is panel and the window key is not empty, its
|
| // value is appended to the launch_id. Otherwise, if the window key is
|
| @@ -37,14 +39,7 @@ std::string GetLaunchId(AppWindow* app_window) {
|
| else
|
| launch_id = base::StringPrintf("%d", app_window->session_id().id());
|
| }
|
| - return launch_id;
|
| -}
|
| -
|
| -std::string GetAppShelfId(AppWindow* app_window) {
|
| - // Set app_shelf_id value to app_id and then append launch_id.
|
| - std::string app_id = app_window->extension_id();
|
| - std::string launch_id = GetLaunchId(app_window);
|
| - return app_id + launch_id;
|
| + return ash::ShelfID(app_window->extension_id(), launch_id);
|
| }
|
|
|
| } // namespace
|
| @@ -58,15 +53,11 @@ ExtensionAppWindowLauncherController::ExtensionAppWindowLauncherController(
|
| }
|
|
|
| ExtensionAppWindowLauncherController::~ExtensionAppWindowLauncherController() {
|
| - for (std::set<AppWindowRegistry*>::iterator it = registry_.begin();
|
| - it != registry_.end(); ++it)
|
| - (*it)->RemoveObserver(this);
|
| -
|
| - for (WindowToAppShelfIdMap::iterator iter =
|
| - window_to_app_shelf_id_map_.begin();
|
| - iter != window_to_app_shelf_id_map_.end(); ++iter) {
|
| - iter->first->RemoveObserver(this);
|
| - }
|
| + for (extensions::AppWindowRegistry* iter : registry_)
|
| + iter->RemoveObserver(this);
|
| +
|
| + for (const auto& iter : window_to_shelf_id_map_)
|
| + iter.first->RemoveObserver(this);
|
| }
|
|
|
| void ExtensionAppWindowLauncherController::AdditionalUserAddedToSession(
|
| @@ -87,8 +78,8 @@ void ExtensionAppWindowLauncherController::AdditionalUserAddedToSession(
|
|
|
| void ExtensionAppWindowLauncherController::OnAppWindowIconChanged(
|
| AppWindow* app_window) {
|
| - const std::string app_shelf_id = GetAppShelfId(app_window);
|
| - AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id);
|
| + const ash::ShelfID shelf_id = GetShelfId(app_window);
|
| + AppControllerMap::iterator iter = app_controller_map_.find(shelf_id);
|
| if (iter == app_controller_map_.end())
|
| return;
|
|
|
| @@ -127,79 +118,68 @@ void ExtensionAppWindowLauncherController::OnWindowDestroying(
|
| }
|
|
|
| void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) {
|
| + const ash::ShelfID shelf_id = GetShelfId(app_window);
|
| + DCHECK(!shelf_id.IsNull());
|
| + aura::Window* window = app_window->GetNativeWindow();
|
| + window->SetProperty(ash::kShelfIDKey, new ash::ShelfID(shelf_id));
|
| +
|
| // Windows created by IME extension should be treated the same way as the
|
| // virtual keyboard window, which does not register itself in launcher.
|
| // Ash's ShelfWindowWatcher handles app panel windows separately.
|
| if (app_window->is_ime_window() || app_window->window_type_is_panel())
|
| return;
|
|
|
| - aura::Window* window = app_window->GetNativeWindow();
|
| // Get the app's shelf identifier and add an entry to the map.
|
| - DCHECK(window_to_app_shelf_id_map_.find(window) ==
|
| - window_to_app_shelf_id_map_.end());
|
| - const std::string app_shelf_id = GetAppShelfId(app_window);
|
| - window_to_app_shelf_id_map_[window] = app_shelf_id;
|
| + DCHECK_EQ(window_to_shelf_id_map_.count(window), 0u);
|
| + window_to_shelf_id_map_[window] = shelf_id;
|
| window->AddObserver(this);
|
|
|
| // Find or create an item controller and launcher item.
|
| - std::string app_id = app_window->extension_id();
|
| ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window)
|
| ? ash::STATUS_ACTIVE
|
| : ash::STATUS_RUNNING;
|
| AppControllerMap::iterator app_controller_iter =
|
| - app_controller_map_.find(app_shelf_id);
|
| - ash::ShelfID shelf_id = 0;
|
| + app_controller_map_.find(shelf_id);
|
|
|
| if (app_controller_iter != app_controller_map_.end()) {
|
| ExtensionAppWindowLauncherItemController* controller =
|
| app_controller_iter->second;
|
| - DCHECK(controller->app_id() == app_id);
|
| - shelf_id = controller->shelf_id();
|
| + DCHECK_EQ(controller->app_id(), shelf_id.app_id);
|
| controller->AddAppWindow(app_window);
|
| } else {
|
| - std::string launch_id = GetLaunchId(app_window);
|
| std::unique_ptr<ExtensionAppWindowLauncherItemController> controller =
|
| - base::MakeUnique<ExtensionAppWindowLauncherItemController>(
|
| - ash::AppLaunchId(app_id, launch_id));
|
| - ExtensionAppWindowLauncherItemController* item_controller =
|
| - controller.get();
|
| -
|
| + base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id);
|
| + app_controller_map_[shelf_id] = controller.get();
|
| controller->AddAppWindow(app_window);
|
| - // If there is already a shelf id mapped to this AppLaunchId (e.g. pinned),
|
| - // use that shelf item.
|
| - shelf_id = owner()->GetShelfIDForAppIDAndLaunchID(app_id, launch_id);
|
|
|
| - if (shelf_id == 0) {
|
| - shelf_id = owner()->CreateAppLauncherItem(std::move(controller), status);
|
| + // Check for any existing pinned shelf item with a matching |shelf_id|.
|
| + const int item_index = owner()->shelf_model()->ItemIndexByID(shelf_id);
|
| + if (item_index < 0) {
|
| + owner()->CreateAppLauncherItem(std::move(controller), status);
|
| // Restore any existing app icon and flag as set.
|
| if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) {
|
| owner()->SetLauncherItemImage(shelf_id,
|
| app_window->app_icon().AsImageSkia());
|
| - item_controller->set_image_set_by_controller(true);
|
| + app_controller_map_[shelf_id]->set_image_set_by_controller(true);
|
| }
|
| } else {
|
| owner()->shelf_model()->SetShelfItemDelegate(shelf_id,
|
| std::move(controller));
|
| }
|
| -
|
| - // We need to change the controller associated with app_shelf_id.
|
| - app_controller_map_[app_shelf_id] = item_controller;
|
| }
|
| +
|
| owner()->SetItemStatus(shelf_id, status);
|
| - ash::WmWindow::Get(window)->aura_window()->SetProperty(ash::kShelfIDKey,
|
| - shelf_id);
|
| }
|
|
|
| void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) {
|
| - WindowToAppShelfIdMap::iterator window_iter =
|
| - window_to_app_shelf_id_map_.find(window);
|
| - DCHECK(window_iter != window_to_app_shelf_id_map_.end());
|
| - std::string app_shelf_id = window_iter->second;
|
| - window_to_app_shelf_id_map_.erase(window_iter);
|
| + const auto window_iter = window_to_shelf_id_map_.find(window);
|
| + DCHECK(window_iter != window_to_shelf_id_map_.end());
|
| + ash::ShelfID shelf_id = window_iter->second;
|
| + window_to_shelf_id_map_.erase(window_iter);
|
| window->RemoveObserver(this);
|
|
|
| AppControllerMap::iterator app_controller_iter =
|
| - app_controller_map_.find(app_shelf_id);
|
| + app_controller_map_.find(shelf_id);
|
| DCHECK(app_controller_iter != app_controller_map_.end());
|
| ExtensionAppWindowLauncherItemController* controller;
|
| controller = app_controller_iter->second;
|
| @@ -208,7 +188,6 @@ void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) {
|
| if (controller->window_count() == 0) {
|
| // If this is the last window associated with the app window shelf id,
|
| // close the shelf item.
|
| - ash::ShelfID shelf_id = controller->shelf_id();
|
| owner()->CloseLauncherItem(shelf_id);
|
| app_controller_map_.erase(app_controller_iter);
|
| }
|
| @@ -216,8 +195,7 @@ void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) {
|
|
|
| bool ExtensionAppWindowLauncherController::IsRegisteredApp(
|
| aura::Window* window) {
|
| - return window_to_app_shelf_id_map_.find(window) !=
|
| - window_to_app_shelf_id_map_.end();
|
| + return window_to_shelf_id_map_.find(window) != window_to_shelf_id_map_.end();
|
| }
|
|
|
| // Private Methods
|
| @@ -225,13 +203,11 @@ bool ExtensionAppWindowLauncherController::IsRegisteredApp(
|
| AppWindowLauncherItemController*
|
| ExtensionAppWindowLauncherController::ControllerForWindow(
|
| aura::Window* window) {
|
| - WindowToAppShelfIdMap::iterator window_iter =
|
| - window_to_app_shelf_id_map_.find(window);
|
| - if (window_iter == window_to_app_shelf_id_map_.end())
|
| + const auto window_iter = window_to_shelf_id_map_.find(window);
|
| + if (window_iter == window_to_shelf_id_map_.end())
|
| return nullptr;
|
| - AppControllerMap::iterator app_controller_iter =
|
| - app_controller_map_.find(window_iter->second);
|
| - if (app_controller_iter == app_controller_map_.end())
|
| + const auto controller_iter = app_controller_map_.find(window_iter->second);
|
| + if (controller_iter == app_controller_map_.end())
|
| return nullptr;
|
| - return app_controller_iter->second;
|
| + return controller_iter->second;
|
| }
|
|
|