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

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

Issue 2391253004: Use mojo Shelf interfaces for both mash and classic ash. (Closed)
Patch Set: Address comments. Created 4 years, 2 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_launcher_controller_mus.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_mus.h"
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" 8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
9 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
10 #include "extensions/grit/extensions_browser_resources.h"
11 #include "mojo/common/common_type_converters.h"
12 #include "ui/base/resource/resource_bundle.h"
9 13
10 // static 14 class ChromeShelfItemDelegate : public ash::mojom::ShelfItemDelegate {
11 ChromeLauncherController* ChromeLauncherControllerMus::CreateInstance() { 15 public:
12 DCHECK(!ChromeLauncherController::instance()); 16 explicit ChromeShelfItemDelegate(const std::string& app_id,
13 ChromeLauncherControllerMus* instance = new ChromeLauncherControllerMus(); 17 ChromeLauncherController* controller)
14 ChromeLauncherController::set_instance(instance); 18 : app_id_(app_id),
15 return instance; 19 item_delegate_binding_(this),
16 } 20 controller_(controller) {}
21 ~ChromeShelfItemDelegate() override {}
17 22
18 ChromeLauncherControllerMus::ChromeLauncherControllerMus() 23 ash::mojom::ShelfItemDelegateAssociatedPtrInfo CreateInterfacePtrInfoAndBind(
19 : shelf_controller_(new ChromeMashShelfController) {} 24 mojo::AssociatedGroup* associated_group) {
25 DCHECK(!item_delegate_binding_.is_bound());
26 ash::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
27 item_delegate_binding_.Bind(&ptr_info, associated_group);
28 return ptr_info;
29 }
30
31 private:
32 // ash::mojom::ShelfItemDelegate:
33 void LaunchItem() override {
34 controller_->LaunchApp(app_id_, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE);
35 }
36 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {
37 NOTIMPLEMENTED();
38 }
39 void ItemPinned() override { NOTIMPLEMENTED(); }
40 void ItemUnpinned() override { NOTIMPLEMENTED(); }
41 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); }
42
43 std::string app_id_;
44 mojo::AssociatedBinding<ash::mojom::ShelfItemDelegate> item_delegate_binding_;
45
46 // Not owned.
47 ChromeLauncherController* controller_;
48
49 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate);
50 };
51
52 ChromeLauncherControllerMus::ChromeLauncherControllerMus() {}
20 53
21 ChromeLauncherControllerMus::~ChromeLauncherControllerMus() {} 54 ChromeLauncherControllerMus::~ChromeLauncherControllerMus() {}
22 55
23 void ChromeLauncherControllerMus::Init() {} 56 void ChromeLauncherControllerMus::Init() {
57 NOTIMPLEMENTED();
58 }
24 59
25 ash::ShelfID ChromeLauncherControllerMus::CreateAppLauncherItem( 60 ash::ShelfID ChromeLauncherControllerMus::CreateAppLauncherItem(
26 LauncherItemController* controller, 61 LauncherItemController* controller,
27 const std::string& app_id, 62 const std::string& app_id,
28 ash::ShelfItemStatus status) { 63 ash::ShelfItemStatus status) {
29 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
30 return ash::TYPE_UNDEFINED; 65 return ash::TYPE_UNDEFINED;
31 } 66 }
32 67
33 void ChromeLauncherControllerMus::SetItemStatus(ash::ShelfID id, 68 void ChromeLauncherControllerMus::SetItemStatus(ash::ShelfID id,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 bool ChromeLauncherControllerMus::IsOpen(ash::ShelfID id) { 121 bool ChromeLauncherControllerMus::IsOpen(ash::ShelfID id) {
87 NOTIMPLEMENTED(); 122 NOTIMPLEMENTED();
88 return false; 123 return false;
89 } 124 }
90 125
91 bool ChromeLauncherControllerMus::IsPlatformApp(ash::ShelfID id) { 126 bool ChromeLauncherControllerMus::IsPlatformApp(ash::ShelfID id) {
92 NOTIMPLEMENTED(); 127 NOTIMPLEMENTED();
93 return false; 128 return false;
94 } 129 }
95 130
96 void ChromeLauncherControllerMus::LaunchApp(const std::string& app_id,
97 ash::LaunchSource source,
98 int event_flags) {
99 shelf_controller_->LaunchItem(app_id);
100 }
101
102 void ChromeLauncherControllerMus::ActivateApp(const std::string& app_id, 131 void ChromeLauncherControllerMus::ActivateApp(const std::string& app_id,
103 ash::LaunchSource source, 132 ash::LaunchSource source,
104 int event_flags) { 133 int event_flags) {
105 NOTIMPLEMENTED(); 134 NOTIMPLEMENTED();
106 } 135 }
107 136
108 extensions::LaunchType ChromeLauncherControllerMus::GetLaunchType( 137 extensions::LaunchType ChromeLauncherControllerMus::GetLaunchType(
109 ash::ShelfID id) { 138 ash::ShelfID id) {
110 NOTIMPLEMENTED(); 139 NOTIMPLEMENTED();
111 return extensions::LAUNCH_TYPE_INVALID; 140 return extensions::LAUNCH_TYPE_INVALID;
(...skipping 10 matching lines...) Expand all
122 NOTIMPLEMENTED(); 151 NOTIMPLEMENTED();
123 return false; 152 return false;
124 } 153 }
125 154
126 void ChromeLauncherControllerMus::SetLaunchType( 155 void ChromeLauncherControllerMus::SetLaunchType(
127 ash::ShelfID id, 156 ash::ShelfID id,
128 extensions::LaunchType launch_type) { 157 extensions::LaunchType launch_type) {
129 NOTIMPLEMENTED(); 158 NOTIMPLEMENTED();
130 } 159 }
131 160
132 Profile* ChromeLauncherControllerMus::GetProfile() {
133 return ProfileManager::GetActiveUserProfile();
134 }
135
136 void ChromeLauncherControllerMus::UpdateAppState(content::WebContents* contents, 161 void ChromeLauncherControllerMus::UpdateAppState(content::WebContents* contents,
137 AppState app_state) { 162 AppState app_state) {
138 NOTIMPLEMENTED(); 163 NOTIMPLEMENTED();
139 } 164 }
140 165
141 ash::ShelfID ChromeLauncherControllerMus::GetShelfIDForWebContents( 166 ash::ShelfID ChromeLauncherControllerMus::GetShelfIDForWebContents(
142 content::WebContents* contents) { 167 content::WebContents* contents) {
143 NOTIMPLEMENTED(); 168 NOTIMPLEMENTED();
144 return ash::TYPE_UNDEFINED; 169 return ash::TYPE_UNDEFINED;
145 } 170 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 257
233 void ChromeLauncherControllerMus::OnUserProfileReadyToSwitch(Profile* profile) { 258 void ChromeLauncherControllerMus::OnUserProfileReadyToSwitch(Profile* profile) {
234 NOTIMPLEMENTED(); 259 NOTIMPLEMENTED();
235 } 260 }
236 261
237 ArcAppDeferredLauncherController* 262 ArcAppDeferredLauncherController*
238 ChromeLauncherControllerMus::GetArcDeferredLauncher() { 263 ChromeLauncherControllerMus::GetArcDeferredLauncher() {
239 NOTIMPLEMENTED(); 264 NOTIMPLEMENTED();
240 return nullptr; 265 return nullptr;
241 } 266 }
267
268 void ChromeLauncherControllerMus::OnAppImageUpdated(
269 const std::string& app_id,
270 const gfx::ImageSkia& image) {
271 if (ConnectToShelfController())
272 shelf_controller()->SetItemImage(app_id, *image.bitmap());
273 }
274
275 void ChromeLauncherControllerMus::PinAppsFromPrefs() {
276 if (!ConnectToShelfController())
277 return;
278
279 std::vector<std::string> pinned_apps = ash::launcher::GetPinnedAppsFromPrefs(
280 profile()->GetPrefs(), launcher_controller_helper());
281
282 for (const auto& app : pinned_apps) {
283 if (app == ash::launcher::kPinnedAppsPlaceholder)
284 continue;
285
286 ash::mojom::ShelfItemPtr item(ash::mojom::ShelfItem::New());
287 item->app_id = app;
288 item->app_title = mojo::String::From(
289 launcher_controller_helper()->GetAppTitle(profile(), app));
290 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
291 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
292 item->image = *image.ToSkBitmap();
293 std::unique_ptr<ChromeShelfItemDelegate> delegate(
294 new ChromeShelfItemDelegate(app, this));
295 shelf_controller()->PinItem(std::move(item),
296 delegate->CreateInterfacePtrInfoAndBind(
297 shelf_controller().associated_group()));
298 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate)));
299
300 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app);
301 if (app_icon_loader) {
302 app_icon_loader->FetchImage(app);
303 app_icon_loader->UpdateImage(app);
304 }
305 }
306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698