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

Unified Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc

Issue 12022002: Fixing activation states from the new launcher. Also adding a whole bunch of unit tests for the new… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgotten to add file to repository Created 7 years, 11 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: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc
index 348833146b42e4046d48387c9c8a9ff287fdb95e..f6a9a15e0a0bf0a8b4df11e83f61eadef7defa05 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc
@@ -282,28 +282,7 @@ void ChromeLauncherControllerPerApp::SetItemStatus(
if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
return;
}
- // Determine the new browser's active state and change if necessary.
- int browser_index = -1;
- for (size_t index = 0; index < model_->items().size() && browser_index == -1;
- index++) {
- if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
- browser_index = index;
- }
- DCHECK(browser_index >= 0);
- ash::LauncherItem browser_item = model_->items()[browser_index];
- ash::LauncherItemStatus browser_status = browser_item.status;
- // See if the active window is a browser.
- if (chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())) {
- browser_status = ash::STATUS_ACTIVE;
- } else if (!BrowserList::empty()) {
- browser_status = ash::STATUS_RUNNING;
- } else {
- browser_status = ash::STATUS_CLOSED;
- }
- if (browser_status != browser_item.status) {
- browser_item.status = browser_status;
- model_->Set(browser_index, browser_item);
- }
+ UpdateBrowserItemStatus();
}
void ChromeLauncherControllerPerApp::SetItemController(
@@ -441,8 +420,14 @@ void ChromeLauncherControllerPerApp::ActivateApp(const std::string& app_id,
return;
}
- // Otherwise launch the app.
- LaunchApp(app_id, event_flags);
+ // Create a temporary application launcher item and use it to see if there are
+ // running instances.
+ scoped_ptr<AppShortcutLauncherItemController> app_controller(
+ new AppShortcutLauncherItemController(app_id, this));
+ if (!app_controller->GetRunningApplications().empty())
+ app_controller->Activate();
+ else
+ LaunchApp(app_id, event_flags);
}
extensions::ExtensionPrefs::LaunchType
@@ -678,8 +663,12 @@ void ChromeLauncherControllerPerApp::UpdateAppState(
RemoveTabFromRunningApp(contents, last_app_id);
}
- if (app_id.empty())
+ if (app_id.empty()) {
+ // Even if there is no application running, we should update the activation
+ // state of the associated browser.
+ UpdateBrowserItemStatus();
return;
+ }
web_contents_to_app_id_[contents] = app_id;
@@ -995,6 +984,52 @@ ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest(
return id_to_item_controller_map_[id]->app_id();
}
+void ChromeLauncherControllerPerApp::UpdateBrowserItemStatus() {
+ // Determine the new browser's active state and change if necessary.
+ int browser_index = -1;
+ for (size_t index = 0; index < model_->items().size() && browser_index == -1;
+ index++) {
+ if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
+ browser_index = index;
+ }
+ DCHECK(browser_index >= 0);
+ ash::LauncherItem browser_item = model_->items()[browser_index];
+ ash::LauncherItemStatus browser_status = browser_item.status;
+ // See if the active window is a browser.
+ aura::Window* window = ash::wm::GetActiveWindow();
+ if (window && chrome::FindBrowserWithWindow(window)) {
+ browser_status = ash::STATUS_ACTIVE;
+ } else if (BrowserIsRunning()) {
+ browser_status = ash::STATUS_RUNNING;
+ } else {
+ browser_status = ash::STATUS_CLOSED;
+ }
+ if (browser_status != browser_item.status) {
+ browser_item.status = browser_status;
+ model_->Set(browser_index, browser_item);
+ }
+}
+
+bool ChromeLauncherControllerPerApp::BrowserIsRunning() {
+ if (BrowserList::empty())
+ return false;
+
+ // If there is only one browser left, we might have been called while the
+ // last browser is shutting down. In that case we need to do more checks.
+ // If on the other hand there are more browsers still running, we will get
+ // called again when the others are going down and are safe to say that
+ // there are still browsers running.
+ if (BrowserList::size() > 1)
+ return true;
+
+ Browser* browser = *BrowserList::begin();
+ TabStripModel* tab_strip = browser->tab_strip_model();
+ DCHECK(tab_strip);
+
+ // The browser active if it is not trying to close all tabs.
sky 2013/01/17 23:59:09 is active. Also, is closing_all true if an unload
Mr4D (OOO till 08-26) 2013/01/18 17:46:08 Added now global observer instead. Also changed co
+ return !tab_strip->closing_all();
+}
+
Profile* ChromeLauncherControllerPerApp::GetProfileForNewWindows() {
return ProfileManager::GetDefaultProfileOrOffTheRecord();
}

Powered by Google App Engine
This is Rietveld 408576698