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

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

Issue 2551243002: Use ChromeLauncherControllerImpl::GetItem; cleanup. (Closed)
Patch Set: Skip app-id mapping check that breaks tests. Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() { 257 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() {
258 // Reset the BrowserStatusMonitor as it has a weak pointer to this. 258 // Reset the BrowserStatusMonitor as it has a weak pointer to this.
259 browser_status_monitor_.reset(); 259 browser_status_monitor_.reset();
260 260
261 // Reset the app window controllers here since it has a weak pointer to this. 261 // Reset the app window controllers here since it has a weak pointer to this.
262 app_window_controllers_.clear(); 262 app_window_controllers_.clear();
263 263
264 model_->RemoveObserver(this); 264 model_->RemoveObserver(this);
265 if (ash::Shell::HasInstance()) 265 if (ash::Shell::HasInstance())
266 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 266 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
267 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 267 for (const auto& pair : id_to_item_controller_map_) {
268 i != id_to_item_controller_map_.end(); ++i) { 268 int index = model_->ItemIndexByID(pair.first);
269 int index = model_->ItemIndexByID(i->first);
270 // A "browser proxy" is not known to the model and this removal does 269 // A "browser proxy" is not known to the model and this removal does
271 // therefore not need to be propagated to the model. 270 // therefore not need to be propagated to the model.
272 if (index != -1 && 271 if (index != -1 &&
273 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) 272 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT)
274 model_->RemoveItemAt(index); 273 model_->RemoveItemAt(index);
275 } 274 }
276 275
277 // Release all profile dependent resources. 276 // Release all profile dependent resources.
278 ReleaseProfile(); 277 ReleaseProfile();
279 278
(...skipping 23 matching lines...) Expand all
303 302
304 const ash::ShelfItem& ChromeLauncherControllerImpl::GetItem( 303 const ash::ShelfItem& ChromeLauncherControllerImpl::GetItem(
305 ash::ShelfID id) const { 304 ash::ShelfID id) const {
306 const int index = model_->ItemIndexByID(id); 305 const int index = model_->ItemIndexByID(id);
307 DCHECK_GE(index, 0); 306 DCHECK_GE(index, 0);
308 return model_->items()[index]; 307 return model_->items()[index];
309 } 308 }
310 309
311 void ChromeLauncherControllerImpl::SetItemType(ash::ShelfID id, 310 void ChromeLauncherControllerImpl::SetItemType(ash::ShelfID id,
312 ash::ShelfItemType type) { 311 ash::ShelfItemType type) {
313 const int index = model_->ItemIndexByID(id); 312 ash::ShelfItem item = GetItem(id);
314 DCHECK_GE(index, 0);
315 ash::ShelfItem item = model_->items()[index];
316 if (item.type != type) { 313 if (item.type != type) {
317 item.type = type; 314 item.type = type;
318 model_->Set(index, item); 315 model_->Set(model_->ItemIndexByID(id), item);
James Cook 2016/12/06 00:27:01 ShelfModel::Set() has a DCHECK that the index is i
msw 2016/12/06 00:30:40 Bad code would have already crashed in GetItem, if
msw 2016/12/06 01:56:22 It just occurred to me that you meant an early ret
319 } 316 }
320 } 317 }
321 318
322 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, 319 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id,
323 ash::ShelfItemStatus status) { 320 ash::ShelfItemStatus status) {
324 const int index = model_->ItemIndexByID(id); 321 ash::ShelfItem item = GetItem(id);
325 DCHECK_GE(index, 0);
326 ash::ShelfItem item = model_->items()[index];
327 if (item.status != status) { 322 if (item.status != status) {
328 item.status = status; 323 item.status = status;
329 model_->Set(index, item); 324 model_->Set(model_->ItemIndexByID(id), item);
330 } 325 }
331 } 326 }
332 327
333 void ChromeLauncherControllerImpl::SetItemController( 328 void ChromeLauncherControllerImpl::SetItemController(
334 ash::ShelfID id, 329 ash::ShelfID id,
335 LauncherItemController* controller) { 330 LauncherItemController* controller) {
336 CHECK(controller); 331 CHECK(controller);
337 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
338 CHECK(iter != id_to_item_controller_map_.end()); 333 CHECK(iter != id_to_item_controller_map_.end());
339 controller->set_shelf_id(id); 334 controller->set_shelf_id(id);
(...skipping 16 matching lines...) Expand all
356 iter->second->set_shelf_id(id); 351 iter->second->set_shelf_id(id);
357 // Existing controller is destroyed and replaced by registering again. 352 // Existing controller is destroyed and replaced by registering again.
358 SetShelfItemDelegate(id, iter->second); 353 SetShelfItemDelegate(id, iter->second);
359 } else { 354 } else {
360 LauncherItemClosed(id); 355 LauncherItemClosed(id);
361 } 356 }
362 } 357 }
363 358
364 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 359 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
365 DCHECK(HasShelfIDToAppIDMapping(id)); 360 DCHECK(HasShelfIDToAppIDMapping(id));
366 361 ash::ShelfItem item = GetItem(id);
367 int index = model_->ItemIndexByID(id);
368 DCHECK_GE(index, 0);
369
370 ash::ShelfItem item = model_->items()[index];
371
372 if (item.type == ash::TYPE_APP) { 362 if (item.type == ash::TYPE_APP) {
373 item.type = ash::TYPE_APP_SHORTCUT; 363 item.type = ash::TYPE_APP_SHORTCUT;
374 model_->Set(index, item); 364 model_->Set(model_->ItemIndexByID(id), item);
375 } else if (item.type != ash::TYPE_APP_SHORTCUT) { 365 } else if (item.type != ash::TYPE_APP_SHORTCUT) {
376 return; 366 return;
377 } 367 }
378 368
379 SyncPinPosition(id); 369 SyncPinPosition(id);
380 } 370 }
381 371
382 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { 372 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) {
383 UnpinAndUpdatePrefs(id, true /* update_prefs */); 373 UnpinAndUpdatePrefs(id, true /* update_prefs */);
384 } 374 }
385 375
386 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, 376 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id,
387 bool update_prefs) { 377 bool update_prefs) {
388 LauncherItemController* controller = GetLauncherItemController(id); 378 LauncherItemController* controller = GetLauncherItemController(id);
389 CHECK(controller); 379 CHECK(controller);
390 380
391 if (update_prefs) { 381 if (update_prefs) {
392 ash::launcher::RemovePinPosition( 382 ash::launcher::RemovePinPosition(
393 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), 383 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id),
394 GetLaunchIDForShelfID(id))); 384 GetLaunchIDForShelfID(id)));
395 } 385 }
396 386
397 if (GetItem(id).status != ash::STATUS_CLOSED || controller->locked()) 387 if (GetItem(id).status != ash::STATUS_CLOSED || controller->locked())
398 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 388 UnpinRunningAppInternal(model_->ItemIndexByID(id));
399 else 389 else
400 LauncherItemClosed(id); 390 LauncherItemClosed(id);
401 } 391 }
402 392
403 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 393 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
404 int index = model_->ItemIndexByID(id); 394 if (model_->ItemIndexByID(id) < 0)
405 if (index < 0)
406 return false; 395 return false;
407 ash::ShelfItemType type = model_->items()[index].type; 396 ash::ShelfItemType type = GetItem(id).type;
408 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); 397 return type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT;
409 } 398 }
410 399
411 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) { 400 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) {
412 if (!HasShelfIDToAppIDMapping(id)) 401 if (!HasShelfIDToAppIDMapping(id))
413 return; // May happen if item closed with menu open. 402 return; // May happen if item closed with menu open.
414 403
415 if (IsPinned(id)) 404 if (IsPinned(id))
416 Unpin(id); 405 Unpin(id);
417 else 406 else
418 Pin(id); 407 Pin(id);
419 } 408 }
420 409
421 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { 410 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const {
422 int index = model_->ItemIndexByID(id); 411 if (model_->ItemIndexByID(id) < 0)
423 if (index == -1)
424 return false; 412 return false;
425 413
426 ash::ShelfItemType type = model_->items()[index].type; 414 ash::ShelfItemType type = GetItem(id).type;
427 std::string app_id;
428 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && 415 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) &&
429 model_->GetShelfItemDelegate(id)->CanPin()); 416 model_->GetShelfItemDelegate(id)->CanPin());
430 } 417 }
431 418
432 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 419 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
433 ash::ShelfID id = GetShelfIDForAppID(app_id); 420 ash::ShelfID id = GetShelfIDForAppID(app_id);
434 if (id == ash::kInvalidShelfID) { 421 if (id == ash::kInvalidShelfID) {
435 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), 422 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id),
436 model_->item_count(), ash::TYPE_APP); 423 model_->item_count(), ash::TYPE_APP);
437 id = GetShelfIDForAppID(app_id); 424 id = GetShelfIDForAppID(app_id);
(...skipping 20 matching lines...) Expand all
458 } 445 }
459 446
460 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { 447 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) {
461 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 448 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
462 if (!delegate) 449 if (!delegate)
463 return; // May happen if menu closed. 450 return; // May happen if menu closed.
464 delegate->Close(); 451 delegate->Close();
465 } 452 }
466 453
467 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { 454 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) {
468 const int index = model_->ItemIndexByID(id); 455 return model_->ItemIndexByID(id) >= 0 &&
469 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED; 456 GetItem(id).status != ash::STATUS_CLOSED;
470 } 457 }
471 458
472 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { 459 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) {
473 if (!HasShelfIDToAppIDMapping(id)) 460 if (!HasShelfIDToAppIDMapping(id))
474 return false; 461 return false;
475 462
476 std::string app_id = GetAppIDForShelfID(id); 463 std::string app_id = GetAppIDForShelfID(id);
477 const Extension* extension = GetExtensionForAppID(app_id, profile()); 464 const Extension* extension = GetExtensionForAppID(app_id, profile());
478 // An extension can be synced / updated at any time and therefore not be 465 // An extension can be synced / updated at any time and therefore not be
479 // available. 466 // available.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return extensions::LAUNCH_TYPE_DEFAULT; 498 return extensions::LAUNCH_TYPE_DEFAULT;
512 499
513 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()), 500 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()),
514 extension); 501 extension);
515 } 502 }
516 503
517 void ChromeLauncherControllerImpl::SetLauncherItemImage( 504 void ChromeLauncherControllerImpl::SetLauncherItemImage(
518 ash::ShelfID shelf_id, 505 ash::ShelfID shelf_id,
519 const gfx::ImageSkia& image) { 506 const gfx::ImageSkia& image) {
520 int index = model_->ItemIndexByID(shelf_id); 507 int index = model_->ItemIndexByID(shelf_id);
521 if (index == -1) 508 if (index < 0)
522 return; 509 return;
523 ash::ShelfItem item = model_->items()[index]; 510 ash::ShelfItem item = GetItem(shelf_id);
524 item.image = image; 511 item.image = image;
525 model_->Set(index, item); 512 model_->Set(index, item);
526 } 513 }
527 514
528 void ChromeLauncherControllerImpl::SetLaunchType( 515 void ChromeLauncherControllerImpl::SetLaunchType(
529 ash::ShelfID id, 516 ash::ShelfID id,
530 extensions::LaunchType launch_type) { 517 extensions::LaunchType launch_type) {
531 LauncherItemController* controller = GetLauncherItemController(id); 518 LauncherItemController* controller = GetLauncherItemController(id);
532 if (!controller) 519 if (!controller)
533 return; 520 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); 576 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
590 return model_->items()[browser_index].id; 577 return model_->items()[browser_index].id;
591 } 578 }
592 579
593 return id; 580 return id;
594 } 581 }
595 582
596 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( 583 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest(
597 ash::ShelfID id, 584 ash::ShelfID id,
598 const GURL& url) { 585 const GURL& url) {
599 int index = model_->ItemIndexByID(id); 586 if (model_->ItemIndexByID(id) < 0) {
600 if (index == -1) {
601 NOTREACHED() << "Invalid launcher id"; 587 NOTREACHED() << "Invalid launcher id";
602 return; 588 return;
603 } 589 }
604 590
605 ash::ShelfItemType type = model_->items()[index].type; 591 ash::ShelfItemType type = GetItem(id).type;
606 if ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && 592 if ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) &&
607 !IsPlatformApp(id)) { 593 !IsPlatformApp(id)) {
608 LauncherItemController* controller = GetLauncherItemController(id); 594 LauncherItemController* controller = GetLauncherItemController(id);
609 DCHECK(controller); 595 DCHECK(controller);
610 AppShortcutLauncherItemController* app_controller = 596 AppShortcutLauncherItemController* app_controller =
611 static_cast<AppShortcutLauncherItemController*>(controller); 597 static_cast<AppShortcutLauncherItemController*>(controller);
612 app_controller->set_refocus_url(url); 598 app_controller->set_refocus_url(url);
613 } else { 599 } else {
614 NOTREACHED() << "Invalid launcher type"; 600 NOTREACHED() << "Invalid launcher type";
615 } 601 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( 666 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession(
681 Profile* profile) { 667 Profile* profile) {
682 // Switch the running applications to the new user. 668 // Switch the running applications to the new user.
683 for (auto& controller : app_window_controllers_) 669 for (auto& controller : app_window_controllers_)
684 controller->AdditionalUserAddedToSession(profile); 670 controller->AdditionalUserAddedToSession(profile);
685 } 671 }
686 672
687 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( 673 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList(
688 const ash::ShelfItem& item, 674 const ash::ShelfItem& item,
689 int event_flags) { 675 int event_flags) {
690 // Make sure that there is a controller associated with the id and that the
691 // extension itself is a valid application and not a panel.
692 LauncherItemController* controller = GetLauncherItemController(item.id); 676 LauncherItemController* controller = GetLauncherItemController(item.id);
693 if (!controller || !GetShelfIDForAppID(controller->app_id())) 677 return controller ? controller->GetApplicationList(event_flags)
694 return ChromeLauncherAppMenuItems(); 678 : ChromeLauncherAppMenuItems();
695
696 return controller->GetApplicationList(event_flags);
697 } 679 }
698 680
699 std::vector<content::WebContents*> 681 std::vector<content::WebContents*>
700 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( 682 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId(
701 const std::string& app_id) { 683 const std::string& app_id) {
702 ash::ShelfID id = GetShelfIDForAppID(app_id); 684 ash::ShelfID id = GetShelfIDForAppID(app_id);
703 // If there is no such item pinned to the launcher, no menu gets created. 685 // If there is no such item pinned to the launcher, no menu gets created.
704 if (id != ash::kInvalidShelfID && 686 if (id != ash::kInvalidShelfID &&
705 GetItem(id).type == ash::TYPE_APP_SHORTCUT) { 687 GetItem(id).type == ash::TYPE_APP_SHORTCUT) {
706 LauncherItemController* controller = GetLauncherItemController(id); 688 LauncherItemController* controller = GetLauncherItemController(id);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 const extensions::Extension* extension = 756 const extensions::Extension* extension =
775 GetExtensionForAppID(app_id, profile()); 757 GetExtensionForAppID(app_id, profile());
776 if (extension) 758 if (extension)
777 return base::UTF8ToUTF16(extension->name()); 759 return base::UTF8ToUTF16(extension->name());
778 } 760 }
779 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 761 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
780 } 762 }
781 763
782 BrowserShortcutLauncherItemController* 764 BrowserShortcutLauncherItemController*
783 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { 765 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() {
784 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 766 for (const auto& pair : id_to_item_controller_map_) {
785 i != id_to_item_controller_map_.end(); ++i) { 767 if (GetItem(pair.first).type == ash::TYPE_BROWSER_SHORTCUT)
786 int index = model_->ItemIndexByID(i->first); 768 return static_cast<BrowserShortcutLauncherItemController*>(pair.second);
787 const ash::ShelfItem& item = model_->items()[index];
788 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
789 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
790 } 769 }
791 NOTREACHED() 770 NOTREACHED()
792 << "There should be always be a BrowserShortcutLauncherItemController."; 771 << "There should be always be a BrowserShortcutLauncherItemController.";
793 return nullptr; 772 return nullptr;
794 } 773 }
795 774
796 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( 775 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController(
797 const ash::ShelfID id) { 776 const ash::ShelfID id) {
798 if (!HasShelfIDToAppIDMapping(id)) 777 if (!HasShelfIDToAppIDMapping(id))
799 return nullptr; 778 return nullptr;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 if (GetPinnableForAppID(shelf_app_id, profile()) == 916 if (GetPinnableForAppID(shelf_app_id, profile()) ==
938 AppListControllerDelegate::PIN_EDITABLE) 917 AppListControllerDelegate::PIN_EDITABLE)
939 DoPinAppWithID(shelf_app_id); 918 DoPinAppWithID(shelf_app_id);
940 else 919 else
941 NOTREACHED(); 920 NOTREACHED();
942 } 921 }
943 922
944 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { 923 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) {
945 const std::string shelf_app_id = 924 const std::string shelf_app_id =
946 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 925 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
947 for (IDToItemControllerMap::const_iterator i = 926 for (const auto& pair : id_to_item_controller_map_) {
948 id_to_item_controller_map_.begin(); 927 if (IsPinned(pair.first) && pair.second->app_id() == shelf_app_id)
949 i != id_to_item_controller_map_.end(); ++i) {
950 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id)
951 return true; 928 return true;
952 } 929 }
953 return false; 930 return false;
954 } 931 }
955 932
956 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { 933 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) {
957 const std::string shelf_app_id = 934 const std::string shelf_app_id =
958 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 935 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
959 if (GetPinnableForAppID(shelf_app_id, profile()) == 936 if (GetPinnableForAppID(shelf_app_id, profile()) ==
960 AppListControllerDelegate::PIN_EDITABLE) 937 AppListControllerDelegate::PIN_EDITABLE)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 return; 1020 return;
1044 1021
1045 // Find the first insertion point for running applications. 1022 // Find the first insertion point for running applications.
1046 int running_index = model_->FirstRunningAppIndex(); 1023 int running_index = model_->FirstRunningAppIndex();
1047 for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); 1024 for (RunningAppListIds::iterator app_id = app_id_list->second.begin();
1048 app_id != app_id_list->second.end(); ++app_id) { 1025 app_id != app_id_list->second.end(); ++app_id) {
1049 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); 1026 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id);
1050 if (shelf_id) { 1027 if (shelf_id) {
1051 int app_index = model_->ItemIndexByID(shelf_id); 1028 int app_index = model_->ItemIndexByID(shelf_id);
1052 DCHECK_GE(app_index, 0); 1029 DCHECK_GE(app_index, 0);
1053 if (model_->items()[app_index].type == ash::TYPE_APP) { 1030 if (GetItem(shelf_id).type == ash::TYPE_APP) {
1054 if (running_index != app_index) 1031 if (running_index != app_index)
1055 model_->Move(running_index, app_index); 1032 model_->Move(running_index, app_index);
1056 running_index++; 1033 running_index++;
1057 } 1034 }
1058 } 1035 }
1059 } 1036 }
1060 } 1037 }
1061 1038
1062 ash::ShelfID 1039 ash::ShelfID
1063 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1040 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 bool update_prefs) { 1087 bool update_prefs) {
1111 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1088 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1112 if (shelf_id && IsPinned(shelf_id)) 1089 if (shelf_id && IsPinned(shelf_id))
1113 UnpinAndUpdatePrefs(shelf_id, update_prefs); 1090 UnpinAndUpdatePrefs(shelf_id, update_prefs);
1114 } 1091 }
1115 1092
1116 void ChromeLauncherControllerImpl::PinRunningAppInternal( 1093 void ChromeLauncherControllerImpl::PinRunningAppInternal(
1117 int index, 1094 int index,
1118 ash::ShelfID shelf_id) { 1095 ash::ShelfID shelf_id) {
1119 int running_index = model_->ItemIndexByID(shelf_id); 1096 int running_index = model_->ItemIndexByID(shelf_id);
1120 ash::ShelfItem item = model_->items()[running_index]; 1097 ash::ShelfItem item = GetItem(shelf_id);
1121 DCHECK_EQ(item.type, ash::TYPE_APP); 1098 DCHECK_EQ(item.type, ash::TYPE_APP);
1122 item.type = ash::TYPE_APP_SHORTCUT; 1099 item.type = ash::TYPE_APP_SHORTCUT;
1123 model_->Set(running_index, item); 1100 model_->Set(running_index, item);
1124 // The |ShelfModel|'s weight system might reposition the item to a 1101 // The |ShelfModel|'s weight system might reposition the item to a
1125 // new index, so we get the index again. 1102 // new index, so we get the index again.
1126 running_index = model_->ItemIndexByID(shelf_id); 1103 running_index = model_->ItemIndexByID(shelf_id);
1127 if (running_index < index) 1104 if (running_index < index)
1128 --index; 1105 --index;
1129 if (running_index != index) 1106 if (running_index != index)
1130 model_->Move(running_index, index); 1107 model_->Move(running_index, index);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 LauncherItemController* controller = GetLauncherItemController(item.id); 1507 LauncherItemController* controller = GetLauncherItemController(item.id);
1531 if (!controller || controller->image_set_by_controller()) 1508 if (!controller || controller->image_set_by_controller())
1532 continue; 1509 continue;
1533 item.image = image; 1510 item.image = image;
1534 if (arc_deferred_launcher_) 1511 if (arc_deferred_launcher_)
1535 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1512 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1536 model_->Set(index, item); 1513 model_->Set(index, item);
1537 // It's possible we're waiting on more than one item, so don't break. 1514 // It's possible we're waiting on more than one item, so don't break.
1538 } 1515 }
1539 } 1516 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698