| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_mash_shelf_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 7 #include "chrome/browser/extensions/extension_app_icon_loader.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 9 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 10 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 10 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 void ChromeMashShelfController::Init() { | 72 void ChromeMashShelfController::Init() { |
| 73 shell::Connector* connector = | 73 shell::Connector* connector = |
| 74 content::MojoShellConnection::GetForProcess()->GetConnector(); | 74 content::MojoShellConnection::GetForProcess()->GetConnector(); |
| 75 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); | 75 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); |
| 76 | 76 |
| 77 // Set shelf alignment and auto-hide behavior from preferences. | 77 // Set shelf alignment and auto-hide behavior from preferences. |
| 78 Profile* profile = ProfileManager::GetActiveUserProfile(); | 78 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 79 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 79 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 80 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( | 80 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( |
| 81 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); | 81 ash::launcher::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); |
| 82 shelf_controller_->SetAutoHideBehavior( | 82 shelf_controller_->SetAutoHideBehavior( |
| 83 static_cast<mash::shelf::mojom::AutoHideBehavior>( | 83 static_cast<mash::shelf::mojom::AutoHideBehavior>( |
| 84 ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id))); | 84 ash::launcher::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), |
| 85 display_id))); |
| 85 | 86 |
| 86 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded | 87 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded |
| 87 // image is associated with a profile (its loader requires the profile). | 88 // image is associated with a profile (its loader requires the profile). |
| 88 // Since icon size changes are possible, the icon could be requested to be | 89 // Since icon size changes are possible, the icon could be requested to be |
| 89 // reloaded. However - having it not multi profile aware would cause problems | 90 // reloaded. However - having it not multi profile aware would cause problems |
| 90 // if the icon cache gets deleted upon user switch. | 91 // if the icon cache gets deleted upon user switch. |
| 91 std::unique_ptr<AppIconLoader> extension_app_icon_loader( | 92 std::unique_ptr<AppIconLoader> extension_app_icon_loader( |
| 92 new extensions::ExtensionAppIconLoader( | 93 new extensions::ExtensionAppIconLoader( |
| 93 profile, extension_misc::EXTENSION_ICON_SMALL, this)); | 94 profile, extension_misc::EXTENSION_ICON_SMALL, this)); |
| 94 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); | 95 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); |
| 95 | 96 |
| 96 if (arc::ArcAuthService::IsAllowedForProfile(profile)) { | 97 if (arc::ArcAuthService::IsAllowedForProfile(profile)) { |
| 97 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( | 98 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( |
| 98 profile, extension_misc::EXTENSION_ICON_SMALL, this)); | 99 profile, extension_misc::EXTENSION_ICON_SMALL, this)); |
| 99 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); | 100 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 PinAppsFromPrefs(); | 103 PinAppsFromPrefs(); |
| 103 | 104 |
| 104 // Start observing the shelf now that it has been initialized. | 105 // Start observing the shelf now that it has been initialized. |
| 105 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; | 106 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; |
| 106 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); | 107 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); |
| 107 shelf_controller_->AddObserver(std::move(ptr_info)); | 108 shelf_controller_->AddObserver(std::move(ptr_info)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void ChromeMashShelfController::PinAppsFromPrefs() { | 111 void ChromeMashShelfController::PinAppsFromPrefs() { |
| 111 Profile* profile = ProfileManager::GetActiveUserProfile(); | 112 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 112 std::vector<std::string> pinned_apps = | 113 std::vector<std::string> pinned_apps = |
| 113 ash::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_); | 114 ash::launcher::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_); |
| 114 | 115 |
| 115 for (const auto& app : pinned_apps) { | 116 for (const auto& app : pinned_apps) { |
| 116 if (app == ash::kPinnedAppsPlaceholder) | 117 if (app == ash::launcher::kPinnedAppsPlaceholder) |
| 117 continue; | 118 continue; |
| 118 | 119 |
| 119 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); | 120 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); |
| 120 item->app_id = app; | 121 item->app_id = app; |
| 121 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); | 122 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); |
| 122 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 123 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); | 124 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 124 item->image = *image.ToSkBitmap(); | 125 item->image = *image.ToSkBitmap(); |
| 125 std::unique_ptr<ChromeShelfItemDelegate> delegate( | 126 std::unique_ptr<ChromeShelfItemDelegate> delegate( |
| 126 new ChromeShelfItemDelegate(app, this)); | 127 new ChromeShelfItemDelegate(app, this)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 for (const auto& app_icon_loader : app_icon_loaders_) { | 143 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 143 if (app_icon_loader->CanLoadImageForApp(app_id)) | 144 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 144 return app_icon_loader.get(); | 145 return app_icon_loader.get(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 return nullptr; | 148 return nullptr; |
| 148 } | 149 } |
| 149 | 150 |
| 150 void ChromeMashShelfController::OnAlignmentChanged( | 151 void ChromeMashShelfController::OnAlignmentChanged( |
| 151 mash::shelf::mojom::Alignment alignment) { | 152 mash::shelf::mojom::Alignment alignment) { |
| 152 ash::SetShelfAlignmentPref( | 153 ash::launcher::SetShelfAlignmentPref( |
| 153 ProfileManager::GetActiveUserProfile()->GetPrefs(), | 154 ProfileManager::GetActiveUserProfile()->GetPrefs(), |
| 154 display::Screen::GetScreen()->GetPrimaryDisplay().id(), | 155 display::Screen::GetScreen()->GetPrimaryDisplay().id(), |
| 155 static_cast<ash::ShelfAlignment>(alignment)); | 156 static_cast<ash::ShelfAlignment>(alignment)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ChromeMashShelfController::OnAutoHideBehaviorChanged( | 159 void ChromeMashShelfController::OnAutoHideBehaviorChanged( |
| 159 mash::shelf::mojom::AutoHideBehavior auto_hide) { | 160 mash::shelf::mojom::AutoHideBehavior auto_hide) { |
| 160 ash::SetShelfAutoHideBehaviorPref( | 161 ash::launcher::SetShelfAutoHideBehaviorPref( |
| 161 ProfileManager::GetActiveUserProfile()->GetPrefs(), | 162 ProfileManager::GetActiveUserProfile()->GetPrefs(), |
| 162 display::Screen::GetScreen()->GetPrimaryDisplay().id(), | 163 display::Screen::GetScreen()->GetPrimaryDisplay().id(), |
| 163 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); | 164 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, | 167 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, |
| 167 const gfx::ImageSkia& image) { | 168 const gfx::ImageSkia& image) { |
| 168 shelf_controller_->SetItemImage(app_id, *image.bitmap()); | 169 shelf_controller_->SetItemImage(app_id, *image.bitmap()); |
| 169 } | 170 } |
| OLD | NEW |