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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 PinAppsFromPrefs(); | 97 PinAppsFromPrefs(); |
98 | 98 |
99 // Start observing the shelf now that it has been initialized. | 99 // Start observing the shelf now that it has been initialized. |
100 ash::mojom::ShelfObserverAssociatedPtrInfo ptr_info; | 100 ash::mojom::ShelfObserverAssociatedPtrInfo ptr_info; |
101 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); | 101 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); |
102 shelf_controller_->AddObserver(std::move(ptr_info)); | 102 shelf_controller_->AddObserver(std::move(ptr_info)); |
103 } | 103 } |
104 | 104 |
105 void ChromeMashShelfController::PinAppsFromPrefs() { | 105 void ChromeMashShelfController::PinAppsFromPrefs() { |
106 Profile* profile = ProfileManager::GetActiveUserProfile(); | 106 Profile* profile = ProfileManager::GetActiveUserProfile(); |
107 std::vector<std::string> pinned_apps = | 107 std::vector<ash::launcher::AppLauncherId> pinned_apps = |
108 ash::launcher::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_); | 108 ash::launcher::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper_); |
109 | 109 |
110 for (const auto& app : pinned_apps) { | 110 for (const auto& app_launcher_id : pinned_apps) { |
111 if (app == ash::launcher::kPinnedAppsPlaceholder) | 111 if (app_launcher_id.GetAsString() == ash::launcher::kPinnedAppsPlaceholder) |
112 continue; | 112 continue; |
113 | 113 |
114 ash::mojom::ShelfItemPtr item(ash::mojom::ShelfItem::New()); | 114 ash::mojom::ShelfItemPtr item(ash::mojom::ShelfItem::New()); |
115 item->app_id = app; | 115 item->app_id = app_launcher_id.GetAsString(); |
James Cook
2016/10/04 16:08:37
nit: Given that you use app_launcher_id.GetAsStrin
Andra Paraschiv
2016/10/05 11:21:58
Done.
| |
116 item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); | 116 item->app_title = mojo::String::From( |
117 helper_.GetAppTitle(profile, app_launcher_id.GetAsString())); | |
117 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 118 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
118 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); | 119 const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); |
119 item->image = *image.ToSkBitmap(); | 120 item->image = *image.ToSkBitmap(); |
120 std::unique_ptr<ChromeShelfItemDelegate> delegate( | 121 std::unique_ptr<ChromeShelfItemDelegate> delegate( |
121 new ChromeShelfItemDelegate(app, this)); | 122 new ChromeShelfItemDelegate(app_launcher_id.GetAsString(), this)); |
122 shelf_controller_->PinItem(std::move(item), | 123 shelf_controller_->PinItem(std::move(item), |
123 delegate->CreateInterfacePtrInfoAndBind( | 124 delegate->CreateInterfacePtrInfoAndBind( |
124 shelf_controller_.associated_group())); | 125 shelf_controller_.associated_group())); |
125 app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate))); | 126 app_id_to_item_delegate_.insert( |
127 std::make_pair(app_launcher_id.GetAsString(), std::move(delegate))); | |
126 | 128 |
127 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app); | 129 AppIconLoader* app_icon_loader = |
130 GetAppIconLoaderForApp(app_launcher_id.GetAsString()); | |
128 if (app_icon_loader) { | 131 if (app_icon_loader) { |
129 app_icon_loader->FetchImage(app); | 132 app_icon_loader->FetchImage(app_launcher_id.GetAsString()); |
130 app_icon_loader->UpdateImage(app); | 133 app_icon_loader->UpdateImage(app_launcher_id.GetAsString()); |
131 } | 134 } |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp( | 138 AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp( |
136 const std::string& app_id) { | 139 const std::string& app_id) { |
137 for (const auto& app_icon_loader : app_icon_loaders_) { | 140 for (const auto& app_icon_loader : app_icon_loaders_) { |
138 if (app_icon_loader->CanLoadImageForApp(app_id)) | 141 if (app_icon_loader->CanLoadImageForApp(app_id)) |
139 return app_icon_loader.get(); | 142 return app_icon_loader.get(); |
140 } | 143 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 // This will uselessly store a preference value for invalid display ids. | 175 // This will uselessly store a preference value for invalid display ids. |
173 ash::launcher::SetShelfAutoHideBehaviorPref( | 176 ash::launcher::SetShelfAutoHideBehaviorPref( |
174 ProfileManager::GetActiveUserProfile()->GetPrefs(), display_id, | 177 ProfileManager::GetActiveUserProfile()->GetPrefs(), display_id, |
175 auto_hide); | 178 auto_hide); |
176 } | 179 } |
177 | 180 |
178 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, | 181 void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, |
179 const gfx::ImageSkia& image) { | 182 const gfx::ImageSkia& image) { |
180 shelf_controller_->SetItemImage(app_id, *image.bitmap()); | 183 shelf_controller_->SetItemImage(app_id, *image.bitmap()); |
181 } | 184 } |
OLD | NEW |