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

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

Issue 1921403002: Pin apps from prefs on the mash shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only use ChromeMashShelfController with use_ash=1. Created 4 years, 7 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
OLDNEW
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/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 9 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
10 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
11 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
9 #include "chrome/grit/theme_resources.h" 12 #include "chrome/grit/theme_resources.h"
10 #include "content/public/common/mojo_shell_connection.h" 13 #include "content/public/common/mojo_shell_connection.h"
14 #include "extensions/common/constants.h"
15 #include "extensions/grit/extensions_browser_resources.h"
16 #include "mojo/common/common_type_converters.h"
11 #include "services/shell/public/cpp/connector.h" 17 #include "services/shell/public/cpp/connector.h"
12 #include "skia/public/type_converters.h" 18 #include "skia/public/type_converters.h"
13 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
15 21
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
24 #endif
25
16 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate { 26 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate {
17 public: 27 public:
18 ChromeShelfItemDelegate() : item_delegate_binding_(this) {} 28 ChromeShelfItemDelegate() : item_delegate_binding_(this) {}
19 ~ChromeShelfItemDelegate() override {} 29 ~ChromeShelfItemDelegate() override {}
20 30
21 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo 31 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo
22 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { 32 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) {
23 DCHECK(!item_delegate_binding_.is_bound()); 33 DCHECK(!item_delegate_binding_.is_bound());
24 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; 34 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
25 item_delegate_binding_.Bind(&ptr_info, associated_group); 35 item_delegate_binding_.Bind(&ptr_info, associated_group);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 74
65 // Set shelf alignment and auto-hide behavior from preferences. 75 // Set shelf alignment and auto-hide behavior from preferences.
66 Profile* profile = ProfileManager::GetActiveUserProfile(); 76 Profile* profile = ProfileManager::GetActiveUserProfile();
67 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 77 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
68 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( 78 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
69 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); 79 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id)));
70 shelf_controller_->SetAutoHideBehavior( 80 shelf_controller_->SetAutoHideBehavior(
71 static_cast<mash::shelf::mojom::AutoHideBehavior>( 81 static_cast<mash::shelf::mojom::AutoHideBehavior>(
72 ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id))); 82 ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id)));
73 83
74 // Create a test shortcut item to a fake application. 84 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
75 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); 85 // image is associated with a profile (its loader requires the profile).
76 std::string item_id("mojo:fake_app"); 86 // Since icon size changes are possible, the icon could be requested to be
77 item->app_id = item_id; 87 // reloaded. However - having it not multi profile aware would cause problems
78 item->app_title = "Fake Mojo App (test pinned shelf item)"; 88 // if the icon cache gets deleted upon user switch.
79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 89 std::unique_ptr<AppIconLoader> extension_app_icon_loader(
80 const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32); 90 new extensions::ExtensionAppIconLoader(
81 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); 91 profile, extension_misc::EXTENSION_ICON_SMALL, this));
82 std::unique_ptr<ChromeShelfItemDelegate> delegate( 92 app_icon_loaders_.push_back(std::move(extension_app_icon_loader));
83 new ChromeShelfItemDelegate()); 93
84 shelf_controller_->PinItem(std::move(item), 94 #if defined(OS_CHROMEOS)
85 delegate->CreateInterfacePtrInfoAndBind( 95 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader(
86 shelf_controller_.associated_group())); 96 profile, extension_misc::EXTENSION_ICON_SMALL, this));
87 app_id_to_item_delegate_.insert(std::make_pair(item_id, std::move(delegate))); 97 app_icon_loaders_.push_back(std::move(arc_app_icon_loader));
98 #endif
99
100 PinAppsFromPrefs();
88 101
89 // Start observing the shelf now that it has been initialized. 102 // Start observing the shelf now that it has been initialized.
90 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; 103 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
91 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); 104 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group());
92 shelf_controller_->AddObserver(std::move(ptr_info)); 105 shelf_controller_->AddObserver(std::move(ptr_info));
93 } 106 }
94 107
108 void ChromeMashShelfController::PinAppsFromPrefs() {
109 Profile* profile = ProfileManager::GetActiveUserProfile();
110 LauncherControllerHelper helper(profile);
111 std::vector<std::string> pinned_apps =
112 ash::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper);
113
114 for (const auto& app : pinned_apps) {
115 if (app == ash::kPinnedAppsPlaceholder)
116 continue;
117
118 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
119 item->app_id = app;
120 item->app_title = mojo::String::From(helper.GetAppTitle(profile, app));
121 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
122 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
123 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
124 std::unique_ptr<ChromeShelfItemDelegate> delegate(
125 new ChromeShelfItemDelegate());
126 shelf_controller_->PinItem(std::move(item),
127 delegate->CreateInterfacePtrInfoAndBind(
128 shelf_controller_.associated_group()));
129 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate)));
130
131 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app);
132 if (app_icon_loader) {
133 app_icon_loader->FetchImage(app);
134 app_icon_loader->UpdateImage(app);
135 }
136 }
137 }
138
139 AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp(
140 const std::string& app_id) {
141 for (const auto& app_icon_loader : app_icon_loaders_) {
142 if (app_icon_loader->CanLoadImageForApp(app_id))
143 return app_icon_loader.get();
144 }
145
146 return nullptr;
147 }
148
95 void ChromeMashShelfController::OnAlignmentChanged( 149 void ChromeMashShelfController::OnAlignmentChanged(
96 mash::shelf::mojom::Alignment alignment) { 150 mash::shelf::mojom::Alignment alignment) {
97 ash::SetShelfAlignmentPref( 151 ash::SetShelfAlignmentPref(
98 ProfileManager::GetActiveUserProfile()->GetPrefs(), 152 ProfileManager::GetActiveUserProfile()->GetPrefs(),
99 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 153 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
100 static_cast<ash::wm::ShelfAlignment>(alignment)); 154 static_cast<ash::wm::ShelfAlignment>(alignment));
101 } 155 }
102 156
103 void ChromeMashShelfController::OnAutoHideBehaviorChanged( 157 void ChromeMashShelfController::OnAutoHideBehaviorChanged(
104 mash::shelf::mojom::AutoHideBehavior auto_hide) { 158 mash::shelf::mojom::AutoHideBehavior auto_hide) {
105 ash::SetShelfAutoHideBehaviorPref( 159 ash::SetShelfAutoHideBehaviorPref(
106 ProfileManager::GetActiveUserProfile()->GetPrefs(), 160 ProfileManager::GetActiveUserProfile()->GetPrefs(),
107 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 161 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
108 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); 162 static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
109 } 163 }
164
165 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id,
166 const gfx::ImageSkia& image) {
167 shelf_controller_->SetItemImage(app_id,
168 skia::mojom::Bitmap::From(*image.bitmap()));
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698