Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: extensions/shell/browser/shell_desktop_controller.cc

Issue 642383003: Add the ability to load multiple apps into app_shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/shell/browser/shell_desktop_controller.cc
diff --git a/extensions/shell/browser/shell_desktop_controller.cc b/extensions/shell/browser/shell_desktop_controller.cc
index 59e84a57a016d71402c789ac5c00c47474ce1240..1ec98c81c94a2f50bd7d04af473662d71ca947e5 100644
--- a/extensions/shell/browser/shell_desktop_controller.cc
+++ b/extensions/shell/browser/shell_desktop_controller.cc
@@ -4,6 +4,7 @@
#include "extensions/shell/browser/shell_desktop_controller.h"
+#include <algorithm>
#include <string>
#include <vector>
@@ -160,7 +161,7 @@ class AppsFocusRules : public wm::BaseFocusRules {
} // namespace
ShellDesktopController::ShellDesktopController()
- : app_window_client_(new ShellAppWindowClient), app_window_(NULL) {
+ : app_window_client_(new ShellAppWindowClient) {
extensions::AppWindowClient::Set(app_window_client_.get());
#if defined(OS_CHROMEOS)
@@ -191,8 +192,9 @@ aura::WindowTreeHost* ShellDesktopController::GetHost() {
AppWindow* ShellDesktopController::CreateAppWindow(
content::BrowserContext* context,
const Extension* extension) {
- app_window_ = new AppWindow(context, new ShellAppDelegate, extension);
- return app_window_;
+ app_windows_.push_back(
+ new AppWindow(context, new ShellAppDelegate, extension));
+ return app_windows_.back();
}
void ShellDesktopController::AddAppWindow(aura::Window* window) {
@@ -200,11 +202,20 @@ void ShellDesktopController::AddAppWindow(aura::Window* window) {
root_window->AddChild(window);
}
+void ShellDesktopController::RemoveAppWindow(AppWindow* window) {
+ auto iter = std::find(app_windows_.begin(), app_windows_.end(), window);
+ DCHECK(iter != app_windows_.end());
+ app_windows_.erase(iter);
+}
+
void ShellDesktopController::CloseAppWindows() {
- if (app_window_) {
- app_window_->GetBaseWindow()->Close(); // Close() deletes |app_window_|.
- app_window_ = NULL;
- }
+ // Create a copy of the window vector, because closing the windows will
+ // trigger RemoveAppWindow, which will invalidate the iterator.
+ // This vector should be small enough that this should not be an issue.
+ std::vector<AppWindow*> app_windows(app_windows_);
+ for (AppWindow* app_window : app_windows)
+ app_window->GetBaseWindow()->Close(); // Close() deletes |app_window|.
+ app_windows_.clear();
}
aura::Window* ShellDesktopController::GetDefaultParent(
« no previous file with comments | « extensions/shell/browser/shell_desktop_controller.h ('k') | extensions/shell/browser/shell_extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698