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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc

Issue 213193007: Simplifying launcher handling by removing an unnecessary data structure and some functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing unittest Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/desktop_background/desktop_background_controller.h" 10 #include "ash/desktop_background/desktop_background_controller.h"
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 void ChromeLauncherController::ToggleShelfAutoHideBehavior( 913 void ChromeLauncherController::ToggleShelfAutoHideBehavior(
914 aura::Window* root_window) { 914 aura::Window* root_window) {
915 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == 915 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
916 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 916 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
917 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : 917 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
918 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 918 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
919 SetShelfAutoHideBehaviorPrefs(behavior, root_window); 919 SetShelfAutoHideBehaviorPrefs(behavior, root_window);
920 return; 920 return;
921 } 921 }
922 922
923 void ChromeLauncherController::RemoveTabFromRunningApp(
924 WebContents* tab,
925 const std::string& app_id) {
926 web_contents_to_app_id_.erase(tab);
927 // BrowserShortcutLauncherItemController::UpdateBrowserItemState() will update
928 // the state when no application is associated with the tab.
929 if (app_id.empty())
930 return;
931
932 AppIDToWebContentsListMap::iterator i_app_id =
933 app_id_to_web_contents_list_.find(app_id);
934 if (i_app_id != app_id_to_web_contents_list_.end()) {
935 WebContentsList* tab_list = &i_app_id->second;
936 tab_list->remove(tab);
937 ash::ShelfItemStatus status = ash::STATUS_RUNNING;
938 if (tab_list->empty()) {
939 app_id_to_web_contents_list_.erase(i_app_id);
940 status = ash::STATUS_CLOSED;
941 }
942 ash::ShelfID id = GetShelfIDForAppID(app_id);
943 if (id)
944 SetItemStatus(id, status);
945 }
946 }
947
948 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, 923 void ChromeLauncherController::UpdateAppState(content::WebContents* contents,
949 AppState app_state) { 924 AppState app_state) {
950 std::string app_id = app_tab_helper_->GetAppID(contents); 925 std::string app_id = app_tab_helper_->GetAppID(contents);
951 926
952 // Check if the gMail app is loaded and it matches the given content. 927 // Check if the gMail app is loaded and it matches the given content.
953 // This special treatment is needed to address crbug.com/234268. 928 // This special treatment is needed to address crbug.com/234268.
954 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 929 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
955 app_id = kGmailAppId; 930 app_id = kGmailAppId;
956 931
957 // Check the old |app_id| for a tab. If the contents has changed we need to 932 // Check the old |app_id| for a tab. If the contents has changed we need to
958 // remove it from the previous app. 933 // remove it from the previous app.
959 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 934 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
960 std::string last_app_id = web_contents_to_app_id_[contents]; 935 std::string last_app_id = web_contents_to_app_id_[contents];
961 if (last_app_id != app_id) 936 if (last_app_id != app_id) {
962 RemoveTabFromRunningApp(contents, last_app_id); 937 ash::ShelfID id = GetShelfIDForAppID(last_app_id);
938 if (id) {
939 // Since GetAppState() will use |web_contents_to_app_id_| we remove
940 // the connection before calling it.
941 web_contents_to_app_id_.erase(contents);
942 SetItemStatus(id, GetAppState(last_app_id));
943 }
944 }
963 } 945 }
964 946
965 web_contents_to_app_id_[contents] = app_id; 947 if (app_state == APP_STATE_REMOVED)
948 web_contents_to_app_id_.erase(contents);
949 else
950 web_contents_to_app_id_[contents] = app_id;
966 951
967 if (app_state == APP_STATE_REMOVED) { 952 ash::ShelfID id = GetShelfIDForAppID(app_id);
968 // The tab has gone away. 953 if (id) {
969 RemoveTabFromRunningApp(contents, app_id); 954 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE ||
970 } else if (!app_id.empty()) { 955 app_state == APP_STATE_ACTIVE) ? ash::STATUS_ACTIVE :
971 WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]); 956 GetAppState(app_id));
972 WebContentsList::const_iterator i_tab =
973 std::find(tab_list.begin(), tab_list.end(), contents);
974
975 if (i_tab == tab_list.end())
976 tab_list.push_back(contents);
977
978 if (app_state == APP_STATE_INACTIVE || app_state == APP_STATE_ACTIVE) {
979 if (i_tab != tab_list.begin()) {
980 // Going to running state, but wasn't the front tab, indicating that a
981 // new tab has already become active.
982 return;
983 }
984 }
985
986 if (app_state == APP_STATE_ACTIVE || app_state == APP_STATE_WINDOW_ACTIVE) {
987 tab_list.remove(contents);
988 tab_list.push_front(contents);
989 }
990
991 ash::ShelfID id = GetShelfIDForAppID(app_id);
992 if (id) {
993 // If the window is active, mark the app as active.
994 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ?
995 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
996 }
997 } 957 }
998 } 958 }
999 959
1000 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( 960 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents(
1001 content::WebContents* contents) { 961 content::WebContents* contents) {
1002 DCHECK(contents); 962 DCHECK(contents);
1003 963
1004 std::string app_id = app_tab_helper_->GetAppID(contents); 964 std::string app_id = app_tab_helper_->GetAppID(contents);
1005 965
1006 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 966 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 alignment = ash::SHELF_ALIGNMENT_TOP; 1672 alignment = ash::SHELF_ALIGNMENT_TOP;
1713 ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter); 1673 ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter);
1714 } 1674 }
1715 } 1675 }
1716 1676
1717 void ChromeLauncherController::SetShelfBehaviorsFromPrefs() { 1677 void ChromeLauncherController::SetShelfBehaviorsFromPrefs() {
1718 SetShelfAutoHideBehaviorFromPrefs(); 1678 SetShelfAutoHideBehaviorFromPrefs();
1719 SetShelfAlignmentFromPrefs(); 1679 SetShelfAlignmentFromPrefs();
1720 } 1680 }
1721 1681
1722 WebContents* ChromeLauncherController::GetLastActiveWebContents( 1682 ash::ShelfItemStatus ChromeLauncherController::GetAppState(
1723 const std::string& app_id) { 1683 const::std::string& app_id) {
1724 AppIDToWebContentsListMap::iterator i = 1684 ash::ShelfItemStatus status = ash::STATUS_CLOSED;
1725 app_id_to_web_contents_list_.find(app_id); 1685 for (WebContentsToAppIDMap::iterator it = web_contents_to_app_id_.begin();
1726 if (i == app_id_to_web_contents_list_.end()) 1686 it != web_contents_to_app_id_.end();
1727 return NULL; 1687 ++it) {
1728 1688 if (it->second == app_id) {
1729 // There are many crash records (crbug.com/341250) which indicate that the 1689 Browser* browser = chrome::FindBrowserWithWebContents(it->first);
1730 // app_id_to_web_contents_list_ contains deleted content entries - so there 1690 // There should never be an item in our |web_contents_to_app_id_| list
1731 // must be a way that the content does not get properly updated. To fix 1691 // which got deleted already. If it is, it is likely that
1732 // M33 and M34 we filter out the invalid items here, but this should be 1692 // BrowserStatusMonitor forgot to inform us of that change.
1733 // addressed by a later patch correctly. Looking at the code however, the 1693 DCHECK(browser);
1734 // real culprit is possibly BrowserStatusMonitor::UpdateAppItemState which 1694 if (browser->window()->IsActive()) {
1735 // does not call "UpdateAppState(.., APP_STATE_REMOVED)" because due to a 1695 return browser->tab_strip_model()->GetActiveWebContents() == it->first ?
1736 // Browser::SwapTabContent operation it isn't able to get the browser. I 1696 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
1737 // think that the real patch is to call anyway when APP_STATE_REMOVED is 1697 } else {
1738 // requested, but for a backport that seems risky. 1698 status = ash::STATUS_RUNNING;
1739 WebContentsList* list = &i->second; 1699 }
1740 while (!list->empty()) { 1700 }
1741 WebContents* contents = *list->begin();
1742 if (chrome::FindBrowserWithWebContents(contents))
1743 return contents;
1744 list->erase(list->begin());
1745 // This might not be necessary, but since we do not know why the lists
1746 // diverged we also erase it since it cannot be correct either.
1747 web_contents_to_app_id_.erase(contents);
1748 } 1701 }
1749 app_id_to_web_contents_list_.erase(app_id); 1702 return status;
1750 return NULL;
1751 } 1703 }
1752 1704
1753 ash::ShelfID ChromeLauncherController::InsertAppLauncherItem( 1705 ash::ShelfID ChromeLauncherController::InsertAppLauncherItem(
1754 LauncherItemController* controller, 1706 LauncherItemController* controller,
1755 const std::string& app_id, 1707 const std::string& app_id,
1756 ash::ShelfItemStatus status, 1708 ash::ShelfItemStatus status,
1757 int index, 1709 int index,
1758 ash::ShelfItemType shelf_item_type) { 1710 ash::ShelfItemType shelf_item_type) {
1759 ash::ShelfID id = model_->next_id(); 1711 ash::ShelfID id = model_->next_id();
1760 CHECK(!HasItemController(id)); 1712 CHECK(!HasItemController(id));
1761 CHECK(controller); 1713 CHECK(controller);
1762 id_to_item_controller_map_[id] = controller; 1714 id_to_item_controller_map_[id] = controller;
1763 controller->set_shelf_id(id); 1715 controller->set_shelf_id(id);
1764 1716
1765 ash::ShelfItem item; 1717 ash::ShelfItem item;
1766 item.type = shelf_item_type; 1718 item.type = shelf_item_type;
1767 item.image = extensions::IconsInfo::GetDefaultAppIcon(); 1719 item.image = extensions::IconsInfo::GetDefaultAppIcon();
1768 1720
1769 WebContents* active_tab = GetLastActiveWebContents(app_id); 1721 ash::ShelfItemStatus new_state = GetAppState(app_id);
1770 if (active_tab) { 1722 if (new_state != ash::STATUS_CLOSED)
1771 Browser* browser = chrome::FindBrowserWithWebContents(active_tab); 1723 status = new_state;
1772 DCHECK(browser); 1724
1773 if (browser->window()->IsActive())
1774 status = ash::STATUS_ACTIVE;
1775 else
1776 status = ash::STATUS_RUNNING;
1777 }
1778 item.status = status; 1725 item.status = status;
1779 1726
1780 model_->AddAt(index, item); 1727 model_->AddAt(index, item);
1781 1728
1782 app_icon_loader_->FetchImage(app_id); 1729 app_icon_loader_->FetchImage(app_id);
1783 1730
1784 SetShelfItemDelegate(id, controller); 1731 SetShelfItemDelegate(id, controller);
1785 1732
1786 return id; 1733 return id;
1787 } 1734 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 } 2005 }
2059 2006
2060 void ChromeLauncherController::ReleaseProfile() { 2007 void ChromeLauncherController::ReleaseProfile() {
2061 if (app_sync_ui_state_) 2008 if (app_sync_ui_state_)
2062 app_sync_ui_state_->RemoveObserver(this); 2009 app_sync_ui_state_->RemoveObserver(this);
2063 2010
2064 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 2011 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
2065 2012
2066 pref_change_registrar_.RemoveAll(); 2013 pref_change_registrar_.RemoveAll();
2067 } 2014 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698