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

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

Issue 2259153002: mash: Port ash_sysui ShelfDelegateMus impl to mojo:ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 3 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/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"
11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
12 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 12 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
13 #include "chrome/grit/theme_resources.h" 13 #include "chrome/grit/theme_resources.h"
14 #include "content/public/common/mojo_shell_connection.h" 14 #include "content/public/common/mojo_shell_connection.h"
15 #include "extensions/common/constants.h" 15 #include "extensions/common/constants.h"
16 #include "extensions/grit/extensions_browser_resources.h" 16 #include "extensions/grit/extensions_browser_resources.h"
17 #include "mojo/common/common_type_converters.h" 17 #include "mojo/common/common_type_converters.h"
18 #include "services/shell/public/cpp/connector.h" 18 #include "services/shell/public/cpp/connector.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/display/display.h" 20 #include "ui/display/display.h"
21 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
22 22
23 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate { 23 class ChromeShelfItemDelegate : public ash::mojom::ShelfItemDelegate {
24 public: 24 public:
25 explicit ChromeShelfItemDelegate(const std::string& app_id, 25 explicit ChromeShelfItemDelegate(const std::string& app_id,
26 ChromeMashShelfController* controller) 26 ChromeMashShelfController* controller)
27 : app_id_(app_id), 27 : app_id_(app_id),
28 item_delegate_binding_(this), 28 item_delegate_binding_(this),
29 controller_(controller) {} 29 controller_(controller) {}
30 ~ChromeShelfItemDelegate() override {} 30 ~ChromeShelfItemDelegate() override {}
31 31
32 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo 32 ash::mojom::ShelfItemDelegateAssociatedPtrInfo CreateInterfacePtrInfoAndBind(
33 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { 33 mojo::AssociatedGroup* associated_group) {
34 DCHECK(!item_delegate_binding_.is_bound()); 34 DCHECK(!item_delegate_binding_.is_bound());
35 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; 35 ash::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
36 item_delegate_binding_.Bind(&ptr_info, associated_group); 36 item_delegate_binding_.Bind(&ptr_info, associated_group);
37 return ptr_info; 37 return ptr_info;
38 } 38 }
39 39
40 private: 40 private:
41 // mash::shelf::mojom::ShelfItemDelegate: 41 // ash::mojom::ShelfItemDelegate:
42 void LaunchItem() override { controller_->LaunchItem(app_id_); } 42 void LaunchItem() override { controller_->LaunchItem(app_id_); }
43 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override { 43 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {
44 NOTIMPLEMENTED(); 44 NOTIMPLEMENTED();
45 } 45 }
46 void ItemPinned() override { NOTIMPLEMENTED(); } 46 void ItemPinned() override { NOTIMPLEMENTED(); }
47 void ItemUnpinned() override { NOTIMPLEMENTED(); } 47 void ItemUnpinned() override { NOTIMPLEMENTED(); }
48 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); } 48 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); }
49 49
50 std::string app_id_; 50 std::string app_id_;
51 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate> 51 mojo::AssociatedBinding<ash::mojom::ShelfItemDelegate> item_delegate_binding_;
52 item_delegate_binding_;
53 52
54 // Not owned. 53 // Not owned.
55 ChromeMashShelfController* controller_; 54 ChromeMashShelfController* controller_;
56 55
57 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate); 56 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate);
58 }; 57 };
59 58
60 ChromeMashShelfController::ChromeMashShelfController() 59 ChromeMashShelfController::ChromeMashShelfController()
61 : helper_(ProfileManager::GetActiveUserProfile()), 60 : helper_(ProfileManager::GetActiveUserProfile()),
62 observer_binding_(this) { 61 observer_binding_(this) {
63 Init(); 62 Init();
64 } 63 }
65 64
66 ChromeMashShelfController::~ChromeMashShelfController() {} 65 ChromeMashShelfController::~ChromeMashShelfController() {}
67 66
68 void ChromeMashShelfController::LaunchItem(const std::string& app_id) { 67 void ChromeMashShelfController::LaunchItem(const std::string& app_id) {
69 helper_.LaunchApp(app_id, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE); 68 helper_.LaunchApp(app_id, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE);
70 } 69 }
71 70
72 void ChromeMashShelfController::Init() { 71 void ChromeMashShelfController::Init() {
73 shell::Connector* connector = 72 shell::Connector* connector =
74 content::MojoShellConnection::GetForProcess()->GetConnector(); 73 content::MojoShellConnection::GetForProcess()->GetConnector();
75 connector->ConnectToInterface("mojo:ash", &shelf_controller_); 74 connector->ConnectToInterface("mojo:ash", &shelf_controller_);
76 75
77 // Set shelf alignment and auto-hide behavior from preferences. 76 // Initialize shelf alignment and auto-hide behavior from preferences.
78 Profile* profile = ProfileManager::GetActiveUserProfile(); 77 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays())
79 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 78 OnShelfCreated(display.id());
80 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
81 ash::launcher::GetShelfAlignmentPref(profile->GetPrefs(), display_id)));
82 shelf_controller_->SetAutoHideBehavior(
83 static_cast<mash::shelf::mojom::AutoHideBehavior>(
84 ash::launcher::GetShelfAutoHideBehaviorPref(profile->GetPrefs(),
85 display_id)));
86 79
87 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded 80 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
88 // image is associated with a profile (its loader requires the profile). 81 // image is associated with a profile (its loader requires the profile).
89 // Since icon size changes are possible, the icon could be requested to be 82 // Since icon size changes are possible, the icon could be requested to be
90 // reloaded. However - having it not multi profile aware would cause problems 83 // reloaded. However - having it not multi profile aware would cause problems
91 // if the icon cache gets deleted upon user switch. 84 // if the icon cache gets deleted upon user switch.
85 Profile* profile = ProfileManager::GetActiveUserProfile();
92 std::unique_ptr<AppIconLoader> extension_app_icon_loader( 86 std::unique_ptr<AppIconLoader> extension_app_icon_loader(
93 new extensions::ExtensionAppIconLoader( 87 new extensions::ExtensionAppIconLoader(
94 profile, extension_misc::EXTENSION_ICON_SMALL, this)); 88 profile, extension_misc::EXTENSION_ICON_SMALL, this));
95 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); 89 app_icon_loaders_.push_back(std::move(extension_app_icon_loader));
96 90
97 if (arc::ArcAuthService::IsAllowedForProfile(profile)) { 91 if (arc::ArcAuthService::IsAllowedForProfile(profile)) {
98 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( 92 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader(
99 profile, extension_misc::EXTENSION_ICON_SMALL, this)); 93 profile, extension_misc::EXTENSION_ICON_SMALL, this));
100 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); 94 app_icon_loaders_.push_back(std::move(arc_app_icon_loader));
101 } 95 }
102 96
103 PinAppsFromPrefs(); 97 PinAppsFromPrefs();
104 98
105 // Start observing the shelf now that it has been initialized. 99 // Start observing the shelf now that it has been initialized.
106 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; 100 ash::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
107 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); 101 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group());
108 shelf_controller_->AddObserver(std::move(ptr_info)); 102 shelf_controller_->AddObserver(std::move(ptr_info));
109 } 103 }
110 104
111 void ChromeMashShelfController::PinAppsFromPrefs() { 105 void ChromeMashShelfController::PinAppsFromPrefs() {
112 Profile* profile = ProfileManager::GetActiveUserProfile(); 106 Profile* profile = ProfileManager::GetActiveUserProfile();
113 std::vector<std::string> pinned_apps = 107 std::vector<std::string> pinned_apps =
114 ash::launcher::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_); 108 ash::launcher::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_);
115 109
116 for (const auto& app : pinned_apps) { 110 for (const auto& app : pinned_apps) {
117 if (app == ash::launcher::kPinnedAppsPlaceholder) 111 if (app == ash::launcher::kPinnedAppsPlaceholder)
118 continue; 112 continue;
119 113
120 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); 114 ash::mojom::ShelfItemPtr item(ash::mojom::ShelfItem::New());
121 item->app_id = app; 115 item->app_id = app;
122 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); 116 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app));
123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 117 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
124 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); 118 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
125 item->image = *image.ToSkBitmap(); 119 item->image = *image.ToSkBitmap();
126 std::unique_ptr<ChromeShelfItemDelegate> delegate( 120 std::unique_ptr<ChromeShelfItemDelegate> delegate(
127 new ChromeShelfItemDelegate(app, this)); 121 new ChromeShelfItemDelegate(app, this));
128 shelf_controller_->PinItem(std::move(item), 122 shelf_controller_->PinItem(std::move(item),
129 delegate->CreateInterfacePtrInfoAndBind( 123 delegate->CreateInterfacePtrInfoAndBind(
130 shelf_controller_.associated_group())); 124 shelf_controller_.associated_group()));
(...skipping 10 matching lines...) Expand all
141 AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp( 135 AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp(
142 const std::string& app_id) { 136 const std::string& app_id) {
143 for (const auto& app_icon_loader : app_icon_loaders_) { 137 for (const auto& app_icon_loader : app_icon_loaders_) {
144 if (app_icon_loader->CanLoadImageForApp(app_id)) 138 if (app_icon_loader->CanLoadImageForApp(app_id))
145 return app_icon_loader.get(); 139 return app_icon_loader.get();
146 } 140 }
147 141
148 return nullptr; 142 return nullptr;
149 } 143 }
150 144
145 void ChromeMashShelfController::OnShelfCreated(int64_t display_id) {
146 // The pref helper functions return default values for invalid display ids.
147 Profile* profile = ProfileManager::GetActiveUserProfile();
148 shelf_controller_->SetAlignment(
149 ash::launcher::GetShelfAlignmentPref(profile->GetPrefs(), display_id),
150 display_id);
151 shelf_controller_->SetAutoHideBehavior(
152 ash::launcher::GetShelfAutoHideBehaviorPref(profile->GetPrefs(),
153 display_id),
154 display_id);
155 }
156
151 void ChromeMashShelfController::OnAlignmentChanged( 157 void ChromeMashShelfController::OnAlignmentChanged(
152 mash::shelf::mojom::Alignment alignment) { 158 ash::ShelfAlignment alignment,
159 int64_t display_id) {
160 // The locked alignment is set temporarily and not saved to preferences.
161 if (alignment == ash::SHELF_ALIGNMENT_BOTTOM_LOCKED)
162 return;
163 // This will uselessly store a preference value for invalid display ids.
153 ash::launcher::SetShelfAlignmentPref( 164 ash::launcher::SetShelfAlignmentPref(
154 ProfileManager::GetActiveUserProfile()->GetPrefs(), 165 ProfileManager::GetActiveUserProfile()->GetPrefs(), display_id,
155 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 166 alignment);
156 static_cast<ash::ShelfAlignment>(alignment));
157 } 167 }
158 168
159 void ChromeMashShelfController::OnAutoHideBehaviorChanged( 169 void ChromeMashShelfController::OnAutoHideBehaviorChanged(
160 mash::shelf::mojom::AutoHideBehavior auto_hide) { 170 ash::ShelfAutoHideBehavior auto_hide,
171 int64_t display_id) {
172 // This will uselessly store a preference value for invalid display ids.
161 ash::launcher::SetShelfAutoHideBehaviorPref( 173 ash::launcher::SetShelfAutoHideBehaviorPref(
162 ProfileManager::GetActiveUserProfile()->GetPrefs(), 174 ProfileManager::GetActiveUserProfile()->GetPrefs(), display_id,
163 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 175 auto_hide);
164 static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
165 } 176 }
166 177
167 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, 178 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id,
168 const gfx::ImageSkia& image) { 179 const gfx::ImageSkia& image) {
169 shelf_controller_->SetItemImage(app_id, *image.bitmap()); 180 shelf_controller_->SetItemImage(app_id, *image.bitmap());
170 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h ('k') | mash/shelf/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698