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

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

Issue 10534142: Add support for pinning platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { 185 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
186 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); 186 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
187 id_to_item_map_.erase(id); 187 id_to_item_map_.erase(id);
188 model_->RemoveItemAt(model_->ItemIndexByID(id)); 188 model_->RemoveItemAt(model_->ItemIndexByID(id));
189 } 189 }
190 190
191 void ChromeLauncherController::Unpin(ash::LauncherID id) { 191 void ChromeLauncherController::Unpin(ash::LauncherID id) {
192 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); 192 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
193 DCHECK(!id_to_item_map_[id].controller); 193 DCHECK(!id_to_item_map_[id].controller);
194 LauncherItemClosed(id); 194
195 if (ShellWindowRegistry::Get(profile_)->GetShellWindowsForApp(
196 id_to_item_map_[id].app_id).size() > 0) {
197 int index = model_->ItemIndexByID(id);
198 ash::LauncherItem item = model_->items()[index];
199 item.type = ash::TYPE_PLATFORM_APP;
200 model_->Set(index, item);
201 } else {
202 LauncherItemClosed(id);
203 }
204 if (CanPin())
205 PersistPinnedState();
206 }
207
208 void ChromeLauncherController::Pin(ash::LauncherID id) {
209 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
210 DCHECK(!id_to_item_map_[id].controller);
211
212 int index = model_->ItemIndexByID(id);
213 ash::LauncherItem item = model_->items()[index];
214
215 if (item.type != ash::TYPE_PLATFORM_APP)
216 return;
217
218 item.type = ash::TYPE_APP_SHORTCUT;
219 model_->Set(index, item);
sky 2012/06/13 21:20:53 Are we picking up the type right for these when th
DaveMoore 2012/06/13 22:30:16 I believe so. We only persist shortcuts, not the a
220
195 if (CanPin()) 221 if (CanPin())
196 PersistPinnedState(); 222 PersistPinnedState();
197 } 223 }
198 224
199 bool ChromeLauncherController::IsPinned(ash::LauncherID id) { 225 bool ChromeLauncherController::IsPinned(ash::LauncherID id) {
200 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); 226 int index = model_->ItemIndexByID(id);
201 return id_to_item_map_[id].is_pinned(); 227 ash::LauncherItemType type = model_->items()[index].type;
228 return type == ash::TYPE_APP_SHORTCUT;
202 } 229 }
203 230
204 void ChromeLauncherController::TogglePinned(ash::LauncherID id) { 231 void ChromeLauncherController::TogglePinned(ash::LauncherID id) {
205 if (id_to_item_map_.find(id) == id_to_item_map_.end()) 232 if (id_to_item_map_.find(id) == id_to_item_map_.end())
206 return; // May happen if item closed with menu open. 233 return; // May happen if item closed with menu open.
207 234
208 // Only currently support unpinning.
209 if (IsPinned(id)) 235 if (IsPinned(id))
210 Unpin(id); 236 Unpin(id);
237 else
238 Pin(id);
211 } 239 }
212 240
213 bool ChromeLauncherController::IsPinnable(ash::LauncherID id) const { 241 bool ChromeLauncherController::IsPinnable(ash::LauncherID id) const {
214 int index = model_->ItemIndexByID(id); 242 int index = model_->ItemIndexByID(id);
215 return (index != -1 && 243 if (index == -1)
216 model_->items()[index].type == ash::TYPE_APP_SHORTCUT && 244 return false;
245
246 ash::LauncherItemType type = model_->items()[index].type;
247 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP) &&
217 CanPin()); 248 CanPin());
218 } 249 }
219 250
220 void ChromeLauncherController::Open(ash::LauncherID id, int event_flags) { 251 void ChromeLauncherController::Open(ash::LauncherID id, int event_flags) {
221 if (id_to_item_map_.find(id) == id_to_item_map_.end()) 252 if (id_to_item_map_.find(id) == id_to_item_map_.end())
222 return; // In case invoked from menu and item closed while menu up. 253 return; // In case invoked from menu and item closed while menu up.
223 254
224 BrowserLauncherItemController* controller = id_to_item_map_[id].controller; 255 BrowserLauncherItemController* controller = id_to_item_map_[id].controller;
225 if (controller) { 256 if (controller) {
226 controller->window()->Show(); 257 controller->window()->Show();
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 801 }
771 model_->AddAt(index, item); 802 model_->AddAt(index, item);
772 803
773 if (!controller || controller->type() != 804 if (!controller || controller->type() !=
774 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) { 805 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) {
775 if (item.status != ash::STATUS_IS_PENDING) 806 if (item.status != ash::STATUS_IS_PENDING)
776 app_icon_loader_->FetchImage(app_id); 807 app_icon_loader_->FetchImage(app_id);
777 } 808 }
778 return id; 809 return id;
779 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698