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

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

Issue 2059963002: Mustash implementation of ChromeLauncherController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@launcher_controller_mus_5
Patch Set: Removing unused import. Created 4 years, 6 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 mash::shelf::mojom::ShelfItemDelegate {
24 public: 24 public:
25 explicit ChromeShelfItemDelegate(const std::string& app_id) 25 explicit ChromeShelfItemDelegate(const std::string& app_id,
26 : app_id_(app_id), item_delegate_binding_(this) {} 26 ChromeMashShelfController* controller)
27 : app_id_(app_id),
28 item_delegate_binding_(this),
29 controller_(controller) {}
27 ~ChromeShelfItemDelegate() override {} 30 ~ChromeShelfItemDelegate() override {}
28 31
29 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo 32 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo
30 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { 33 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) {
31 DCHECK(!item_delegate_binding_.is_bound()); 34 DCHECK(!item_delegate_binding_.is_bound());
32 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; 35 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
33 item_delegate_binding_.Bind(&ptr_info, associated_group); 36 item_delegate_binding_.Bind(&ptr_info, associated_group);
34 return ptr_info; 37 return ptr_info;
35 } 38 }
36 39
37 private: 40 private:
38 // mash::shelf::mojom::ShelfItemDelegate: 41 // mash::shelf::mojom::ShelfItemDelegate:
39 void LaunchItem() override { 42 void LaunchItem() override { controller_->LaunchItem(app_id_); }
40 ChromeMashShelfController::instance()->LaunchItem(app_id_);
41 }
42 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override { 43 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {
43 NOTIMPLEMENTED(); 44 NOTIMPLEMENTED();
44 } 45 }
45 void ItemPinned() override { NOTIMPLEMENTED(); } 46 void ItemPinned() override { NOTIMPLEMENTED(); }
46 void ItemUnpinned() override { NOTIMPLEMENTED(); } 47 void ItemUnpinned() override { NOTIMPLEMENTED(); }
47 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); } 48 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); }
48 49
49 std::string app_id_; 50 std::string app_id_;
50 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate> 51 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate>
51 item_delegate_binding_; 52 item_delegate_binding_;
52 53
54 // Not owned.
55 ChromeMashShelfController* controller_;
56
53 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate); 57 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate);
54 }; 58 };
55 59
56 // static 60 ChromeMashShelfController::ChromeMashShelfController()
57 ChromeMashShelfController* ChromeMashShelfController::instance_ = nullptr; 61 : helper_(ProfileManager::GetActiveUserProfile()),
62 observer_binding_(this) {}
58 63
59 ChromeMashShelfController::~ChromeMashShelfController() {} 64 ChromeMashShelfController::~ChromeMashShelfController() {}
60 65
61 // static
62 ChromeMashShelfController* ChromeMashShelfController::CreateInstance() {
63 DCHECK(!instance_);
64 instance_ = new ChromeMashShelfController();
65 instance_->Init();
msw 2016/06/13 21:01:22 You'll need to call Init() at some point. Inline i
mfomitchev 2016/06/13 21:33:31 Oops! Thanks, done.
66 return instance_;
67 }
68
69 void ChromeMashShelfController::LaunchItem(const std::string& app_id) { 66 void ChromeMashShelfController::LaunchItem(const std::string& app_id) {
70 helper_.LaunchApp(app_id, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE); 67 helper_.LaunchApp(app_id, ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE);
71 } 68 }
72 69
73 ChromeMashShelfController::ChromeMashShelfController()
74 : helper_(ProfileManager::GetActiveUserProfile()),
75 observer_binding_(this) {}
76
77 void ChromeMashShelfController::Init() { 70 void ChromeMashShelfController::Init() {
78 shell::Connector* connector = 71 shell::Connector* connector =
79 content::MojoShellConnection::Get()->GetConnector(); 72 content::MojoShellConnection::Get()->GetConnector();
80 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); 73 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_);
81 74
82 // Set shelf alignment and auto-hide behavior from preferences. 75 // Set shelf alignment and auto-hide behavior from preferences.
83 Profile* profile = ProfileManager::GetActiveUserProfile(); 76 Profile* profile = ProfileManager::GetActiveUserProfile();
84 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 77 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
85 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( 78 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
86 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); 79 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (app == ash::kPinnedAppsPlaceholder) 114 if (app == ash::kPinnedAppsPlaceholder)
122 continue; 115 continue;
123 116
124 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); 117 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
125 item->app_id = app; 118 item->app_id = app;
126 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); 119 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app));
127 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 120 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
128 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); 121 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
129 item->image = *image.ToSkBitmap(); 122 item->image = *image.ToSkBitmap();
130 std::unique_ptr<ChromeShelfItemDelegate> delegate( 123 std::unique_ptr<ChromeShelfItemDelegate> delegate(
131 new ChromeShelfItemDelegate(app)); 124 new ChromeShelfItemDelegate(app, this));
132 shelf_controller_->PinItem(std::move(item), 125 shelf_controller_->PinItem(std::move(item),
133 delegate->CreateInterfacePtrInfoAndBind( 126 delegate->CreateInterfacePtrInfoAndBind(
134 shelf_controller_.associated_group())); 127 shelf_controller_.associated_group()));
135 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate))); 128 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate)));
136 129
137 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app); 130 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app);
138 if (app_icon_loader) { 131 if (app_icon_loader) {
139 app_icon_loader->FetchImage(app); 132 app_icon_loader->FetchImage(app);
140 app_icon_loader->UpdateImage(app); 133 app_icon_loader->UpdateImage(app);
141 } 134 }
(...skipping 23 matching lines...) Expand all
165 ash::SetShelfAutoHideBehaviorPref( 158 ash::SetShelfAutoHideBehaviorPref(
166 ProfileManager::GetActiveUserProfile()->GetPrefs(), 159 ProfileManager::GetActiveUserProfile()->GetPrefs(),
167 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 160 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
168 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); 161 static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
169 } 162 }
170 163
171 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, 164 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id,
172 const gfx::ImageSkia& image) { 165 const gfx::ImageSkia& image) {
173 shelf_controller_->SetItemImage(app_id, *image.bitmap()); 166 shelf_controller_->SetItemImage(app_id, *image.bitmap());
174 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698