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

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

Issue 2860503002: mash: Replace int ShelfIDs with AppLaunchID strings. (Closed)
Patch Set: Restore AppLaunchId class via using ShelfID = AppLaunchId; cleanup. Created 3 years, 7 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 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.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include "ash/multi_profile_uma.h" 7 #include "ash/multi_profile_uma.h"
8 #include "ash/public/cpp/shelf_item.h" 8 #include "ash/public/cpp/shelf_item.h"
9 #include "ash/public/interfaces/constants.mojom.h" 9 #include "ash/public/interfaces/constants.mojom.h"
10 #include "ash/resources/grit/ash_resources.h" 10 #include "ash/resources/grit/ash_resources.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); 293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
294 } 294 }
295 295
296 ash::ShelfID ChromeLauncherController::CreateAppLauncherItem( 296 ash::ShelfID ChromeLauncherController::CreateAppLauncherItem(
297 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, 297 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
298 ash::ShelfItemStatus status) { 298 ash::ShelfItemStatus status) {
299 return InsertAppLauncherItem(std::move(item_delegate), status, 299 return InsertAppLauncherItem(std::move(item_delegate), status,
300 model_->item_count(), ash::TYPE_APP); 300 model_->item_count(), ash::TYPE_APP);
301 } 301 }
302 302
303 const ash::ShelfItem* ChromeLauncherController::GetItem(ash::ShelfID id) const { 303 const ash::ShelfItem* ChromeLauncherController::GetItem(
304 const ash::ShelfID& id) const {
304 const int index = model_->ItemIndexByID(id); 305 const int index = model_->ItemIndexByID(id);
305 if (index >= 0 && index < model_->item_count()) 306 if (index >= 0 && index < model_->item_count())
306 return &model_->items()[index]; 307 return &model_->items()[index];
307 return nullptr; 308 return nullptr;
308 } 309 }
309 310
310 void ChromeLauncherController::SetItemType(ash::ShelfID id, 311 void ChromeLauncherController::SetItemType(const ash::ShelfID& id,
311 ash::ShelfItemType type) { 312 ash::ShelfItemType type) {
312 const ash::ShelfItem* item = GetItem(id); 313 const ash::ShelfItem* item = GetItem(id);
313 if (item && item->type != type) { 314 if (item && item->type != type) {
314 ash::ShelfItem new_item = *item; 315 ash::ShelfItem new_item = *item;
315 new_item.type = type; 316 new_item.type = type;
316 model_->Set(model_->ItemIndexByID(id), new_item); 317 model_->Set(model_->ItemIndexByID(id), new_item);
317 } 318 }
318 } 319 }
319 320
320 void ChromeLauncherController::SetItemStatus(ash::ShelfID id, 321 void ChromeLauncherController::SetItemStatus(const ash::ShelfID& id,
321 ash::ShelfItemStatus status) { 322 ash::ShelfItemStatus status) {
322 const ash::ShelfItem* item = GetItem(id); 323 const ash::ShelfItem* item = GetItem(id);
323 if (item && item->status != status) { 324 if (item && item->status != status) {
324 ash::ShelfItem new_item = *item; 325 ash::ShelfItem new_item = *item;
325 new_item.status = status; 326 new_item.status = status;
326 model_->Set(model_->ItemIndexByID(id), new_item); 327 model_->Set(model_->ItemIndexByID(id), new_item);
327 } 328 }
328 } 329 }
329 330
330 void ChromeLauncherController::CloseLauncherItem(ash::ShelfID id) { 331 void ChromeLauncherController::CloseLauncherItem(const ash::ShelfID& id) {
331 CHECK(id); 332 CHECK(!id.IsEmpty());
332 if (IsPinned(id)) { 333 if (IsPinned(id)) {
333 // Create a new shortcut delegate. 334 // Create a new shortcut delegate.
334 SetItemStatus(id, ash::STATUS_CLOSED); 335 SetItemStatus(id, ash::STATUS_CLOSED);
335 model_->SetShelfItemDelegate(id, AppShortcutLauncherItemController::Create( 336 model_->SetShelfItemDelegate(id,
336 GetItem(id)->app_launch_id)); 337 AppShortcutLauncherItemController::Create(id));
337 } else { 338 } else {
338 RemoveShelfItem(id); 339 RemoveShelfItem(id);
339 } 340 }
340 } 341 }
341 342
342 void ChromeLauncherController::UnpinShelfItemInternal(ash::ShelfID id) { 343 void ChromeLauncherController::UnpinShelfItemInternal(const ash::ShelfID& id) {
343 const ash::ShelfItem* item = GetItem(id); 344 const ash::ShelfItem* item = GetItem(id);
344 if (item && item->status != ash::STATUS_CLOSED) 345 if (item && item->status != ash::STATUS_CLOSED)
345 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 346 UnpinRunningAppInternal(model_->ItemIndexByID(id));
346 else 347 else
347 RemoveShelfItem(id); 348 RemoveShelfItem(id);
348 } 349 }
349 350
350 bool ChromeLauncherController::IsPinned(ash::ShelfID id) { 351 bool ChromeLauncherController::IsPinned(const ash::ShelfID& id) {
351 const ash::ShelfItem* item = GetItem(id); 352 const ash::ShelfItem* item = GetItem(id);
352 return item && ItemTypeIsPinned(*item); 353 return item && ItemTypeIsPinned(*item);
353 } 354 }
354 355
355 void ChromeLauncherController::SetV1AppStatus(const std::string& app_id, 356 void ChromeLauncherController::SetV1AppStatus(const std::string& app_id,
356 ash::ShelfItemStatus status) { 357 ash::ShelfItemStatus status) {
357 ash::ShelfID id = GetShelfIDForAppID(app_id); 358 ash::ShelfID id = GetShelfIDForAppID(app_id);
358 const ash::ShelfItem* item = GetItem(id); 359 const ash::ShelfItem* item = GetItem(id);
359 if (item) { 360 if (item) {
360 if (!IsPinned(id) && status == ash::STATUS_CLOSED) 361 if (!IsPinned(id) && status == ash::STATUS_CLOSED)
361 RemoveShelfItem(id); 362 RemoveShelfItem(id);
362 else 363 else
363 SetItemStatus(id, status); 364 SetItemStatus(id, status);
364 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { 365 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) {
365 InsertAppLauncherItem( 366 InsertAppLauncherItem(
366 AppShortcutLauncherItemController::Create(ash::AppLaunchId(app_id)), 367 AppShortcutLauncherItemController::Create(ash::ShelfID(app_id)), status,
367 status, model_->item_count(), ash::TYPE_APP); 368 model_->item_count(), ash::TYPE_APP);
368 } 369 }
369 } 370 }
370 371
371 void ChromeLauncherController::Launch(ash::ShelfID id, int event_flags) { 372 void ChromeLauncherController::Launch(const ash::ShelfID& id, int event_flags) {
372 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 373 LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, event_flags);
James Cook 2017/05/04 16:38:49 Double-checking: We don't need to copy the ID anym
msw 2017/05/04 19:05:57 This should be fine. The one caller, LauncherConte
373 if (!delegate)
374 return; // In case invoked from menu and item closed while menu up.
375
376 // Launching some items replaces the associated item delegate instance,
377 // which destroys the app and launch id strings; making copies avoid crashes.
378 LaunchApp(ash::AppLaunchId(delegate->app_id(), delegate->launch_id()),
379 ash::LAUNCH_FROM_UNKNOWN, event_flags);
380 } 374 }
381 375
382 void ChromeLauncherController::Close(ash::ShelfID id) { 376 void ChromeLauncherController::Close(const ash::ShelfID& id) {
383 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 377 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
384 if (!delegate) 378 if (!delegate)
385 return; // May happen if menu closed. 379 return; // May happen if menu closed.
386 delegate->Close(); 380 delegate->Close();
387 } 381 }
388 382
389 bool ChromeLauncherController::IsOpen(ash::ShelfID id) { 383 bool ChromeLauncherController::IsOpen(const ash::ShelfID& id) {
390 const ash::ShelfItem* item = GetItem(id); 384 const ash::ShelfItem* item = GetItem(id);
391 return item && item->status != ash::STATUS_CLOSED; 385 return item && item->status != ash::STATUS_CLOSED;
392 } 386 }
393 387
394 bool ChromeLauncherController::IsPlatformApp(ash::ShelfID id) { 388 bool ChromeLauncherController::IsPlatformApp(const ash::ShelfID& id) {
395 std::string app_id = GetAppIDForShelfID(id); 389 std::string app_id = GetAppIDForShelfID(id);
396 const extensions::Extension* extension = 390 const extensions::Extension* extension =
397 GetExtensionForAppID(app_id, profile()); 391 GetExtensionForAppID(app_id, profile());
398 // An extension can be synced / updated at any time and therefore not be 392 // An extension can be synced / updated at any time and therefore not be
399 // available. 393 // available.
400 return extension ? extension->is_platform_app() : false; 394 return extension ? extension->is_platform_app() : false;
401 } 395 }
402 396
403 void ChromeLauncherController::LaunchApp(ash::AppLaunchId id, 397 void ChromeLauncherController::LaunchApp(const ash::ShelfID& id,
404 ash::ShelfLaunchSource source, 398 ash::ShelfLaunchSource source,
405 int event_flags) { 399 int event_flags) {
406 launcher_controller_helper_->LaunchApp(id, source, event_flags); 400 launcher_controller_helper_->LaunchApp(id, source, event_flags);
407 } 401 }
408 402
409 void ChromeLauncherController::ActivateApp(const std::string& app_id, 403 void ChromeLauncherController::ActivateApp(const std::string& app_id,
410 ash::ShelfLaunchSource source, 404 ash::ShelfLaunchSource source,
411 int event_flags) { 405 int event_flags) {
412 // If there is an existing non-shortcut delegate for this app, open it. 406 // If there is an existing delegate for this app, select it.
413 ash::ShelfID id = GetShelfIDForAppID(app_id); 407 const ash::ShelfID shelf_id(app_id);
414 if (id) { 408 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(shelf_id);
415 SelectItemWithSource(model_->GetShelfItemDelegate(id), source); 409 if (delegate) {
410 SelectItemWithSource(delegate, source);
416 return; 411 return;
417 } 412 }
418 413
419 // Create a temporary application launcher item and use it to see if there are 414 // Create a temporary delegate to see if there are running app instances.
420 // running instances.
421 ash::AppLaunchId app_launch_id(app_id);
422 std::unique_ptr<AppShortcutLauncherItemController> item_delegate = 415 std::unique_ptr<AppShortcutLauncherItemController> item_delegate =
423 AppShortcutLauncherItemController::Create(app_launch_id); 416 AppShortcutLauncherItemController::Create(shelf_id);
424 if (!item_delegate->GetRunningApplications().empty()) 417 if (!item_delegate->GetRunningApplications().empty())
425 SelectItemWithSource(item_delegate.get(), source); 418 SelectItemWithSource(item_delegate.get(), source);
426 else 419 else
427 LaunchApp(app_launch_id, source, event_flags); 420 LaunchApp(shelf_id, source, event_flags);
428 } 421 }
429 422
430 void ChromeLauncherController::SetLauncherItemImage( 423 void ChromeLauncherController::SetLauncherItemImage(
431 ash::ShelfID shelf_id, 424 const ash::ShelfID& shelf_id,
432 const gfx::ImageSkia& image) { 425 const gfx::ImageSkia& image) {
433 const ash::ShelfItem* item = GetItem(shelf_id); 426 const ash::ShelfItem* item = GetItem(shelf_id);
434 if (item) { 427 if (item) {
435 ash::ShelfItem new_item = *item; 428 ash::ShelfItem new_item = *item;
436 new_item.image = image; 429 new_item.image = image;
437 model_->Set(model_->ItemIndexByID(shelf_id), new_item); 430 model_->Set(model_->ItemIndexByID(shelf_id), new_item);
438 } 431 }
439 } 432 }
440 433
441 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, 434 void ChromeLauncherController::UpdateAppState(content::WebContents* contents,
442 AppState app_state) { 435 AppState app_state) {
443 std::string app_id = launcher_controller_helper_->GetAppID(contents); 436 std::string app_id = launcher_controller_helper_->GetAppID(contents);
444 437
445 // Check if the gMail app is loaded and it matches the given content. 438 // Check if the gMail app is loaded and it matches the given content.
446 // This special treatment is needed to address crbug.com/234268. 439 // This special treatment is needed to address crbug.com/234268.
447 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 440 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
448 app_id = kGmailAppId; 441 app_id = kGmailAppId;
449 442
450 // Check the old |app_id| for a tab. If the contents has changed we need to 443 // Check the old |app_id| for a tab. If the contents has changed we need to
451 // remove it from the previous app. 444 // remove it from the previous app.
452 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 445 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
453 std::string last_app_id = web_contents_to_app_id_[contents]; 446 std::string last_app_id = web_contents_to_app_id_[contents];
454 if (last_app_id != app_id) { 447 if (last_app_id != app_id) {
455 ash::ShelfID id = GetShelfIDForAppID(last_app_id); 448 ash::ShelfID id = GetShelfIDForAppID(last_app_id);
456 if (id) { 449 if (!id.IsEmpty()) {
457 // Since GetAppState() will use |web_contents_to_app_id_| we remove 450 // Since GetAppState() will use |web_contents_to_app_id_| we remove
458 // the connection before calling it. 451 // the connection before calling it.
459 web_contents_to_app_id_.erase(contents); 452 web_contents_to_app_id_.erase(contents);
460 SetItemStatus(id, GetAppState(last_app_id)); 453 SetItemStatus(id, GetAppState(last_app_id));
461 } 454 }
462 } 455 }
463 } 456 }
464 457
465 if (app_state == APP_STATE_REMOVED) 458 if (app_state == APP_STATE_REMOVED)
466 web_contents_to_app_id_.erase(contents); 459 web_contents_to_app_id_.erase(contents);
467 else 460 else
468 web_contents_to_app_id_[contents] = app_id; 461 web_contents_to_app_id_[contents] = app_id;
469 462
470 ash::ShelfID id = GetShelfIDForAppID(app_id); 463 ash::ShelfID id = GetShelfIDForAppID(app_id);
471 if (id) { 464 if (!id.IsEmpty()) {
472 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || 465 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE ||
473 app_state == APP_STATE_ACTIVE) 466 app_state == APP_STATE_ACTIVE)
474 ? ash::STATUS_ACTIVE 467 ? ash::STATUS_ACTIVE
475 : GetAppState(app_id)); 468 : GetAppState(app_id));
476 } 469 }
477 } 470 }
478 471
479 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( 472 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents(
480 content::WebContents* contents) { 473 content::WebContents* contents) {
481 std::string app_id = launcher_controller_helper_->GetAppID(contents); 474 std::string app_id = launcher_controller_helper_->GetAppID(contents);
482 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 475 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
483 app_id = kGmailAppId; 476 app_id = kGmailAppId;
484 477
485 ash::ShelfID id = GetShelfIDForAppID(app_id); 478 ash::ShelfID id = GetShelfIDForAppID(app_id);
486 // If there is no dedicated app item, use the browser shortcut item. 479 // If there is no dedicated app item, use the browser shortcut item.
487 return id == ash::kInvalidShelfID ? GetShelfIDForAppID(kChromeAppId) : id; 480 return id.IsEmpty() ? GetShelfIDForAppID(kChromeAppId) : id;
488 } 481 }
489 482
490 void ChromeLauncherController::SetRefocusURLPatternForTest(ash::ShelfID id, 483 void ChromeLauncherController::SetRefocusURLPatternForTest(
491 const GURL& url) { 484 const ash::ShelfID& id,
485 const GURL& url) {
492 const ash::ShelfItem* item = GetItem(id); 486 const ash::ShelfItem* item = GetItem(id);
493 if (item && !IsPlatformApp(id) && 487 if (item && !IsPlatformApp(id) &&
494 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { 488 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) {
495 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 489 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
496 AppShortcutLauncherItemController* item_controller = 490 AppShortcutLauncherItemController* item_controller =
497 static_cast<AppShortcutLauncherItemController*>(delegate); 491 static_cast<AppShortcutLauncherItemController*>(delegate);
498 item_controller->set_refocus_url(url); 492 item_controller->set_refocus_url(url);
499 } else { 493 } else {
500 NOTREACHED() << "Invalid launcher item or type"; 494 NOTREACHED() << "Invalid launcher item or type";
501 } 495 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 if ((web_contents_to_app_id_.find(web_contents) != 603 if ((web_contents_to_app_id_.find(web_contents) !=
610 web_contents_to_app_id_.end()) && 604 web_contents_to_app_id_.end()) &&
611 (web_contents_to_app_id_[web_contents] == app_id)) 605 (web_contents_to_app_id_[web_contents] == app_id))
612 return true; 606 return true;
613 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); 607 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents));
614 } 608 }
615 609
616 bool ChromeLauncherController::ContentCanBeHandledByGmailApp( 610 bool ChromeLauncherController::ContentCanBeHandledByGmailApp(
617 content::WebContents* web_contents) { 611 content::WebContents* web_contents) {
618 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); 612 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId);
619 if (id) { 613 if (!id.IsEmpty()) {
620 const GURL url = web_contents->GetURL(); 614 const GURL url = web_contents->GetURL();
621 // We need to extend the application matching for the gMail app beyond the 615 // We need to extend the application matching for the gMail app beyond the
622 // manifest file's specification. This is required because of the namespace 616 // manifest file's specification. This is required because of the namespace
623 // overlap with the offline app ("/mail/mu/"). 617 // overlap with the offline app ("/mail/mu/").
624 if (!base::MatchPattern(url.path(), "/mail/mu/*") && 618 if (!base::MatchPattern(url.path(), "/mail/mu/*") &&
625 base::MatchPattern(url.path(), "/mail/*") && 619 base::MatchPattern(url.path(), "/mail/*") &&
626 GetExtensionForAppID(kGmailAppId, profile()) && 620 GetExtensionForAppID(kGmailAppId, profile()) &&
627 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url)) 621 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url))
628 return true; 622 return true;
629 } 623 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 if (user_switch_observer_.get()) 691 if (user_switch_observer_.get())
698 user_switch_observer_->OnUserProfileReadyToSwitch(profile); 692 user_switch_observer_->OnUserProfileReadyToSwitch(profile);
699 } 693 }
700 694
701 ArcAppDeferredLauncherController* 695 ArcAppDeferredLauncherController*
702 ChromeLauncherController::GetArcDeferredLauncher() { 696 ChromeLauncherController::GetArcDeferredLauncher() {
703 return arc_deferred_launcher_.get(); 697 return arc_deferred_launcher_.get();
704 } 698 }
705 699
706 const std::string& ChromeLauncherController::GetLaunchIDForShelfID( 700 const std::string& ChromeLauncherController::GetLaunchIDForShelfID(
707 ash::ShelfID id) { 701 const ash::ShelfID& id) {
708 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 702 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
709 return delegate ? delegate->launch_id() : base::EmptyString(); 703 return delegate ? delegate->launch_id() : base::EmptyString();
710 } 704 }
711 705
712 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( 706 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp(
713 const std::string& app_id) { 707 const std::string& app_id) {
714 for (const auto& app_icon_loader : app_icon_loaders_) { 708 for (const auto& app_icon_loader : app_icon_loaders_) {
715 if (app_icon_loader->CanLoadImageForApp(app_id)) 709 if (app_icon_loader->CanLoadImageForApp(app_id))
716 return app_icon_loader.get(); 710 return app_icon_loader.get();
717 } 711 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 return model_->GetShelfIDForAppID(app_id); 773 return model_->GetShelfIDForAppID(app_id);
780 } 774 }
781 775
782 ash::ShelfID ChromeLauncherController::GetShelfIDForAppIDAndLaunchID( 776 ash::ShelfID ChromeLauncherController::GetShelfIDForAppIDAndLaunchID(
783 const std::string& app_id, 777 const std::string& app_id,
784 const std::string& launch_id) { 778 const std::string& launch_id) {
785 return model_->GetShelfIDForAppIDAndLaunchID(app_id, launch_id); 779 return model_->GetShelfIDForAppIDAndLaunchID(app_id, launch_id);
786 } 780 }
787 781
788 const std::string& ChromeLauncherController::GetAppIDForShelfID( 782 const std::string& ChromeLauncherController::GetAppIDForShelfID(
789 ash::ShelfID id) { 783 const ash::ShelfID& id) {
790 return model_->GetAppIDForShelfID(id); 784 return model_->GetAppIDForShelfID(id);
791 } 785 }
792 786
793 void ChromeLauncherController::PinAppWithID(const std::string& app_id) { 787 void ChromeLauncherController::PinAppWithID(const std::string& app_id) {
794 model_->PinAppWithID(app_id); 788 model_->PinAppWithID(app_id);
795 } 789 }
796 790
797 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { 791 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) {
798 return model_->IsAppPinned(app_id); 792 return model_->IsAppPinned(app_id);
799 } 793 }
(...skipping 28 matching lines...) Expand all
828 app_icon_loader->UpdateImage(app_id); 822 app_icon_loader->UpdateImage(app_id);
829 } 823 }
830 824
831 void ChromeLauncherController::OnAppUninstalledPrepared( 825 void ChromeLauncherController::OnAppUninstalledPrepared(
832 content::BrowserContext* browser_context, 826 content::BrowserContext* browser_context,
833 const std::string& app_id) { 827 const std::string& app_id) {
834 // Since we might have windowed apps of this type which might have 828 // Since we might have windowed apps of this type which might have
835 // outstanding locks which needs to be removed. 829 // outstanding locks which needs to be removed.
836 const Profile* profile = Profile::FromBrowserContext(browser_context); 830 const Profile* profile = Profile::FromBrowserContext(browser_context);
837 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 831 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
838 if (shelf_id != ash::kInvalidShelfID) 832 if (!shelf_id.IsEmpty())
839 CloseWindowedAppsFromRemovedExtension(app_id, profile); 833 CloseWindowedAppsFromRemovedExtension(app_id, profile);
840 834
841 if (IsAppPinned(app_id)) { 835 if (IsAppPinned(app_id)) {
842 if (profile == this->profile() && shelf_id != ash::kInvalidShelfID) { 836 if (profile == this->profile() && !shelf_id.IsEmpty()) {
843 // Some apps may be removed locally. Unpin the item without removing the 837 // Some apps may be removed locally. Unpin the item without removing the
844 // pin position from profile preferences. When needed, it is automatically 838 // pin position from profile preferences. When needed, it is automatically
845 // deleted on app list model update. 839 // deleted on app list model update.
846 UnpinShelfItemInternal(shelf_id); 840 UnpinShelfItemInternal(shelf_id);
847 } 841 }
848 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 842 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
849 if (app_icon_loader) 843 if (app_icon_loader)
850 app_icon_loader->ClearImage(app_id); 844 app_icon_loader->ClearImage(app_id);
851 } 845 }
852 } 846 }
853 847
854 /////////////////////////////////////////////////////////////////////////////// 848 ///////////////////////////////////////////////////////////////////////////////
855 // AppIconLoaderDelegate: 849 // AppIconLoaderDelegate:
856 850
857 void ChromeLauncherController::OnAppImageUpdated(const std::string& app_id, 851 void ChromeLauncherController::OnAppImageUpdated(const std::string& app_id,
858 const gfx::ImageSkia& image) { 852 const gfx::ImageSkia& image) {
859 // TODO: need to get this working for shortcuts. 853 // TODO: need to get this working for shortcuts.
860 for (int index = 0; index < model_->item_count(); ++index) { 854 for (int index = 0; index < model_->item_count(); ++index) {
861 ash::ShelfItem item = model_->items()[index]; 855 ash::ShelfItem item = model_->items()[index];
862 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id); 856 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id);
863 if (item.type == ash::TYPE_APP_PANEL || !delegate || 857 if (item.type == ash::TYPE_APP_PANEL || !delegate ||
864 delegate->image_set_by_controller() || 858 delegate->image_set_by_controller() || item.id.app_id() != app_id) {
865 item.app_launch_id.app_id() != app_id) {
866 continue; 859 continue;
867 } 860 }
868 item.image = image; 861 item.image = image;
869 if (arc_deferred_launcher_) 862 if (arc_deferred_launcher_)
870 arc_deferred_launcher_->MaybeApplySpinningEffect(app_id, &item.image); 863 arc_deferred_launcher_->MaybeApplySpinningEffect(app_id, &item.image);
871 model_->Set(index, item); 864 model_->Set(index, item);
872 // It's possible we're waiting on more than one item, so don't break. 865 // It's possible we're waiting on more than one item, so don't break.
873 } 866 }
874 } 867 }
875 868
(...skipping 11 matching lines...) Expand all
887 return false; 880 return false;
888 881
889 connector->BindInterface(ash::mojom::kServiceName, &shelf_controller_); 882 connector->BindInterface(ash::mojom::kServiceName, &shelf_controller_);
890 return true; 883 return true;
891 } 884 }
892 885
893 /////////////////////////////////////////////////////////////////////////////// 886 ///////////////////////////////////////////////////////////////////////////////
894 // ChromeLauncherController private: 887 // ChromeLauncherController private:
895 888
896 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItem( 889 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItem(
897 const ash::AppLaunchId& app_launch_id, 890 const ash::ShelfID& shelf_id,
898 int index) { 891 int index) {
899 return InsertAppLauncherItem( 892 return InsertAppLauncherItem(
900 AppShortcutLauncherItemController::Create(app_launch_id), 893 AppShortcutLauncherItemController::Create(shelf_id), ash::STATUS_CLOSED,
901 ash::STATUS_CLOSED, index, ash::TYPE_PINNED_APP); 894 index, ash::TYPE_PINNED_APP);
902 } 895 }
903 896
904 void ChromeLauncherController::RememberUnpinnedRunningApplicationOrder() { 897 void ChromeLauncherController::RememberUnpinnedRunningApplicationOrder() {
905 RunningAppListIds list; 898 RunningAppListIds list;
906 for (int i = 0; i < model_->item_count(); i++) { 899 for (int i = 0; i < model_->item_count(); i++) {
907 if (model_->items()[i].type == ash::TYPE_APP) 900 if (model_->items()[i].type == ash::TYPE_APP)
908 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); 901 list.push_back(GetAppIDForShelfID(model_->items()[i].id));
909 } 902 }
910 const std::string user_email = 903 const std::string user_email =
911 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); 904 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail();
(...skipping 14 matching lines...) Expand all
926 if (item && item->type == ash::TYPE_APP) { 919 if (item && item->type == ash::TYPE_APP) {
927 int app_index = model_->ItemIndexByID(item->id); 920 int app_index = model_->ItemIndexByID(item->id);
928 DCHECK_GE(app_index, 0); 921 DCHECK_GE(app_index, 0);
929 if (running_index != app_index) 922 if (running_index != app_index)
930 model_->Move(running_index, app_index); 923 model_->Move(running_index, app_index);
931 running_index++; 924 running_index++;
932 } 925 }
933 } 926 }
934 } 927 }
935 928
936 void ChromeLauncherController::RemoveShelfItem(ash::ShelfID id) { 929 void ChromeLauncherController::RemoveShelfItem(const ash::ShelfID& id) {
937 const int index = model_->ItemIndexByID(id); 930 const int index = model_->ItemIndexByID(id);
938 if (index >= 0 && index < model_->item_count()) 931 if (index >= 0 && index < model_->item_count())
939 model_->RemoveItemAt(index); 932 model_->RemoveItemAt(index);
940 } 933 }
941 934
942 void ChromeLauncherController::PinRunningAppInternal(int index, 935 void ChromeLauncherController::PinRunningAppInternal(
943 ash::ShelfID shelf_id) { 936 int index,
937 const ash::ShelfID& shelf_id) {
944 DCHECK_EQ(GetItem(shelf_id)->type, ash::TYPE_APP); 938 DCHECK_EQ(GetItem(shelf_id)->type, ash::TYPE_APP);
945 SetItemType(shelf_id, ash::TYPE_PINNED_APP); 939 SetItemType(shelf_id, ash::TYPE_PINNED_APP);
946 int running_index = model_->ItemIndexByID(shelf_id); 940 int running_index = model_->ItemIndexByID(shelf_id);
947 if (running_index < index) 941 if (running_index < index)
948 --index; 942 --index;
949 if (running_index != index) 943 if (running_index != index)
950 model_->Move(running_index, index); 944 model_->Move(running_index, index);
951 } 945 }
952 946
953 void ChromeLauncherController::UnpinRunningAppInternal(int index) { 947 void ChromeLauncherController::UnpinRunningAppInternal(int index) {
954 DCHECK(index >= 0 && index < model_->item_count()); 948 DCHECK(index >= 0 && index < model_->item_count());
955 ash::ShelfItem item = model_->items()[index]; 949 ash::ShelfItem item = model_->items()[index];
956 DCHECK_EQ(item.type, ash::TYPE_PINNED_APP); 950 DCHECK_EQ(item.type, ash::TYPE_PINNED_APP);
957 SetItemType(item.id, ash::TYPE_APP); 951 SetItemType(item.id, ash::TYPE_APP);
958 } 952 }
959 953
960 void ChromeLauncherController::SyncPinPosition(ash::ShelfID shelf_id) { 954 void ChromeLauncherController::SyncPinPosition(const ash::ShelfID& shelf_id) {
961 DCHECK(should_sync_pin_changes_); 955 DCHECK(should_sync_pin_changes_);
962 DCHECK(shelf_id); 956 DCHECK(!shelf_id.IsEmpty());
963 957
964 const int max_index = model_->item_count(); 958 const int max_index = model_->item_count();
965 const int index = model_->ItemIndexByID(shelf_id); 959 const int index = model_->ItemIndexByID(shelf_id);
966 DCHECK_GT(index, 0); 960 DCHECK_GT(index, 0);
967 961
968 const std::string& app_id = GetAppIDForShelfID(shelf_id); 962 const std::string& app_id = GetAppIDForShelfID(shelf_id);
969 DCHECK(!app_id.empty()); 963 DCHECK(!app_id.empty());
970 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); 964 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id);
971 965
972 std::string app_id_before; 966 std::string app_id_before;
973 std::string launch_id_before; 967 std::string launch_id_before;
974 std::vector<ash::AppLaunchId> app_launch_ids_after; 968 std::vector<ash::ShelfID> shelf_ids_after;
975 969
976 for (int i = index - 1; i > 0; --i) { 970 for (int i = index - 1; i > 0; --i) {
977 const ash::ShelfID shelf_id_before = model_->items()[i].id; 971 const ash::ShelfID shelf_id_before = model_->items()[i].id;
978 if (IsPinned(shelf_id_before)) { 972 if (IsPinned(shelf_id_before)) {
979 app_id_before = GetAppIDForShelfID(shelf_id_before); 973 app_id_before = GetAppIDForShelfID(shelf_id_before);
980 DCHECK(!app_id_before.empty()); 974 DCHECK(!app_id_before.empty());
981 launch_id_before = GetLaunchIDForShelfID(shelf_id_before); 975 launch_id_before = GetLaunchIDForShelfID(shelf_id_before);
982 break; 976 break;
983 } 977 }
984 } 978 }
985 979
986 for (int i = index + 1; i < max_index; ++i) { 980 for (int i = index + 1; i < max_index; ++i) {
987 const ash::ShelfID shelf_id_after = model_->items()[i].id; 981 const ash::ShelfID shelf_id_after = model_->items()[i].id;
988 if (IsPinned(shelf_id_after)) { 982 if (IsPinned(shelf_id_after)) {
989 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); 983 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after);
990 DCHECK(!app_id_after.empty()); 984 DCHECK(!app_id_after.empty());
991 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after); 985 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after);
992 app_launch_ids_after.push_back( 986 shelf_ids_after.push_back(ash::ShelfID(app_id_after, launch_id_after));
993 ash::AppLaunchId(app_id_after, launch_id_after));
994 } 987 }
995 } 988 }
996 989
997 ash::AppLaunchId app_launch_id_before = 990 ash::ShelfID shelf_id_before = ash::ShelfID(app_id_before, launch_id_before);
998 app_id_before.empty() ? ash::AppLaunchId() 991 ash::launcher::SetPinPosition(profile(), ash::ShelfID(app_id, launch_id),
999 : ash::AppLaunchId(app_id_before, launch_id_before); 992 shelf_id_before, shelf_ids_after);
1000
1001 ash::launcher::SetPinPosition(profile(), ash::AppLaunchId(app_id, launch_id),
1002 app_launch_id_before, app_launch_ids_after);
1003 } 993 }
1004 994
1005 void ChromeLauncherController::OnSyncModelUpdated() { 995 void ChromeLauncherController::OnSyncModelUpdated() {
1006 UpdateAppLaunchersFromPref(); 996 UpdateAppLaunchersFromPref();
1007 } 997 }
1008 998
1009 void ChromeLauncherController::OnIsSyncingChanged() { 999 void ChromeLauncherController::OnIsSyncingChanged() {
1010 UpdateAppLaunchersFromPref(); 1000 UpdateAppLaunchersFromPref();
1011 } 1001 }
1012 1002
1013 void ChromeLauncherController::ScheduleUpdateAppLaunchersFromPref() { 1003 void ChromeLauncherController::ScheduleUpdateAppLaunchersFromPref() {
1014 base::ThreadTaskRunnerHandle::Get()->PostTask( 1004 base::ThreadTaskRunnerHandle::Get()->PostTask(
1015 FROM_HERE, 1005 FROM_HERE,
1016 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, 1006 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
1017 weak_ptr_factory_.GetWeakPtr())); 1007 weak_ptr_factory_.GetWeakPtr()));
1018 } 1008 }
1019 1009
1020 void ChromeLauncherController::UpdateAppLaunchersFromPref() { 1010 void ChromeLauncherController::UpdateAppLaunchersFromPref() {
1021 // Do not sync pin changes during this function to avoid cyclical updates. 1011 // Do not sync pin changes during this function to avoid cyclical updates.
1022 // This function makes the shelf model reflect synced prefs, and should not 1012 // This function makes the shelf model reflect synced prefs, and should not
1023 // cyclically trigger sync changes (eg. ShelfItemAdded calls SyncPinPosition). 1013 // cyclically trigger sync changes (eg. ShelfItemAdded calls SyncPinPosition).
1024 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler(); 1014 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler();
1025 1015
1026 const std::vector<ash::AppLaunchId> pinned_apps = 1016 const std::vector<ash::ShelfID> pinned_apps =
1027 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), 1017 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(),
1028 launcher_controller_helper_.get()); 1018 launcher_controller_helper_.get());
1029 1019
1030 int index = 0; 1020 int index = 0;
1031 // Skip app list items if it exists. 1021 // Skip app list items if it exists.
1032 if (model_->items()[0].type == ash::TYPE_APP_LIST) 1022 if (model_->items()[0].type == ash::TYPE_APP_LIST)
1033 ++index; 1023 ++index;
1034 1024
1035 // Apply pins in two steps. At the first step, go through the list of apps to 1025 // Apply pins in two steps. At the first step, go through the list of apps to
1036 // pin, move existing pin to current position specified by |index| or create 1026 // pin, move existing pin to current position specified by |index| or create
1037 // the new pin at that position. 1027 // the new pin at that position.
1038 for (const auto& pref_app_launch_id : pinned_apps) { 1028 for (const auto& pref_shelf_id : pinned_apps) {
1039 // Filter out apps that may be mapped wrongly. 1029 // Filter out apps that may be mapped wrongly.
1040 // TODO(khmel): b/31703859 is to refactore shelf mapping. 1030 // TODO(khmel): b/31703859 is to refactore shelf mapping.
1041 const std::string app_id = pref_app_launch_id.app_id(); 1031 const std::string app_id = pref_shelf_id.app_id();
1042 const std::string shelf_app_id = 1032 const std::string shelf_app_id =
1043 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 1033 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
1044 if (shelf_app_id != app_id) 1034 if (shelf_app_id != app_id)
1045 continue; 1035 continue;
1046 1036
1047 // Update apps icon if applicable. 1037 // Update apps icon if applicable.
1048 OnAppUpdated(profile(), app_id); 1038 OnAppUpdated(profile(), app_id);
1049 1039
1050 // Find existing pin or app from the right of current |index|. 1040 // Find existing pin or app from the right of current |index|.
1051 int app_index = index; 1041 int app_index = index;
1052 for (; app_index < model_->item_count(); ++app_index) { 1042 for (; app_index < model_->item_count(); ++app_index) {
1053 const ash::ShelfItem& item = model_->items()[app_index]; 1043 const ash::ShelfItem& item = model_->items()[app_index];
1054 if (item.app_launch_id.app_id() == app_id && 1044 if (item.id == pref_shelf_id)
1055 item.app_launch_id.launch_id() == pref_app_launch_id.launch_id()) {
1056 break; 1045 break;
1057 }
1058 } 1046 }
1059 if (app_index < model_->item_count()) { 1047 if (app_index < model_->item_count()) {
1060 // Found existing pin or running app. 1048 // Found existing pin or running app.
1061 const ash::ShelfItem item = model_->items()[app_index]; 1049 const ash::ShelfItem item = model_->items()[app_index];
1062 if (ItemTypeIsPinned(item)) { 1050 if (ItemTypeIsPinned(item)) {
1063 // Just move to required position or keep it inplace. 1051 // Just move to required position or keep it inplace.
1064 model_->Move(app_index, index); 1052 model_->Move(app_index, index);
1065 } else { 1053 } else {
1066 PinRunningAppInternal(index, item.id); 1054 PinRunningAppInternal(index, item.id);
1067 } 1055 }
1068 DCHECK_EQ(model_->ItemIndexByID(item.id), index); 1056 DCHECK_EQ(model_->ItemIndexByID(item.id), index);
1069 } else { 1057 } else {
1070 // This is fresh pin. Create new one. 1058 // This is fresh pin. Create new one.
1071 DCHECK_NE(app_id, kChromeAppId); 1059 DCHECK_NE(app_id, kChromeAppId);
1072 CreateAppShortcutLauncherItem(pref_app_launch_id, index); 1060 CreateAppShortcutLauncherItem(pref_shelf_id, index);
1073 } 1061 }
1074 ++index; 1062 ++index;
1075 } 1063 }
1076 1064
1077 // At second step remove any pin to the right from the current index. 1065 // At second step remove any pin to the right from the current index.
1078 while (index < model_->item_count()) { 1066 while (index < model_->item_count()) {
1079 const ash::ShelfItem item = model_->items()[index]; 1067 const ash::ShelfItem item = model_->items()[index];
1080 if (item.type == ash::TYPE_PINNED_APP) 1068 if (item.type == ash::TYPE_PINNED_APP)
1081 UnpinShelfItemInternal(item.id); 1069 UnpinShelfItemInternal(item.id);
1082 else 1070 else
1083 ++index; 1071 ++index;
1084 } 1072 }
1085 1073
1086 UpdatePolicyPinnedAppsFromPrefs(); 1074 UpdatePolicyPinnedAppsFromPrefs();
1087 } 1075 }
1088 1076
1089 void ChromeLauncherController::UpdatePolicyPinnedAppsFromPrefs() { 1077 void ChromeLauncherController::UpdatePolicyPinnedAppsFromPrefs() {
1090 for (int index = 0; index < model_->item_count(); index++) { 1078 for (int index = 0; index < model_->item_count(); index++) {
1091 ash::ShelfItem item = model_->items()[index]; 1079 ash::ShelfItem item = model_->items()[index];
1092 const bool pinned_by_policy = 1080 const bool pinned_by_policy =
1093 GetPinnableForAppID(item.app_launch_id.app_id(), profile()) == 1081 GetPinnableForAppID(item.id.app_id(), profile()) ==
1094 AppListControllerDelegate::PIN_FIXED; 1082 AppListControllerDelegate::PIN_FIXED;
1095 if (item.pinned_by_policy != pinned_by_policy) { 1083 if (item.pinned_by_policy != pinned_by_policy) {
1096 item.pinned_by_policy = pinned_by_policy; 1084 item.pinned_by_policy = pinned_by_policy;
1097 model_->Set(index, item); 1085 model_->Set(index, item);
1098 } 1086 }
1099 } 1087 }
1100 } 1088 }
1101 1089
1102 void ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs() { 1090 void ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs() {
1103 const PrefService* service = profile()->GetPrefs(); 1091 const PrefService* service = profile()->GetPrefs();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 } 1131 }
1144 } 1132 }
1145 return status; 1133 return status;
1146 } 1134 }
1147 1135
1148 ash::ShelfID ChromeLauncherController::InsertAppLauncherItem( 1136 ash::ShelfID ChromeLauncherController::InsertAppLauncherItem(
1149 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, 1137 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
1150 ash::ShelfItemStatus status, 1138 ash::ShelfItemStatus status,
1151 int index, 1139 int index,
1152 ash::ShelfItemType shelf_item_type) { 1140 ash::ShelfItemType shelf_item_type) {
1153 ash::ShelfID id = model_->next_id();
1154 CHECK(!GetItem(id));
1155 CHECK(item_delegate); 1141 CHECK(item_delegate);
1142 CHECK(!GetItem(item_delegate->shelf_id()));
1156 // Ash's ShelfWindowWatcher handles app panel windows separately. 1143 // Ash's ShelfWindowWatcher handles app panel windows separately.
1157 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); 1144 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type);
1158 ash::ShelfItem item; 1145 ash::ShelfItem item;
1159 item.status = status; 1146 item.status = status;
1160 item.type = shelf_item_type; 1147 item.type = shelf_item_type;
1161 item.app_launch_id = item_delegate->app_launch_id(); 1148 item.id = item_delegate->shelf_id();
1162 // Set the delegate first to avoid constructing one in ShelfItemAdded. 1149 // Set the delegate first to avoid constructing one in ShelfItemAdded.
1163 model_->SetShelfItemDelegate(id, std::move(item_delegate)); 1150 model_->SetShelfItemDelegate(item.id, std::move(item_delegate));
1164 model_->AddAt(index, item); 1151 model_->AddAt(index, item);
1165 return id; 1152 return item.id;
1166 } 1153 }
1167 1154
1168 void ChromeLauncherController::CreateBrowserShortcutLauncherItem() { 1155 void ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1169 // Do not sync the pin position of the browser shortcut item when it is added; 1156 // Do not sync the pin position of the browser shortcut item when it is added;
1170 // its initial position before prefs have loaded is unimportant and the sync 1157 // its initial position before prefs have loaded is unimportant and the sync
1171 // service may not yet be initialized. 1158 // service may not yet be initialized.
1172 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler(); 1159 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler();
1173 1160
1174 ash::ShelfItem browser_shortcut; 1161 ash::ShelfItem browser_shortcut;
1175 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1162 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1176 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1163 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1177 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1164 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1178 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 1165 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
1179 browser_shortcut.app_launch_id = ash::AppLaunchId(kChromeAppId); 1166 browser_shortcut.id = ash::ShelfID(kChromeAppId);
1180 ash::ShelfID id = model_->next_id();
1181 std::unique_ptr<BrowserShortcutLauncherItemController> item_delegate = 1167 std::unique_ptr<BrowserShortcutLauncherItemController> item_delegate =
1182 base::MakeUnique<BrowserShortcutLauncherItemController>(model_); 1168 base::MakeUnique<BrowserShortcutLauncherItemController>(model_);
1183 BrowserShortcutLauncherItemController* item_controller = item_delegate.get(); 1169 BrowserShortcutLauncherItemController* item_controller = item_delegate.get();
1184 // Set the delegate first to avoid constructing another one in ShelfItemAdded. 1170 // Set the delegate first to avoid constructing another one in ShelfItemAdded.
1185 model_->SetShelfItemDelegate(id, std::move(item_delegate)); 1171 model_->SetShelfItemDelegate(browser_shortcut.id, std::move(item_delegate));
1186 model_->AddAt(0, browser_shortcut); 1172 model_->AddAt(0, browser_shortcut);
1187 item_controller->UpdateBrowserItemState(); 1173 item_controller->UpdateBrowserItemState();
1188 } 1174 }
1189 1175
1190 bool ChromeLauncherController::IsIncognito( 1176 bool ChromeLauncherController::IsIncognito(
1191 const content::WebContents* web_contents) const { 1177 const content::WebContents* web_contents) const {
1192 const Profile* profile = 1178 const Profile* profile =
1193 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1179 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1194 return profile->IsOffTheRecord() && !profile->IsGuestSession() && 1180 return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
1195 !profile->IsSystemProfile(); 1181 !profile->IsSystemProfile();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 1354
1369 void ChromeLauncherController::ShelfItemAdded(int index) { 1355 void ChromeLauncherController::ShelfItemAdded(int index) {
1370 // Update the pin position preference as needed. 1356 // Update the pin position preference as needed.
1371 ash::ShelfItem item = model_->items()[index]; 1357 ash::ShelfItem item = model_->items()[index];
1372 if (ItemTypeIsPinned(item) && should_sync_pin_changes_) 1358 if (ItemTypeIsPinned(item) && should_sync_pin_changes_)
1373 SyncPinPosition(item.id); 1359 SyncPinPosition(item.id);
1374 1360
1375 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859 1361 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859
1376 const std::string shelf_app_id = 1362 const std::string shelf_app_id =
1377 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( 1363 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(
1378 item.app_launch_id.app_id()); 1364 item.id.app_id());
1379 1365
1380 // Fetch and update the icon for the app's item. 1366 // Fetch and update the icon for the app's item.
1381 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(shelf_app_id); 1367 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(shelf_app_id);
1382 if (app_icon_loader) { 1368 if (app_icon_loader) {
1383 app_icon_loader->FetchImage(shelf_app_id); 1369 app_icon_loader->FetchImage(shelf_app_id);
1384 app_icon_loader->UpdateImage(shelf_app_id); 1370 app_icon_loader->UpdateImage(shelf_app_id);
1385 } 1371 }
1386 1372
1387 // Update the item with any missing Chrome-specific info. 1373 // Update the item with any missing Chrome-specific info.
1388 if (item.type == ash::TYPE_APP || item.type == ash::TYPE_PINNED_APP) { 1374 if (item.type == ash::TYPE_APP || item.type == ash::TYPE_PINNED_APP) {
(...skipping 12 matching lines...) Expand all
1401 needs_update = true; 1387 needs_update = true;
1402 item.status = status; 1388 item.status = status;
1403 } 1389 }
1404 if (needs_update) 1390 if (needs_update)
1405 model_->Set(index, item); 1391 model_->Set(index, item);
1406 } 1392 }
1407 1393
1408 // Construct a ShelfItemDelegate for the item if one does not yet exist. 1394 // Construct a ShelfItemDelegate for the item if one does not yet exist.
1409 if (!model_->GetShelfItemDelegate(item.id)) { 1395 if (!model_->GetShelfItemDelegate(item.id)) {
1410 model_->SetShelfItemDelegate( 1396 model_->SetShelfItemDelegate(
1411 item.id, AppShortcutLauncherItemController::Create(ash::AppLaunchId( 1397 item.id, AppShortcutLauncherItemController::Create(
1412 shelf_app_id, item.app_launch_id.launch_id()))); 1398 ash::ShelfID(shelf_app_id, item.id.launch_id())));
1413 } 1399 }
1414 } 1400 }
1415 1401
1416 void ChromeLauncherController::ShelfItemRemoved( 1402 void ChromeLauncherController::ShelfItemRemoved(
1417 int index, 1403 int index,
1418 const ash::ShelfItem& old_item) { 1404 const ash::ShelfItem& old_item) {
1419 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859 1405 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859
1420 const std::string shelf_app_id = 1406 const std::string shelf_app_id =
1421 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( 1407 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(
1422 old_item.app_launch_id.app_id()); 1408 old_item.id.app_id());
1423 1409
1424 // Remove the pin position from preferences as needed. 1410 // Remove the pin position from preferences as needed.
1425 if (ItemTypeIsPinned(old_item) && should_sync_pin_changes_) { 1411 if (ItemTypeIsPinned(old_item) && should_sync_pin_changes_) {
1426 ash::AppLaunchId app_launch_id(shelf_app_id, 1412 ash::ShelfID shelf_id(shelf_app_id, old_item.id.launch_id());
1427 old_item.app_launch_id.launch_id()); 1413 ash::launcher::RemovePinPosition(profile(), shelf_id);
1428 ash::launcher::RemovePinPosition(profile(), app_launch_id);
1429 } 1414 }
1430 1415
1431 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(shelf_app_id); 1416 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(shelf_app_id);
1432 if (app_icon_loader) 1417 if (app_icon_loader)
1433 app_icon_loader->ClearImage(shelf_app_id); 1418 app_icon_loader->ClearImage(shelf_app_id);
1434 } 1419 }
1435 1420
1436 void ChromeLauncherController::ShelfItemMoved(int start_index, 1421 void ChromeLauncherController::ShelfItemMoved(int start_index,
1437 int target_index) { 1422 int target_index) {
1438 // Update the pin position preference as needed. 1423 // Update the pin position preference as needed.
(...skipping 10 matching lines...) Expand all
1449 return; 1434 return;
1450 1435
1451 const ash::ShelfItem& item = model_->items()[index]; 1436 const ash::ShelfItem& item = model_->items()[index];
1452 // Add or remove the pin position from preferences as needed. 1437 // Add or remove the pin position from preferences as needed.
1453 if (!ItemTypeIsPinned(old_item) && ItemTypeIsPinned(item)) { 1438 if (!ItemTypeIsPinned(old_item) && ItemTypeIsPinned(item)) {
1454 SyncPinPosition(item.id); 1439 SyncPinPosition(item.id);
1455 } else if (ItemTypeIsPinned(old_item) && !ItemTypeIsPinned(item)) { 1440 } else if (ItemTypeIsPinned(old_item) && !ItemTypeIsPinned(item)) {
1456 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859 1441 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859
1457 const std::string shelf_app_id = 1442 const std::string shelf_app_id =
1458 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( 1443 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(
1459 old_item.app_launch_id.app_id()); 1444 old_item.id.app_id());
1460 1445
1461 ash::AppLaunchId app_launch_id(shelf_app_id, 1446 ash::ShelfID shelf_id(shelf_app_id, old_item.id.launch_id());
1462 old_item.app_launch_id.launch_id()); 1447 ash::launcher::RemovePinPosition(profile(), shelf_id);
1463 ash::launcher::RemovePinPosition(profile(), app_launch_id);
1464 } 1448 }
1465 } 1449 }
1466 1450
1467 /////////////////////////////////////////////////////////////////////////////// 1451 ///////////////////////////////////////////////////////////////////////////////
1468 // ash::WindowTreeHostManager::Observer: 1452 // ash::WindowTreeHostManager::Observer:
1469 1453
1470 void ChromeLauncherController::OnDisplayConfigurationChanged() { 1454 void ChromeLauncherController::OnDisplayConfigurationChanged() {
1471 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. 1455 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs.
1472 // Because it might be called by some operations, like crbug.com/627040 1456 // Because it might be called by some operations, like crbug.com/627040
1473 // rotating screen. 1457 // rotating screen.
(...skipping 14 matching lines...) Expand all
1488 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); 1472 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE);
1489 1473
1490 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); 1474 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST);
1491 DCHECK_GE(app_list_index, 0); 1475 DCHECK_GE(app_list_index, 0);
1492 ash::ShelfItem item = model_->items()[app_list_index]; 1476 ash::ShelfItem item = model_->items()[app_list_index];
1493 if (item.title != title) { 1477 if (item.title != title) {
1494 item.title = title; 1478 item.title = title;
1495 model_->Set(app_list_index, item); 1479 model_->Set(app_list_index, item);
1496 } 1480 }
1497 } 1481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698