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 d3d80af4098e70cf967eb808caea1a26930810fd..2057c077bd1a8a151e6cdc7f361de1e09c963b97 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 |
@@ -8,6 +8,7 @@ |
#include "ash/shelf/shelf_util.h" |
#include "ash/shell.h" |
#include "ash/wm/window_util.h" |
+#include "base/stl_util.h" |
#include "base/strings/stringprintf.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
@@ -123,7 +124,9 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
: ash::STATUS_RUNNING; |
AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); |
ash::ShelfID shelf_id = 0; |
- if (iter != app_controller_map_.end()) { |
+ std::string window_key = app_window->window_key(); |
+ |
+ if (!app_window->show_in_shelf() && iter != app_controller_map_.end()) { |
ExtensionAppWindowLauncherItemController* controller = iter->second; |
DCHECK(controller->app_id() == app_id); |
shelf_id = controller->shelf_id(); |
@@ -138,12 +141,24 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
owner()); |
controller->AddAppWindow(app_window); |
// If the app shelf id is not unique, and there is already a shelf |
- // item for this app id (e.g. pinned), use that shelf item. |
- if (app_shelf_id == app_id) { |
+ // item for this app id (e.g. pinned), use that shelf item, except for the |
+ // case when the showInShelf parameter is true. |
stevenjb
2016/06/14 18:33:21
This is confusing. We should have a comment in the
Andra Paraschiv
2016/06/28 07:04:46
Done.
|
+ if (!window_key.empty() && |
+ ContainsKey(window_id_to_shelf_id_map_, window_key)) { |
stevenjb
2016/06/14 18:33:21
This should be window_key_to_shelf_id_map_.
Andra Paraschiv
2016/06/28 07:04:46
Done.
|
+ shelf_id = window_id_to_shelf_id_map_[window_key]; |
stevenjb
2016/06/14 18:33:21
We are doing two lookups. We should get an iterato
Andra Paraschiv
2016/06/28 07:04:46
Done.
|
+ if (!owner()->IsPinned(shelf_id)) { |
stevenjb
2016/06/14 18:33:21
I'm not following what this is supposed to do. Why
Andra Paraschiv
2016/06/28 07:04:46
If a pinned window is closed, then unpinned and op
|
+ window_id_to_shelf_id_map_.erase(window_key); |
+ shelf_id = 0; |
+ } |
+ } |
+ else if (app_shelf_id == app_id && !app_window->show_in_shelf() && |
stevenjb
2016/06/14 18:33:21
else on previous line
Andra Paraschiv
2016/06/28 07:04:46
Done.
|
+ secondary_window_controller_map_.empty() && |
+ window_id_to_shelf_id_map_.empty()) { |
stevenjb
2016/06/14 18:33:21
Why test for an empty map? Couldn't a different ap
Andra Paraschiv
2016/06/28 07:04:46
Yes, you are right, thank you for this notice. The
|
shelf_id = |
ash::Shell::GetInstance()->GetShelfDelegate()->GetShelfIDForAppID( |
app_id); |
} |
+ |
if (shelf_id == 0) { |
shelf_id = owner()->CreateAppLauncherItem(controller, app_id, status); |
// Restore any existing app icon and flag as set. |
@@ -155,31 +170,64 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
} else { |
owner()->SetItemController(shelf_id, controller); |
} |
+ |
const std::string app_shelf_id = GetAppShelfId(app_window); |
- app_controller_map_[app_shelf_id] = controller; |
+ // We need to change the controller associated with the app if there is no |
+ // controller currently tied to the app shelf id (first window). |
+ if (!ContainsKey(app_controller_map_, app_shelf_id) && |
+ !app_window->show_in_shelf()) { |
+ app_controller_map_[app_shelf_id] = controller; |
+ } else if (app_window->show_in_shelf()) { |
+ secondary_window_controller_map_[window] = controller; |
+ } |
+ if (!window_key.empty()) { |
+ window_id_to_shelf_id_map_[window_key] = shelf_id; |
+ } |
} |
stevenjb
2016/06/14 18:33:21
Having 3 different maps in this code now is super
Andra Paraschiv
2016/06/21 09:04:13
We could use the window key to map to the shelf it
|
owner()->SetItemStatus(shelf_id, status); |
ash::SetShelfIDForWindow(shelf_id, window); |
} |
void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
- WindowToAppShelfIdMap::iterator iter1 = |
+ WindowToAppShelfIdMap::iterator shelf_id_iter = |
window_to_app_shelf_id_map_.find(window); |
- DCHECK(iter1 != window_to_app_shelf_id_map_.end()); |
- std::string app_shelf_id = iter1->second; |
- window_to_app_shelf_id_map_.erase(iter1); |
+ DCHECK(shelf_id_iter != window_to_app_shelf_id_map_.end()); |
+ std::string app_shelf_id = shelf_id_iter->second; |
+ window_to_app_shelf_id_map_.erase(shelf_id_iter); |
window->RemoveObserver(this); |
- AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
- DCHECK(iter2 != app_controller_map_.end()); |
- ExtensionAppWindowLauncherItemController* controller = iter2->second; |
+ AppControllerMap::iterator app_controller_iter = |
+ app_controller_map_.find(app_shelf_id); |
+ WindowControllerMap::iterator secondary_window_iter = |
+ secondary_window_controller_map_.find(window); |
+ DCHECK(app_controller_iter != app_controller_map_.end() || |
+ secondary_window_iter != secondary_window_controller_map_.end()); |
stevenjb
2016/06/14 18:33:21
I think we should be able to combine these maps. w
Andra Paraschiv
2016/06/28 07:04:46
We combined the app_controller_map and the seconda
|
+ ExtensionAppWindowLauncherItemController* controller; |
+ if (secondary_window_iter != secondary_window_controller_map_.end()) |
+ controller = secondary_window_iter->second; |
+ else |
+ controller = app_controller_iter->second; |
+ |
controller->RemoveWindow(controller->GetAppWindow(window)); |
if (controller->window_count() == 0) { |
// If this is the last window associated with the app shelf id, close the |
// shelf item. |
ash::ShelfID shelf_id = controller->shelf_id(); |
+ if (!owner()->IsPinned(shelf_id)) { |
+ for (WindowIdToShelfIdMap::const_iterator i = |
+ window_id_to_shelf_id_map_.begin(); |
+ i != window_id_to_shelf_id_map_.end(); ++i) { |
+ if (shelf_id == i->second) { |
+ window_id_to_shelf_id_map_.erase(i); |
+ break; |
+ } |
+ } |
stevenjb
2016/06/14 18:33:21
I think we ma have an stl util helper to do this i
Andra Paraschiv
2016/06/28 07:04:46
We should delete the shelf_id from the map for unp
|
+ } |
owner()->CloseLauncherItem(shelf_id); |
- app_controller_map_.erase(iter2); |
+ if (secondary_window_iter != secondary_window_controller_map_.end()) |
+ secondary_window_controller_map_.erase(secondary_window_iter); |
+ else |
+ app_controller_map_.erase(app_controller_iter); |
} |
} |
@@ -194,13 +242,17 @@ bool ExtensionAppWindowLauncherController::IsRegisteredApp( |
AppWindowLauncherItemController* |
ExtensionAppWindowLauncherController::ControllerForWindow( |
aura::Window* window) { |
- WindowToAppShelfIdMap::iterator iter1 = |
+ WindowToAppShelfIdMap::iterator shelf_id_iter = |
window_to_app_shelf_id_map_.find(window); |
- if (iter1 == window_to_app_shelf_id_map_.end()) |
- return nullptr; |
- std::string app_shelf_id = iter1->second; |
- AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
- if (iter2 == app_controller_map_.end()) |
+ if (shelf_id_iter == window_to_app_shelf_id_map_.end()) |
return nullptr; |
- return iter2->second; |
+ WindowControllerMap::iterator secondary_window_iter = |
+ secondary_window_controller_map_.find(window); |
+ if (secondary_window_iter != secondary_window_controller_map_.end()) |
+ return secondary_window_iter->second; |
+ AppControllerMap::iterator app_controller_iter = |
+ app_controller_map_.find(shelf_id_iter->second); |
+ if (app_controller_iter != app_controller_map_.end()) |
+ return app_controller_iter->second; |
+ return nullptr; |
} |