| 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 "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
| 8 #include "ash/public/cpp/shelf_item.h" | 8 #include "ash/public/cpp/shelf_item.h" |
| 9 #include "ash/public/interfaces/constants.mojom.h" | 9 #include "ash/public/interfaces/constants.mojom.h" |
| 10 #include "ash/resources/grit/ash_resources.h" | 10 #include "ash/resources/grit/ash_resources.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 AppShortcutLauncherItemController::Create(shelf_id); | 414 AppShortcutLauncherItemController::Create(shelf_id); |
| 415 if (!item_delegate->GetRunningApplications().empty()) | 415 if (!item_delegate->GetRunningApplications().empty()) |
| 416 SelectItemWithSource(item_delegate.get(), source); | 416 SelectItemWithSource(item_delegate.get(), source); |
| 417 else | 417 else |
| 418 LaunchApp(shelf_id, source, event_flags); | 418 LaunchApp(shelf_id, source, event_flags); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void ChromeLauncherController::SetLauncherItemImage( | 421 void ChromeLauncherController::SetLauncherItemImage( |
| 422 const ash::ShelfID& shelf_id, | 422 const ash::ShelfID& shelf_id, |
| 423 const gfx::ImageSkia& image) { | 423 const gfx::ImageSkia& image) { |
| 424 DCHECK(!image.isNull()); |
| 424 const ash::ShelfItem* item = GetItem(shelf_id); | 425 const ash::ShelfItem* item = GetItem(shelf_id); |
| 425 if (item) { | 426 if (item) { |
| 426 ash::ShelfItem new_item = *item; | 427 ash::ShelfItem new_item = *item; |
| 427 new_item.image = image; | 428 new_item.image = image; |
| 428 model_->Set(model_->ItemIndexByID(shelf_id), new_item); | 429 model_->Set(model_->ItemIndexByID(shelf_id), new_item); |
| 429 } | 430 } |
| 430 } | 431 } |
| 431 | 432 |
| 433 void ChromeLauncherController::UpdateLauncherItemImage( |
| 434 const std::string& app_id) { |
| 435 AppIconLoader* icon_loader = GetAppIconLoaderForApp(app_id); |
| 436 if (icon_loader) |
| 437 icon_loader->UpdateImage(app_id); |
| 438 } |
| 439 |
| 432 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, | 440 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, |
| 433 AppState app_state) { | 441 AppState app_state) { |
| 434 ash::ShelfID shelf_id(launcher_controller_helper_->GetAppID(contents)); | 442 ash::ShelfID shelf_id(launcher_controller_helper_->GetAppID(contents)); |
| 435 | 443 |
| 436 // Check if the gMail app is loaded and it matches the given content. | 444 // Check if the gMail app is loaded and it matches the given content. |
| 437 // This special treatment is needed to address crbug.com/234268. | 445 // This special treatment is needed to address crbug.com/234268. |
| 438 if (shelf_id.IsNull() && ContentCanBeHandledByGmailApp(contents)) | 446 if (shelf_id.IsNull() && ContentCanBeHandledByGmailApp(contents)) |
| 439 shelf_id = ash::ShelfID(kGmailAppId); | 447 shelf_id = ash::ShelfID(kGmailAppId); |
| 440 | 448 |
| 441 // If the tab changed apps, remove its association with the previous app item. | 449 // If the tab changed apps, remove its association with the previous app item. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) { | 686 void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) { |
| 679 if (user_switch_observer_.get()) | 687 if (user_switch_observer_.get()) |
| 680 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 688 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| 681 } | 689 } |
| 682 | 690 |
| 683 ArcAppDeferredLauncherController* | 691 ArcAppDeferredLauncherController* |
| 684 ChromeLauncherController::GetArcDeferredLauncher() { | 692 ChromeLauncherController::GetArcDeferredLauncher() { |
| 685 return arc_deferred_launcher_.get(); | 693 return arc_deferred_launcher_.get(); |
| 686 } | 694 } |
| 687 | 695 |
| 688 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | |
| 689 const std::string& app_id) { | |
| 690 for (const auto& app_icon_loader : app_icon_loaders_) { | |
| 691 if (app_icon_loader->CanLoadImageForApp(app_id)) | |
| 692 return app_icon_loader.get(); | |
| 693 } | |
| 694 | |
| 695 return nullptr; | |
| 696 } | |
| 697 | |
| 698 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { | 696 void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { |
| 699 if (!ConnectToShelfController() || updating_shelf_pref_from_observer_) | 697 if (!ConnectToShelfController() || updating_shelf_pref_from_observer_) |
| 700 return; | 698 return; |
| 701 | 699 |
| 702 // The pref helper functions return default values for invalid display ids. | 700 // The pref helper functions return default values for invalid display ids. |
| 703 PrefService* prefs = profile_->GetPrefs(); | 701 PrefService* prefs = profile_->GetPrefs(); |
| 704 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { | 702 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { |
| 705 shelf_controller_->SetAutoHideBehavior( | 703 shelf_controller_->SetAutoHideBehavior( |
| 706 GetShelfAutoHideBehaviorPref(prefs, display.id()), display.id()); | 704 GetShelfAutoHideBehaviorPref(prefs, display.id()), display.id()); |
| 707 } | 705 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 } | 751 } |
| 754 | 752 |
| 755 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { | 753 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { |
| 756 return model_->IsAppPinned(app_id); | 754 return model_->IsAppPinned(app_id); |
| 757 } | 755 } |
| 758 | 756 |
| 759 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) { | 757 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) { |
| 760 model_->UnpinAppWithID(app_id); | 758 model_->UnpinAppWithID(app_id); |
| 761 } | 759 } |
| 762 | 760 |
| 761 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
| 762 const std::string& app_id) { |
| 763 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 764 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 765 return app_icon_loader.get(); |
| 766 } |
| 767 |
| 768 return nullptr; |
| 769 } |
| 770 |
| 763 /////////////////////////////////////////////////////////////////////////////// | 771 /////////////////////////////////////////////////////////////////////////////// |
| 764 // LauncherAppUpdater::Delegate: | 772 // LauncherAppUpdater::Delegate: |
| 765 | 773 |
| 766 void ChromeLauncherController::OnAppInstalled( | 774 void ChromeLauncherController::OnAppInstalled( |
| 767 content::BrowserContext* browser_context, | 775 content::BrowserContext* browser_context, |
| 768 const std::string& app_id) { | 776 const std::string& app_id) { |
| 769 if (IsAppPinned(app_id)) { | 777 if (IsAppPinned(app_id)) { |
| 770 // Clear and re-fetch to ensure icon is up-to-date. | 778 // Clear and re-fetch to ensure icon is up-to-date. |
| 771 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 779 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 772 if (app_icon_loader) { | 780 if (app_icon_loader) { |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); | 1383 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
| 1376 | 1384 |
| 1377 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); | 1385 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); |
| 1378 DCHECK_GE(app_list_index, 0); | 1386 DCHECK_GE(app_list_index, 0); |
| 1379 ash::ShelfItem item = model_->items()[app_list_index]; | 1387 ash::ShelfItem item = model_->items()[app_list_index]; |
| 1380 if (item.title != title) { | 1388 if (item.title != title) { |
| 1381 item.title = title; | 1389 item.title = title; |
| 1382 model_->Set(app_list_index, item); | 1390 model_->Set(app_list_index, item); |
| 1383 } | 1391 } |
| 1384 } | 1392 } |
| OLD | NEW |