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

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

Issue 565213002: ChromeLaunchController does proper action when extension unloaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: close window, unpin depending on profile Created 6 years, 3 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
« 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 app_window_controller_.reset(new AppWindowLauncherController(this)); 417 app_window_controller_.reset(new AppWindowLauncherController(this));
418 #endif 418 #endif
419 419
420 // Right now ash::Shell isn't created for tests. 420 // Right now ash::Shell isn't created for tests.
421 // TODO(mukai): Allows it to observe display change and write tests. 421 // TODO(mukai): Allows it to observe display change and write tests.
422 if (ash::Shell::HasInstance()) { 422 if (ash::Shell::HasInstance()) {
423 ash::Shell::GetInstance()->display_controller()->AddObserver(this); 423 ash::Shell::GetInstance()->display_controller()->AddObserver(this);
424 item_delegate_manager_ = 424 item_delegate_manager_ =
425 ash::Shell::GetInstance()->shelf_item_delegate_manager(); 425 ash::Shell::GetInstance()->shelf_item_delegate_manager();
426 } 426 }
427
428 notification_registrar_.Add(
429 this,
430 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
431 content::Source<Profile>(profile_));
432 notification_registrar_.Add(
433 this,
434 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
435 content::Source<Profile>(profile_));
436 } 427 }
437 428
438 ChromeLauncherController::~ChromeLauncherController() { 429 ChromeLauncherController::~ChromeLauncherController() {
439 // Reset the BrowserStatusMonitor as it has a weak pointer to this. 430 // Reset the BrowserStatusMonitor as it has a weak pointer to this.
440 browser_status_monitor_.reset(); 431 browser_status_monitor_.reset();
441 432
442 // Reset the app window controller here since it has a weak pointer to this. 433 // Reset the app window controller here since it has a weak pointer to this.
443 app_window_controller_.reset(); 434 app_window_controller_.reset();
444 435
445 for (std::set<ash::Shelf*>::iterator iter = shelves_.begin(); 436 for (std::set<ash::Shelf*>::iterator iter = shelves_.begin();
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 // Force on-screen keyboard to reset. 1161 // Force on-screen keyboard to reset.
1171 if (keyboard::IsKeyboardEnabled()) 1162 if (keyboard::IsKeyboardEnabled())
1172 ash::Shell::GetInstance()->CreateKeyboard(); 1163 ash::Shell::GetInstance()->CreateKeyboard();
1173 } 1164 }
1174 1165
1175 void ChromeLauncherController::AdditionalUserAddedToSession(Profile* profile) { 1166 void ChromeLauncherController::AdditionalUserAddedToSession(Profile* profile) {
1176 // Switch the running applications to the new user. 1167 // Switch the running applications to the new user.
1177 app_window_controller_->AdditionalUserAddedToSession(profile); 1168 app_window_controller_->AdditionalUserAddedToSession(profile);
1178 } 1169 }
1179 1170
1180 void ChromeLauncherController::Observe( 1171 void ChromeLauncherController::OnExtensionLoaded(
1181 int type, 1172 content::BrowserContext* browser_context,
1182 const content::NotificationSource& source, 1173 const Extension* extension) {
1183 const content::NotificationDetails& details) { 1174 if (IsAppPinned(extension->id())) {
1184 switch (type) { 1175 // Clear and re-fetch to ensure icon is up-to-date.
1185 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { 1176 app_icon_loader_->ClearImage(extension->id());
1186 const Extension* extension = 1177 app_icon_loader_->FetchImage(extension->id());
1187 content::Details<const Extension>(details).ptr(); 1178 }
1188 if (IsAppPinned(extension->id())) { 1179
1189 // Clear and re-fetch to ensure icon is up-to-date. 1180 UpdateAppLaunchersFromPref();
1190 app_icon_loader_->ClearImage(extension->id()); 1181 }
1191 app_icon_loader_->FetchImage(extension->id()); 1182
1183 void ChromeLauncherController::OnExtensionUnloaded(
1184 content::BrowserContext* browser_context,
1185 const Extension* extension,
1186 UnloadedExtensionInfo::Reason reason) {
1187 const std::string& id = extension->id();
1188 const Profile* profile = Profile::FromBrowserContext(browser_context);
1189
1190 // Since we might have windowed apps of this type which might have
1191 // outstanding locks which needs to be removed.
1192 if (GetShelfIDForAppID(id) &&
1193 reason == UnloadedExtensionInfo::REASON_UNINSTALL) {
1194 CloseWindowedAppsFromRemovedExtension(id, profile);
1195 }
1196
1197 if (IsAppPinned(id)) {
1198 if (reason == UnloadedExtensionInfo::REASON_UNINSTALL) {
1199 if (profile == profile_) {
1200 DoUnpinAppWithID(id);
1192 } 1201 }
1193 1202 app_icon_loader_->ClearImage(id);
1194 UpdateAppLaunchersFromPref(); 1203 } else {
1195 break; 1204 app_icon_loader_->UpdateImage(id);
1196 } 1205 }
1197 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
1198 const content::Details<UnloadedExtensionInfo>& unload_info(details);
1199 const Extension* extension = unload_info->extension;
1200 const std::string& id = extension->id();
1201 // Since we might have windowed apps of this type which might have
1202 // outstanding locks which needs to be removed.
1203 if (GetShelfIDForAppID(id) &&
1204 unload_info->reason == UnloadedExtensionInfo::REASON_UNINSTALL) {
1205 CloseWindowedAppsFromRemovedExtension(id);
1206 }
1207
1208 if (IsAppPinned(id)) {
1209 if (unload_info->reason == UnloadedExtensionInfo::REASON_UNINSTALL) {
1210 DoUnpinAppWithID(id);
1211 app_icon_loader_->ClearImage(id);
1212 } else {
1213 app_icon_loader_->UpdateImage(id);
1214 }
1215 }
1216 break;
1217 }
1218 default:
1219 NOTREACHED() << "Unexpected notification type=" << type;
1220 } 1206 }
1221 } 1207 }
1222 1208
1223 void ChromeLauncherController::OnShelfAlignmentChanged( 1209 void ChromeLauncherController::OnShelfAlignmentChanged(
1224 aura::Window* root_window) { 1210 aura::Window* root_window) {
1225 const char* pref_value = NULL; 1211 const char* pref_value = NULL;
1226 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { 1212 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) {
1227 case ash::SHELF_ALIGNMENT_BOTTOM: 1213 case ash::SHELF_ALIGNMENT_BOTTOM:
1228 pref_value = ash::kShelfAlignmentBottom; 1214 pref_value = ash::kShelfAlignmentBottom;
1229 break; 1215 break;
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 } 1996 }
2011 1997
2012 bool ChromeLauncherController::IsIncognito( 1998 bool ChromeLauncherController::IsIncognito(
2013 const content::WebContents* web_contents) const { 1999 const content::WebContents* web_contents) const {
2014 const Profile* profile = 2000 const Profile* profile =
2015 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 2001 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2016 return profile->IsOffTheRecord() && !profile->IsGuestSession(); 2002 return profile->IsOffTheRecord() && !profile->IsGuestSession();
2017 } 2003 }
2018 2004
2019 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( 2005 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension(
2020 const std::string& app_id) { 2006 const std::string& app_id,
2007 const Profile* profile) {
2021 // This function cannot rely on the controller's enumeration functionality 2008 // This function cannot rely on the controller's enumeration functionality
2022 // since the extension has already be unloaded. 2009 // since the extension has already be unloaded.
2023 const BrowserList* ash_browser_list = 2010 const BrowserList* ash_browser_list =
2024 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 2011 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
2025 std::vector<Browser*> browser_to_close; 2012 std::vector<Browser*> browser_to_close;
2026 for (BrowserList::const_reverse_iterator 2013 for (BrowserList::const_reverse_iterator
2027 it = ash_browser_list->begin_last_active(); 2014 it = ash_browser_list->begin_last_active();
2028 it != ash_browser_list->end_last_active(); ++it) { 2015 it != ash_browser_list->end_last_active(); ++it) {
2029 Browser* browser = *it; 2016 Browser* browser = *it;
2030 if (!browser->is_type_tabbed() && 2017 if (!browser->is_type_tabbed() && browser->is_type_popup() &&
2031 browser->is_type_popup() &&
2032 browser->is_app() && 2018 browser->is_app() &&
2033 app_id == web_app::GetExtensionIdFromApplicationName( 2019 app_id ==
2034 browser->app_name())) { 2020 web_app::GetExtensionIdFromApplicationName(browser->app_name()) &&
2021 profile == browser->profile()) {
2035 browser_to_close.push_back(browser); 2022 browser_to_close.push_back(browser);
2036 } 2023 }
2037 } 2024 }
2038 while (!browser_to_close.empty()) { 2025 while (!browser_to_close.empty()) {
2039 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 2026 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
2040 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 2027 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
2041 browser_to_close.pop_back(); 2028 browser_to_close.pop_back();
2042 } 2029 }
2043 } 2030 }
2044 2031
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 pref_change_registrar_.Add( 2072 pref_change_registrar_.Add(
2086 prefs::kShelfPreferences, 2073 prefs::kShelfPreferences,
2087 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, 2074 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
2088 base::Unretained(this))); 2075 base::Unretained(this)));
2089 #if defined(OS_CHROMEOS) 2076 #if defined(OS_CHROMEOS)
2090 pref_change_registrar_.Add( 2077 pref_change_registrar_.Add(
2091 prefs::kTouchVirtualKeyboardEnabled, 2078 prefs::kTouchVirtualKeyboardEnabled,
2092 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs, 2079 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs,
2093 base::Unretained(this))); 2080 base::Unretained(this)));
2094 #endif // defined(OS_CHROMEOS) 2081 #endif // defined(OS_CHROMEOS)
2082
2083 extensions::ExtensionRegistry::Get(profile_)->AddObserver(this);
2095 } 2084 }
2096 2085
2097 void ChromeLauncherController::ReleaseProfile() { 2086 void ChromeLauncherController::ReleaseProfile() {
2098 if (app_sync_ui_state_) 2087 if (app_sync_ui_state_)
2099 app_sync_ui_state_->RemoveObserver(this); 2088 app_sync_ui_state_->RemoveObserver(this);
2100 2089
2090 extensions::ExtensionRegistry::Get(profile_)->RemoveObserver(this);
2091
2101 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); 2092 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this);
2102 2093
2103 pref_change_registrar_.RemoveAll(); 2094 pref_change_registrar_.RemoveAll();
2104 } 2095 }
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