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