Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); | 354 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); |
| 355 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile()); | 355 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile()); |
| 356 } | 356 } |
| 357 #endif | 357 #endif |
| 358 | 358 |
| 359 ChromeLauncherController::ChromeLauncherController(Profile* profile, | 359 ChromeLauncherController::ChromeLauncherController(Profile* profile, |
| 360 ash::ShelfModel* model) | 360 ash::ShelfModel* model) |
| 361 : model_(model), | 361 : model_(model), |
| 362 item_delegate_manager_(NULL), | 362 item_delegate_manager_(NULL), |
| 363 profile_(profile), | 363 profile_(profile), |
| 364 extension_registry_(NULL), | |
| 364 app_sync_ui_state_(NULL), | 365 app_sync_ui_state_(NULL), |
| 365 ignore_persist_pinned_state_change_(false) { | 366 ignore_persist_pinned_state_change_(false) { |
| 366 if (!profile_) { | 367 if (!profile_) { |
| 367 // If no profile was passed, we take the currently active profile and use it | 368 // If no profile was passed, we take the currently active profile and use it |
| 368 // as the owner of the current desktop. | 369 // as the owner of the current desktop. |
| 369 // Use the original profile as on chromeos we may get a temporary off the | 370 // Use the original profile as on chromeos we may get a temporary off the |
| 370 // record profile, unless in guest session (where off the record profile is | 371 // record profile, unless in guest session (where off the record profile is |
| 371 // the right one). | 372 // the right one). |
| 372 Profile* active_profile = ProfileManager::GetActiveUserProfile(); | 373 Profile* active_profile = ProfileManager::GetActiveUserProfile(); |
| 373 profile_ = active_profile->IsGuestSession() ? active_profile : | 374 profile_ = active_profile->IsGuestSession() ? active_profile : |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 app_window_controller_.reset(new AppWindowLauncherController(this)); | 418 app_window_controller_.reset(new AppWindowLauncherController(this)); |
| 418 #endif | 419 #endif |
| 419 | 420 |
| 420 // Right now ash::Shell isn't created for tests. | 421 // Right now ash::Shell isn't created for tests. |
| 421 // TODO(mukai): Allows it to observe display change and write tests. | 422 // TODO(mukai): Allows it to observe display change and write tests. |
| 422 if (ash::Shell::HasInstance()) { | 423 if (ash::Shell::HasInstance()) { |
| 423 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 424 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
| 424 item_delegate_manager_ = | 425 item_delegate_manager_ = |
| 425 ash::Shell::GetInstance()->shelf_item_delegate_manager(); | 426 ash::Shell::GetInstance()->shelf_item_delegate_manager(); |
| 426 } | 427 } |
| 427 | |
| 428 notification_registrar_.Add( | |
|
James Cook
2014/09/12 20:35:35
+skuhne -- I'm not sure about the old code here.
Mr4D (OOO till 08-26)
2014/09/12 23:12:11
A closer look reviles that everything should be as
| |
| 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 } | 428 } |
| 437 | 429 |
| 438 ChromeLauncherController::~ChromeLauncherController() { | 430 ChromeLauncherController::~ChromeLauncherController() { |
| 439 // Reset the BrowserStatusMonitor as it has a weak pointer to this. | 431 // Reset the BrowserStatusMonitor as it has a weak pointer to this. |
| 440 browser_status_monitor_.reset(); | 432 browser_status_monitor_.reset(); |
| 441 | 433 |
| 442 // Reset the app window controller here since it has a weak pointer to this. | 434 // Reset the app window controller here since it has a weak pointer to this. |
| 443 app_window_controller_.reset(); | 435 app_window_controller_.reset(); |
| 444 | 436 |
| 445 for (std::set<ash::Shelf*>::iterator iter = shelves_.begin(); | 437 for (std::set<ash::Shelf*>::iterator iter = shelves_.begin(); |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 // Force on-screen keyboard to reset. | 1162 // Force on-screen keyboard to reset. |
| 1171 if (keyboard::IsKeyboardEnabled()) | 1163 if (keyboard::IsKeyboardEnabled()) |
| 1172 ash::Shell::GetInstance()->CreateKeyboard(); | 1164 ash::Shell::GetInstance()->CreateKeyboard(); |
| 1173 } | 1165 } |
| 1174 | 1166 |
| 1175 void ChromeLauncherController::AdditionalUserAddedToSession(Profile* profile) { | 1167 void ChromeLauncherController::AdditionalUserAddedToSession(Profile* profile) { |
| 1176 // Switch the running applications to the new user. | 1168 // Switch the running applications to the new user. |
| 1177 app_window_controller_->AdditionalUserAddedToSession(profile); | 1169 app_window_controller_->AdditionalUserAddedToSession(profile); |
| 1178 } | 1170 } |
| 1179 | 1171 |
| 1180 void ChromeLauncherController::Observe( | 1172 void ChromeLauncherController::OnExtensionLoaded( |
| 1181 int type, | 1173 content::BrowserContext* browser_context, |
| 1182 const content::NotificationSource& source, | 1174 const extensions::Extension* extension) { |
| 1183 const content::NotificationDetails& details) { | 1175 if (IsAppPinned(extension->id())) { |
| 1184 switch (type) { | 1176 // Clear and re-fetch to ensure icon is up-to-date. |
| 1185 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 1177 app_icon_loader_->ClearImage(extension->id()); |
| 1186 const Extension* extension = | 1178 app_icon_loader_->FetchImage(extension->id()); |
| 1187 content::Details<const Extension>(details).ptr(); | 1179 } |
| 1188 if (IsAppPinned(extension->id())) { | |
| 1189 // Clear and re-fetch to ensure icon is up-to-date. | |
| 1190 app_icon_loader_->ClearImage(extension->id()); | |
| 1191 app_icon_loader_->FetchImage(extension->id()); | |
| 1192 } | |
| 1193 | 1180 |
| 1194 UpdateAppLaunchersFromPref(); | 1181 UpdateAppLaunchersFromPref(); |
| 1195 break; | 1182 } |
| 1183 | |
| 1184 void ChromeLauncherController::OnExtensionUnloaded( | |
| 1185 content::BrowserContext* browser_context, | |
| 1186 const extensions::Extension* extension, | |
| 1187 extensions::UnloadedExtensionInfo::Reason reason) { | |
| 1188 const std::string& id = extension->id(); | |
| 1189 // Since we might have windowed apps of this type which might have | |
| 1190 // outstanding locks which needs to be removed. | |
| 1191 if (GetShelfIDForAppID(id) && | |
| 1192 reason == UnloadedExtensionInfo::REASON_UNINSTALL) { | |
|
Mr4D (OOO till 08-26)
2014/09/12 23:12:11
You should forward the profile to CloseWindowedApp
limasdf
2014/09/13 18:31:01
Done.
| |
| 1193 CloseWindowedAppsFromRemovedExtension(id); | |
| 1194 } | |
| 1195 | |
| 1196 if (IsAppPinned(id)) { | |
|
Mr4D (OOO till 08-26)
2014/09/12 23:12:11
DoUnpinAppWithID() should only be called if the pa
limasdf
2014/09/13 18:31:01
:: DoUnpinAppWithID() should only be called if the
| |
| 1197 if (reason == UnloadedExtensionInfo::REASON_UNINSTALL) { | |
| 1198 DoUnpinAppWithID(id); | |
| 1199 app_icon_loader_->ClearImage(id); | |
| 1200 } else { | |
| 1201 app_icon_loader_->UpdateImage(id); | |
| 1196 } | 1202 } |
| 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 } | 1203 } |
| 1221 } | 1204 } |
| 1222 | 1205 |
| 1223 void ChromeLauncherController::OnShelfAlignmentChanged( | 1206 void ChromeLauncherController::OnShelfAlignmentChanged( |
| 1224 aura::Window* root_window) { | 1207 aura::Window* root_window) { |
| 1225 const char* pref_value = NULL; | 1208 const char* pref_value = NULL; |
| 1226 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { | 1209 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { |
| 1227 case ash::SHELF_ALIGNMENT_BOTTOM: | 1210 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 1228 pref_value = ash::kShelfAlignmentBottom; | 1211 pref_value = ash::kShelfAlignmentBottom; |
| 1229 break; | 1212 break; |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2085 pref_change_registrar_.Add( | 2068 pref_change_registrar_.Add( |
| 2086 prefs::kShelfPreferences, | 2069 prefs::kShelfPreferences, |
| 2087 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, | 2070 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, |
| 2088 base::Unretained(this))); | 2071 base::Unretained(this))); |
| 2089 #if defined(OS_CHROMEOS) | 2072 #if defined(OS_CHROMEOS) |
| 2090 pref_change_registrar_.Add( | 2073 pref_change_registrar_.Add( |
| 2091 prefs::kTouchVirtualKeyboardEnabled, | 2074 prefs::kTouchVirtualKeyboardEnabled, |
| 2092 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs, | 2075 base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs, |
| 2093 base::Unretained(this))); | 2076 base::Unretained(this))); |
| 2094 #endif // defined(OS_CHROMEOS) | 2077 #endif // defined(OS_CHROMEOS) |
| 2078 | |
| 2079 extension_registry_ = extensions::ExtensionRegistry::Get(profile_); | |
|
James Cook
2014/09/12 20:35:35
Can you get rid of the extension_registry_ member
limasdf
2014/09/12 20:53:00
Done.
| |
| 2080 extension_registry_->AddObserver(this); | |
| 2095 } | 2081 } |
| 2096 | 2082 |
| 2097 void ChromeLauncherController::ReleaseProfile() { | 2083 void ChromeLauncherController::ReleaseProfile() { |
| 2098 if (app_sync_ui_state_) | 2084 if (app_sync_ui_state_) |
| 2099 app_sync_ui_state_->RemoveObserver(this); | 2085 app_sync_ui_state_->RemoveObserver(this); |
| 2100 | 2086 |
| 2087 if (extension_registry_) | |
| 2088 extension_registry_->RemoveObserver(this); | |
| 2089 extension_registry_ = NULL; | |
| 2090 | |
| 2101 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 2091 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
| 2102 | 2092 |
| 2103 pref_change_registrar_.RemoveAll(); | 2093 pref_change_registrar_.RemoveAll(); |
| 2104 } | 2094 } |
| OLD | NEW |