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

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

Issue 2391253004: Use mojo Shelf interfaces for both mash and classic ash. (Closed)
Patch Set: Sync and rebase. Created 4 years, 2 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_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
11 #include "ash/common/multi_profile_uma.h" 11 #include "ash/common/multi_profile_uma.h"
12 #include "ash/common/shelf/shelf_model.h" 12 #include "ash/common/shelf/shelf_model.h"
13 #include "ash/common/shelf/shelf_widget.h"
14 #include "ash/common/shelf/wm_shelf.h" 13 #include "ash/common/shelf/wm_shelf.h"
15 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
16 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
17 #include "ash/common/wm_window.h" 16 #include "ash/common/wm_window.h"
18 #include "ash/resources/grit/ash_resources.h" 17 #include "ash/resources/grit/ash_resources.h"
19 #include "ash/root_window_controller.h" 18 #include "ash/root_window_controller.h"
20 #include "ash/shell.h" 19 #include "ash/shell.h"
21 #include "ash/wm/window_util.h" 20 #include "ash/wm/window_util.h"
22 #include "base/command_line.h" 21 #include "base/command_line.h"
23 #include "base/macros.h" 22 #include "base/macros.h"
24 #include "base/strings/pattern.h" 23 #include "base/strings/pattern.h"
25 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/values.h" 27 #include "base/values.h"
29 #include "build/build_config.h" 28 #include "build/build_config.h"
30 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chrome_notification_types.h" 30 #include "chrome/browser/chrome_notification_types.h"
32 #include "chrome/browser/chromeos/extensions/gfx_utils.h" 31 #include "chrome/browser/chromeos/extensions/gfx_utils.h"
33 #include "chrome/browser/defaults.h" 32 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/extensions/extension_app_icon_loader.h"
35 #include "chrome/browser/extensions/extension_util.h" 33 #include "chrome/browser/extensions/extension_util.h"
36 #include "chrome/browser/extensions/launch_util.h" 34 #include "chrome/browser/extensions/launch_util.h"
37 #include "chrome/browser/prefs/incognito_mode_prefs.h" 35 #include "chrome/browser/prefs/incognito_mode_prefs.h"
38 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/profiles/profile_manager.h" 37 #include "chrome/browser/profiles/profile_manager.h"
40 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 38 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
41 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
42 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 39 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
43 #include "chrome/browser/ui/ash/app_sync_ui_state.h" 40 #include "chrome/browser/ui/ash/app_sync_ui_state.h"
44 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 41 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
45 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" 42 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
46 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " 43 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 44 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
48 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
49 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" 46 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h"
50 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 47 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
51 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 48 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) { 178 void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) {
182 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == 179 if (chrome::MultiUserWindowManager::GetMultiProfileMode() ==
183 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) 180 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED)
184 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); 181 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile);
185 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile()); 182 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile());
186 } 183 }
187 184
188 ChromeLauncherControllerImpl::ChromeLauncherControllerImpl( 185 ChromeLauncherControllerImpl::ChromeLauncherControllerImpl(
189 Profile* profile, 186 Profile* profile,
190 ash::ShelfModel* model) 187 ash::ShelfModel* model)
191 : model_(model), profile_(profile), weak_ptr_factory_(this) { 188 : model_(model), weak_ptr_factory_(this) {
192 DCHECK(model_); 189 DCHECK(model_);
193 if (!profile_) { 190 if (!profile) {
194 // If no profile was passed, we take the currently active profile and use it 191 // If no profile was passed, we take the currently active profile and use it
195 // as the owner of the current desktop. 192 // as the owner of the current desktop.
196 // Use the original profile as on chromeos we may get a temporary off the 193 // Use the original profile as on chromeos we may get a temporary off the
197 // record profile, unless in guest session (where off the record profile is 194 // record profile, unless in guest session (where off the record profile is
198 // the right one). 195 // the right one).
199 profile_ = ProfileManager::GetActiveUserProfile(); 196 profile = ProfileManager::GetActiveUserProfile();
200 if (!profile_->IsGuestSession() && !profile_->IsSystemProfile()) 197 if (!profile->IsGuestSession() && !profile->IsSystemProfile())
201 profile_ = profile_->GetOriginalProfile(); 198 profile = profile->GetOriginalProfile();
202 199
203 app_sync_ui_state_ = AppSyncUIState::Get(profile_); 200 app_sync_ui_state_ = AppSyncUIState::Get(profile);
204 if (app_sync_ui_state_) 201 if (app_sync_ui_state_)
205 app_sync_ui_state_->AddObserver(this); 202 app_sync_ui_state_->AddObserver(this);
206 } 203 }
207 204
208 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) { 205 if (arc::ArcAuthService::IsAllowedForProfile(profile))
209 arc_deferred_launcher_.reset(new ArcAppDeferredLauncherController(this)); 206 arc_deferred_launcher_.reset(new ArcAppDeferredLauncherController(this));
210 }
211 207
212 // All profile relevant settings get bound to the current profile. 208 // All profile relevant settings get bound to the current profile.
213 AttachProfile(profile_); 209 AttachProfile(profile);
214 model_->AddObserver(this); 210 model_->AddObserver(this);
215 211
216 // In multi profile mode we might have a window manager. We try to create it 212 // In multi profile mode we might have a window manager. We try to create it
217 // here. If the instantiation fails, the manager is not needed. 213 // here. If the instantiation fails, the manager is not needed.
218 chrome::MultiUserWindowManager::CreateInstance(); 214 chrome::MultiUserWindowManager::CreateInstance();
219 215
220 // On Chrome OS using multi profile we want to switch the content of the shelf 216 // On Chrome OS using multi profile we want to switch the content of the shelf
221 // with a user change. Note that for unit tests the instance can be NULL. 217 // with a user change. Note that for unit tests the instance can be NULL.
222 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != 218 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
223 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) { 219 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 293
298 void ChromeLauncherControllerImpl::Init() { 294 void ChromeLauncherControllerImpl::Init() {
299 CreateBrowserShortcutLauncherItem(); 295 CreateBrowserShortcutLauncherItem();
300 UpdateAppLaunchersFromPref(); 296 UpdateAppLaunchersFromPref();
301 297
302 // TODO(sky): update unit test so that this test isn't necessary. 298 // TODO(sky): update unit test so that this test isn't necessary.
303 if (ash::Shell::HasInstance()) 299 if (ash::Shell::HasInstance())
304 SetVirtualKeyboardBehaviorFromPrefs(); 300 SetVirtualKeyboardBehaviorFromPrefs();
305 301
306 prefs_observer_ = 302 prefs_observer_ =
307 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile_); 303 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
308 } 304 }
309 305
310 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( 306 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem(
311 LauncherItemController* controller, 307 LauncherItemController* controller,
312 const std::string& app_id, 308 const std::string& app_id,
313 ash::ShelfItemStatus status) { 309 ash::ShelfItemStatus status) {
314 CHECK(controller); 310 CHECK(controller);
315 int index = 0; 311 int index = 0;
316 // Panels are inserted on the left so as not to push all existing panels over. 312 // Panels are inserted on the left so as not to push all existing panels over.
317 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL) 313 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { 382 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) {
387 UnpinAndUpdatePrefs(id, true /* update_prefs */); 383 UnpinAndUpdatePrefs(id, true /* update_prefs */);
388 } 384 }
389 385
390 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, 386 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id,
391 bool update_prefs) { 387 bool update_prefs) {
392 LauncherItemController* controller = GetLauncherItemController(id); 388 LauncherItemController* controller = GetLauncherItemController(id);
393 CHECK(controller); 389 CHECK(controller);
394 390
395 if (update_prefs) 391 if (update_prefs)
396 ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id)); 392 ash::launcher::RemovePinPosition(profile(), GetAppIDForShelfID(id));
397 393
398 if (controller->type() == LauncherItemController::TYPE_APP || 394 if (controller->type() == LauncherItemController::TYPE_APP ||
399 controller->locked()) { 395 controller->locked()) {
400 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 396 UnpinRunningAppInternal(model_->ItemIndexByID(id));
401 } else { 397 } else {
402 LauncherItemClosed(id); 398 LauncherItemClosed(id);
403 } 399 }
404 } 400 }
405 401
406 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 402 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (!controller) 470 if (!controller)
475 return false; 471 return false;
476 return controller->IsOpen(); 472 return controller->IsOpen();
477 } 473 }
478 474
479 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { 475 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) {
480 if (!HasShelfIDToAppIDMapping(id)) 476 if (!HasShelfIDToAppIDMapping(id))
481 return false; 477 return false;
482 478
483 std::string app_id = GetAppIDForShelfID(id); 479 std::string app_id = GetAppIDForShelfID(id);
484 const Extension* extension = GetExtensionForAppID(app_id, profile_); 480 const Extension* extension = GetExtensionForAppID(app_id, profile());
485 // An extension can be synced / updated at any time and therefore not be 481 // An extension can be synced / updated at any time and therefore not be
486 // available. 482 // available.
487 return extension ? extension->is_platform_app() : false; 483 return extension ? extension->is_platform_app() : false;
488 } 484 }
489 485
490 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id,
491 ash::LaunchSource source,
492 int event_flags) {
493 launcher_controller_helper_->LaunchApp(app_id, source, event_flags);
494 }
495
496 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, 486 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id,
497 ash::LaunchSource source, 487 ash::LaunchSource source,
498 int event_flags) { 488 int event_flags) {
499 // If there is an existing non-shortcut controller for this app, open it. 489 // If there is an existing non-shortcut controller for this app, open it.
500 ash::ShelfID id = GetShelfIDForAppID(app_id); 490 ash::ShelfID id = GetShelfIDForAppID(app_id);
501 if (id) { 491 if (id) {
502 LauncherItemController* controller = GetLauncherItemController(id); 492 LauncherItemController* controller = GetLauncherItemController(id);
503 controller->Activate(source); 493 controller->Activate(source);
504 return; 494 return;
505 } 495 }
506 496
507 // Create a temporary application launcher item and use it to see if there are 497 // Create a temporary application launcher item and use it to see if there are
508 // running instances. 498 // running instances.
509 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 499 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
510 AppShortcutLauncherItemController::Create(app_id, "", this)); 500 AppShortcutLauncherItemController::Create(app_id, "", this));
511 if (!app_controller->GetRunningApplications().empty()) 501 if (!app_controller->GetRunningApplications().empty())
512 app_controller->Activate(source); 502 app_controller->Activate(source);
513 else 503 else
514 LaunchApp(app_id, source, event_flags); 504 LaunchApp(app_id, source, event_flags);
515 } 505 }
516 506
517 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( 507 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType(
518 ash::ShelfID id) { 508 ash::ShelfID id) {
519 const Extension* extension = 509 const Extension* extension =
520 GetExtensionForAppID(GetAppIDForShelfID(id), profile_); 510 GetExtensionForAppID(GetAppIDForShelfID(id), profile());
521 511
522 // An extension can be unloaded/updated/unavailable at any time. 512 // An extension can be unloaded/updated/unavailable at any time.
523 if (!extension) 513 if (!extension)
524 return extensions::LAUNCH_TYPE_DEFAULT; 514 return extensions::LAUNCH_TYPE_DEFAULT;
525 515
526 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), 516 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()),
527 extension); 517 extension);
528 } 518 }
529 519
530 void ChromeLauncherControllerImpl::SetLauncherItemImage( 520 void ChromeLauncherControllerImpl::SetLauncherItemImage(
531 ash::ShelfID shelf_id, 521 ash::ShelfID shelf_id,
532 const gfx::ImageSkia& image) { 522 const gfx::ImageSkia& image) {
533 int index = model_->ItemIndexByID(shelf_id); 523 int index = model_->ItemIndexByID(shelf_id);
534 if (index == -1) 524 if (index == -1)
535 return; 525 return;
536 ash::ShelfItem item = model_->items()[index]; 526 ash::ShelfItem item = model_->items()[index];
(...skipping 11 matching lines...) Expand all
548 return type == ash::TYPE_WINDOWED_APP; 538 return type == ash::TYPE_WINDOWED_APP;
549 } 539 }
550 540
551 void ChromeLauncherControllerImpl::SetLaunchType( 541 void ChromeLauncherControllerImpl::SetLaunchType(
552 ash::ShelfID id, 542 ash::ShelfID id,
553 extensions::LaunchType launch_type) { 543 extensions::LaunchType launch_type) {
554 LauncherItemController* controller = GetLauncherItemController(id); 544 LauncherItemController* controller = GetLauncherItemController(id);
555 if (!controller) 545 if (!controller)
556 return; 546 return;
557 547
558 extensions::SetLaunchType(profile_, controller->app_id(), launch_type); 548 extensions::SetLaunchType(profile(), controller->app_id(), launch_type);
559 }
560
561 Profile* ChromeLauncherControllerImpl::GetProfile() {
562 return profile_;
563 } 549 }
564 550
565 void ChromeLauncherControllerImpl::UpdateAppState( 551 void ChromeLauncherControllerImpl::UpdateAppState(
566 content::WebContents* contents, 552 content::WebContents* contents,
567 AppState app_state) { 553 AppState app_state) {
568 std::string app_id = launcher_controller_helper_->GetAppID(contents); 554 std::string app_id = launcher_controller_helper()->GetAppID(contents);
569 555
570 // Check if the gMail app is loaded and it matches the given content. 556 // Check if the gMail app is loaded and it matches the given content.
571 // This special treatment is needed to address crbug.com/234268. 557 // This special treatment is needed to address crbug.com/234268.
572 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 558 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
573 app_id = kGmailAppId; 559 app_id = kGmailAppId;
574 560
575 // Check the old |app_id| for a tab. If the contents has changed we need to 561 // Check the old |app_id| for a tab. If the contents has changed we need to
576 // remove it from the previous app. 562 // remove it from the previous app.
577 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 563 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
578 std::string last_app_id = web_contents_to_app_id_[contents]; 564 std::string last_app_id = web_contents_to_app_id_[contents];
(...skipping 19 matching lines...) Expand all
598 app_state == APP_STATE_ACTIVE) 584 app_state == APP_STATE_ACTIVE)
599 ? ash::STATUS_ACTIVE 585 ? ash::STATUS_ACTIVE
600 : GetAppState(app_id)); 586 : GetAppState(app_id));
601 } 587 }
602 } 588 }
603 589
604 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( 590 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents(
605 content::WebContents* contents) { 591 content::WebContents* contents) {
606 DCHECK(contents); 592 DCHECK(contents);
607 593
608 std::string app_id = launcher_controller_helper_->GetAppID(contents); 594 std::string app_id = launcher_controller_helper()->GetAppID(contents);
609 595
610 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 596 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
611 app_id = kGmailAppId; 597 app_id = kGmailAppId;
612 598
613 ash::ShelfID id = GetShelfIDForAppID(app_id); 599 ash::ShelfID id = GetShelfIDForAppID(app_id);
614 600
615 if (app_id.empty() || !id) { 601 if (app_id.empty() || !id) {
616 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); 602 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
617 return model_->items()[browser_index].id; 603 return model_->items()[browser_index].id;
618 } 604 }
(...skipping 26 matching lines...) Expand all
645 ash::ShelfItemDelegate::PerformedAction 631 ash::ShelfItemDelegate::PerformedAction
646 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( 632 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive(
647 ui::BaseWindow* window, 633 ui::BaseWindow* window,
648 bool allow_minimize) { 634 bool allow_minimize) {
649 // In separated desktop mode we might have to teleport a window back to the 635 // In separated desktop mode we might have to teleport a window back to the
650 // current user. 636 // current user.
651 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == 637 if (chrome::MultiUserWindowManager::GetMultiProfileMode() ==
652 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { 638 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) {
653 aura::Window* native_window = window->GetNativeWindow(); 639 aura::Window* native_window = window->GetNativeWindow();
654 const AccountId& current_account_id = 640 const AccountId& current_account_id =
655 multi_user_util::GetAccountIdFromProfile(GetProfile()); 641 multi_user_util::GetAccountIdFromProfile(profile());
656 chrome::MultiUserWindowManager* manager = 642 chrome::MultiUserWindowManager* manager =
657 chrome::MultiUserWindowManager::GetInstance(); 643 chrome::MultiUserWindowManager::GetInstance();
658 if (!manager->IsWindowOnDesktopOfUser(native_window, current_account_id)) { 644 if (!manager->IsWindowOnDesktopOfUser(native_window, current_account_id)) {
659 ash::MultiProfileUMA::RecordTeleportAction( 645 ash::MultiProfileUMA::RecordTeleportAction(
660 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER); 646 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER);
661 manager->ShowWindowForUser(native_window, current_account_id); 647 manager->ShowWindowForUser(native_window, current_account_id);
662 window->Activate(); 648 window->Activate();
663 return ash::ShelfItemDelegate::kExistingWindowActivated; 649 return ash::ShelfItemDelegate::kExistingWindowActivated;
664 } 650 }
665 } 651 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( 750 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp(
765 content::WebContents* web_contents) { 751 content::WebContents* web_contents) {
766 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); 752 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId);
767 if (id) { 753 if (id) {
768 const GURL url = web_contents->GetURL(); 754 const GURL url = web_contents->GetURL();
769 // We need to extend the application matching for the gMail app beyond the 755 // We need to extend the application matching for the gMail app beyond the
770 // manifest file's specification. This is required because of the namespace 756 // manifest file's specification. This is required because of the namespace
771 // overlap with the offline app ("/mail/mu/"). 757 // overlap with the offline app ("/mail/mu/").
772 if (!base::MatchPattern(url.path(), "/mail/mu/*") && 758 if (!base::MatchPattern(url.path(), "/mail/mu/*") &&
773 base::MatchPattern(url.path(), "/mail/*") && 759 base::MatchPattern(url.path(), "/mail/*") &&
774 GetExtensionForAppID(kGmailAppId, profile_) && 760 GetExtensionForAppID(kGmailAppId, profile()) &&
775 GetExtensionForAppID(kGmailAppId, profile_)->OverlapsWithOrigin(url)) 761 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url))
776 return true; 762 return true;
777 } 763 }
778 return false; 764 return false;
779 } 765 }
780 766
781 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( 767 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon(
782 content::WebContents* web_contents) const { 768 content::WebContents* web_contents) const {
783 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 769 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
784 if (IsIncognito(web_contents)) 770 if (IsIncognito(web_contents))
785 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); 771 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER);
786 favicon::FaviconDriver* favicon_driver = 772 favicon::FaviconDriver* favicon_driver =
787 favicon::ContentFaviconDriver::FromWebContents(web_contents); 773 favicon::ContentFaviconDriver::FromWebContents(web_contents);
788 gfx::Image result = favicon_driver->GetFavicon(); 774 gfx::Image result = favicon_driver->GetFavicon();
789 if (result.IsEmpty()) 775 if (result.IsEmpty())
790 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); 776 return rb.GetImageNamed(IDR_DEFAULT_FAVICON);
791 return result; 777 return result;
792 } 778 }
793 779
794 base::string16 ChromeLauncherControllerImpl::GetAppListTitle( 780 base::string16 ChromeLauncherControllerImpl::GetAppListTitle(
795 content::WebContents* web_contents) const { 781 content::WebContents* web_contents) const {
796 base::string16 title = web_contents->GetTitle(); 782 base::string16 title = web_contents->GetTitle();
797 if (!title.empty()) 783 if (!title.empty())
798 return title; 784 return title;
799 WebContentsToAppIDMap::const_iterator iter = 785 WebContentsToAppIDMap::const_iterator iter =
800 web_contents_to_app_id_.find(web_contents); 786 web_contents_to_app_id_.find(web_contents);
801 if (iter != web_contents_to_app_id_.end()) { 787 if (iter != web_contents_to_app_id_.end()) {
802 std::string app_id = iter->second; 788 std::string app_id = iter->second;
803 const extensions::Extension* extension = 789 const extensions::Extension* extension =
804 GetExtensionForAppID(app_id, profile_); 790 GetExtensionForAppID(app_id, profile());
805 if (extension) 791 if (extension)
806 return base::UTF8ToUTF16(extension->name()); 792 return base::UTF8ToUTF16(extension->name());
807 } 793 }
808 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 794 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
809 } 795 }
810 796
811 BrowserShortcutLauncherItemController* 797 BrowserShortcutLauncherItemController*
812 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { 798 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() {
813 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 799 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
814 i != id_to_item_controller_map_.end(); ++i) { 800 i != id_to_item_controller_map_.end(); ++i) {
(...skipping 11 matching lines...) Expand all
826 const ash::ShelfID id) { 812 const ash::ShelfID id) {
827 if (!HasShelfIDToAppIDMapping(id)) 813 if (!HasShelfIDToAppIDMapping(id))
828 return NULL; 814 return NULL;
829 return id_to_item_controller_map_[id]; 815 return id_to_item_controller_map_[id];
830 } 816 }
831 817
832 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( 818 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser(
833 ash::WmShelf* shelf, 819 ash::WmShelf* shelf,
834 const AccountId& account_id) const { 820 const AccountId& account_id) const {
835 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); 821 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id);
836 if (!other_profile || other_profile == profile_) 822 if (!other_profile || other_profile == profile())
837 return false; 823 return false;
838 824
839 // Note: The Auto hide state from preferences is not the same as the actual 825 // Note: The Auto hide state from preferences is not the same as the actual
840 // visibility of the shelf. Depending on all the various states (full screen, 826 // visibility of the shelf. Depending on all the various states (full screen,
841 // no window on desktop, multi user, ..) the shelf could be shown - or not. 827 // no window on desktop, multi user, ..) the shelf could be shown - or not.
842 PrefService* prefs = profile_->GetPrefs(); 828 PrefService* prefs = profile()->GetPrefs();
843 PrefService* other_prefs = other_profile->GetPrefs(); 829 PrefService* other_prefs = other_profile->GetPrefs();
844 const int64_t display = GetDisplayIDForShelf(shelf); 830 const int64_t display = GetDisplayIDForShelf(shelf);
845 const bool currently_shown = 831 const bool currently_shown =
846 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == 832 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
847 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display); 833 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display);
848 const bool other_shown = 834 const bool other_shown =
849 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == 835 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
850 ash::launcher::GetShelfAutoHideBehaviorPref(other_prefs, display); 836 ash::launcher::GetShelfAutoHideBehaviorPref(other_prefs, display);
851 837
852 return currently_shown != other_shown || 838 return currently_shown != other_shown ||
853 ash::launcher::GetShelfAlignmentPref(prefs, display) != 839 ash::launcher::GetShelfAlignmentPref(prefs, display) !=
854 ash::launcher::GetShelfAlignmentPref(other_prefs, display); 840 ash::launcher::GetShelfAlignmentPref(other_prefs, display);
855 } 841 }
856 842
857 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( 843 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch(
858 Profile* profile) { 844 Profile* profile) {
859 if (user_switch_observer_.get()) 845 if (user_switch_observer_.get())
860 user_switch_observer_->OnUserProfileReadyToSwitch(profile); 846 user_switch_observer_->OnUserProfileReadyToSwitch(profile);
861 } 847 }
862 848
863 ArcAppDeferredLauncherController* 849 ArcAppDeferredLauncherController*
864 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { 850 ChromeLauncherControllerImpl::GetArcDeferredLauncher() {
865 return arc_deferred_launcher_.get(); 851 return arc_deferred_launcher_.get();
866 } 852 }
867 853
854 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile) {
855 // The base class implementation updates the helper and app icon loaders.
856 ChromeLauncherController::AttachProfile(profile);
857
858 pref_change_registrar_.Init(profile->GetPrefs());
859 pref_change_registrar_.Add(
860 prefs::kPolicyPinnedLauncherApps,
861 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
862 base::Unretained(this)));
863 // Handling of prefs::kArcEnabled change should be called deferred to avoid
864 // race condition when OnAppUninstalledPrepared for Arc apps is called after
865 // UpdateAppLaunchersFromPref.
866 pref_change_registrar_.Add(
867 prefs::kArcEnabled,
868 base::Bind(
869 &ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref,
870 base::Unretained(this)));
871 pref_change_registrar_.Add(
872 prefs::kShelfAlignmentLocal,
873 base::Bind(&ChromeLauncherController::SetShelfAlignmentFromPrefs,
874 base::Unretained(this)));
875 pref_change_registrar_.Add(
876 prefs::kShelfAutoHideBehaviorLocal,
877 base::Bind(&ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs,
878 base::Unretained(this)));
879 pref_change_registrar_.Add(
880 prefs::kShelfPreferences,
881 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
882 base::Unretained(this)));
883 pref_change_registrar_.Add(
884 prefs::kTouchVirtualKeyboardEnabled,
885 base::Bind(
886 &ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs,
887 base::Unretained(this)));
888
889 std::unique_ptr<LauncherAppUpdater> extension_app_updater(
890 new LauncherExtensionAppUpdater(this, profile));
891 app_updaters_.push_back(std::move(extension_app_updater));
892
893 if (arc::ArcAuthService::IsAllowedForProfile(profile)) {
894 std::unique_ptr<LauncherAppUpdater> arc_app_updater(
895 new LauncherArcAppUpdater(this, profile));
896 app_updaters_.push_back(std::move(arc_app_updater));
897 }
898
899 app_list::AppListSyncableService* app_service =
900 app_list::AppListSyncableServiceFactory::GetForProfile(profile);
901 if (app_service)
902 app_service->AddObserverAndStart(this);
903 }
904
868 /////////////////////////////////////////////////////////////////////////////// 905 ///////////////////////////////////////////////////////////////////////////////
869 // ash::ShelfDelegate: 906 // ash::ShelfDelegate:
870 907
871 void ChromeLauncherControllerImpl::OnShelfCreated(ash::WmShelf* shelf) {
872 PrefService* prefs = profile_->GetPrefs();
873 const int64_t display = GetDisplayIDForShelf(shelf);
874
875 shelf->SetAutoHideBehavior(
876 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display));
877
878 if (ash::ShelfWidget::ShelfAlignmentAllowed())
879 shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref(prefs, display));
880 }
881
882 void ChromeLauncherControllerImpl::OnShelfDestroyed(ash::WmShelf* shelf) {}
883
884 void ChromeLauncherControllerImpl::OnShelfAlignmentChanged(
885 ash::WmShelf* shelf) {
886 ash::launcher::SetShelfAlignmentPref(
887 profile_->GetPrefs(), GetDisplayIDForShelf(shelf), shelf->alignment());
888 }
889
890 void ChromeLauncherControllerImpl::OnShelfAutoHideBehaviorChanged(
891 ash::WmShelf* shelf) {
892 ash::launcher::SetShelfAutoHideBehaviorPref(profile_->GetPrefs(),
893 GetDisplayIDForShelf(shelf),
894 shelf->auto_hide_behavior());
895 }
896
897 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged(
898 ash::WmShelf* shelf) {}
899
900 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged(
901 ash::WmShelf* shelf) {}
902
903 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( 908 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
904 const std::string& app_id) { 909 const std::string& app_id) {
905 // Get shelf id for app_id and empty launch_id. 910 // Get shelf id for app_id and empty launch_id.
906 return GetShelfIDForAppIDAndLaunchID(app_id, ""); 911 return GetShelfIDForAppIDAndLaunchID(app_id, "");
907 } 912 }
908 913
909 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( 914 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID(
910 const std::string& app_id, 915 const std::string& app_id,
911 const std::string& launch_id) { 916 const std::string& launch_id) {
912 const std::string shelf_app_id = 917 const std::string shelf_app_id =
(...skipping 18 matching lines...) Expand all
931 936
932 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( 937 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID(
933 ash::ShelfID id) { 938 ash::ShelfID id) {
934 LauncherItemController* controller = GetLauncherItemController(id); 939 LauncherItemController* controller = GetLauncherItemController(id);
935 return controller ? controller->app_id() : base::EmptyString(); 940 return controller ? controller->app_id() : base::EmptyString();
936 } 941 }
937 942
938 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { 943 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) {
939 const std::string shelf_app_id = 944 const std::string shelf_app_id =
940 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 945 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
941 if (GetPinnableForAppID(shelf_app_id, profile_) == 946 if (GetPinnableForAppID(shelf_app_id, profile()) ==
942 AppListControllerDelegate::PIN_EDITABLE) 947 AppListControllerDelegate::PIN_EDITABLE)
943 DoPinAppWithID(shelf_app_id); 948 DoPinAppWithID(shelf_app_id);
944 else 949 else
945 NOTREACHED(); 950 NOTREACHED();
946 } 951 }
947 952
948 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { 953 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) {
949 const std::string shelf_app_id = 954 const std::string shelf_app_id =
950 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 955 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
951 for (IDToItemControllerMap::const_iterator i = 956 for (IDToItemControllerMap::const_iterator i =
952 id_to_item_controller_map_.begin(); 957 id_to_item_controller_map_.begin();
953 i != id_to_item_controller_map_.end(); ++i) { 958 i != id_to_item_controller_map_.end(); ++i) {
954 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id) 959 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id)
955 return true; 960 return true;
956 } 961 }
957 return false; 962 return false;
958 } 963 }
959 964
960 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { 965 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) {
961 const std::string shelf_app_id = 966 const std::string shelf_app_id =
962 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 967 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
963 if (GetPinnableForAppID(shelf_app_id, profile_) == 968 if (GetPinnableForAppID(shelf_app_id, profile()) ==
964 AppListControllerDelegate::PIN_EDITABLE) 969 AppListControllerDelegate::PIN_EDITABLE)
965 DoUnpinAppWithID(shelf_app_id, true /* update_prefs */); 970 DoUnpinAppWithID(shelf_app_id, true /* update_prefs */);
966 else 971 else
967 NOTREACHED(); 972 NOTREACHED();
968 } 973 }
969 974
970 /////////////////////////////////////////////////////////////////////////////// 975 ///////////////////////////////////////////////////////////////////////////////
971 // LauncherAppUpdater::Delegate: 976 // LauncherAppUpdater::Delegate:
972 977
973 void ChromeLauncherControllerImpl::OnAppInstalled( 978 void ChromeLauncherControllerImpl::OnAppInstalled(
(...skipping 22 matching lines...) Expand all
996 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( 1001 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared(
997 content::BrowserContext* browser_context, 1002 content::BrowserContext* browser_context,
998 const std::string& app_id) { 1003 const std::string& app_id) {
999 // Since we might have windowed apps of this type which might have 1004 // Since we might have windowed apps of this type which might have
1000 // outstanding locks which needs to be removed. 1005 // outstanding locks which needs to be removed.
1001 const Profile* profile = Profile::FromBrowserContext(browser_context); 1006 const Profile* profile = Profile::FromBrowserContext(browser_context);
1002 if (GetShelfIDForAppID(app_id)) 1007 if (GetShelfIDForAppID(app_id))
1003 CloseWindowedAppsFromRemovedExtension(app_id, profile); 1008 CloseWindowedAppsFromRemovedExtension(app_id, profile);
1004 1009
1005 if (IsAppPinned(app_id)) { 1010 if (IsAppPinned(app_id)) {
1006 if (profile == profile_) { 1011 if (profile == this->profile()) {
1007 // Some apps may be removed locally. Don't remove pin position from sync 1012 // Some apps may be removed locally. Don't remove pin position from sync
1008 // model. When needed, it is automatically deleted on app list model 1013 // model. When needed, it is automatically deleted on app list model
1009 // update. 1014 // update.
1010 DoUnpinAppWithID(app_id, false /* update_prefs */); 1015 DoUnpinAppWithID(app_id, false /* update_prefs */);
1011 } 1016 }
1012 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1017 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1013 if (app_icon_loader) 1018 if (app_icon_loader)
1014 app_icon_loader->ClearImage(app_id); 1019 app_icon_loader->ClearImage(app_id);
1015 } 1020 }
1016 } 1021 }
1017 1022
1018 /////////////////////////////////////////////////////////////////////////////// 1023 ///////////////////////////////////////////////////////////////////////////////
1019 // ChromeLauncherControllerImpl protected: 1024 // ChromeLauncherControllerImpl protected:
1020 1025
1021 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 1026 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
1022 const std::string& app_id, 1027 const std::string& app_id,
1023 int index) { 1028 int index) {
1024 return CreateAppShortcutLauncherItemWithType(app_id, index, 1029 return CreateAppShortcutLauncherItemWithType(app_id, index,
1025 ash::TYPE_APP_SHORTCUT); 1030 ash::TYPE_APP_SHORTCUT);
1026 } 1031 }
1027 1032
1028 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest(
1029 LauncherControllerHelper* helper) {
1030 launcher_controller_helper_.reset(helper);
1031 }
1032
1033 void ChromeLauncherControllerImpl::SetAppIconLoadersForTest(
1034 std::vector<std::unique_ptr<AppIconLoader>>& loaders) {
1035 app_icon_loaders_.clear();
1036 for (auto& loader : loaders)
1037 app_icon_loaders_.push_back(std::move(loader));
1038 }
1039
1040 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( 1033 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest(
1041 ash::ShelfID id) { 1034 ash::ShelfID id) {
1042 return id_to_item_controller_map_[id]->app_id(); 1035 return id_to_item_controller_map_[id]->app_id();
1043 } 1036 }
1044 1037
1045 /////////////////////////////////////////////////////////////////////////////// 1038 ///////////////////////////////////////////////////////////////////////////////
1046 // ChromeLauncherControllerImpl private: 1039 // ChromeLauncherControllerImpl private:
1047 1040
1048 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 1041 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
1049 RunningAppListIds list; 1042 RunningAppListIds list;
1050 for (int i = 0; i < model_->item_count(); i++) { 1043 for (int i = 0; i < model_->item_count(); i++) {
1051 ash::ShelfItemType type = model_->items()[i].type; 1044 ash::ShelfItemType type = model_->items()[i].type;
1052 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) 1045 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP)
1053 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); 1046 list.push_back(GetAppIDForShelfID(model_->items()[i].id));
1054 } 1047 }
1055 const std::string user_email = 1048 const std::string user_email =
1056 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail(); 1049 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail();
1057 last_used_running_application_order_[user_email] = list; 1050 last_used_running_application_order_[user_email] = list;
1058 } 1051 }
1059 1052
1060 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( 1053 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder(
1061 const std::string& user_id) { 1054 const std::string& user_id) {
1062 const RunningAppListIdMap::iterator app_id_list = 1055 const RunningAppListIdMap::iterator app_id_list =
1063 last_used_running_application_order_.find(user_id); 1056 last_used_running_application_order_.find(user_id);
1064 if (app_id_list == last_used_running_application_order_.end()) 1057 if (app_id_list == last_used_running_application_order_.end())
1065 return; 1058 return;
1066 1059
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 1183
1191 for (int i = index + 1; i < max_index; ++i) { 1184 for (int i = index + 1; i < max_index; ++i) {
1192 const ash::ShelfID shelf_id_after = model_->items()[i].id; 1185 const ash::ShelfID shelf_id_after = model_->items()[i].id;
1193 if (IsPinned(shelf_id_after)) { 1186 if (IsPinned(shelf_id_after)) {
1194 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); 1187 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after);
1195 DCHECK(!app_id_after.empty()); 1188 DCHECK(!app_id_after.empty());
1196 app_ids_after.push_back(app_id_after); 1189 app_ids_after.push_back(app_id_after);
1197 } 1190 }
1198 } 1191 }
1199 1192
1200 ash::launcher::SetPinPosition(profile_, app_id, app_id_before, app_ids_after); 1193 ash::launcher::SetPinPosition(profile(), app_id, app_id_before,
1194 app_ids_after);
1201 } 1195 }
1202 1196
1203 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { 1197 void ChromeLauncherControllerImpl::OnSyncModelUpdated() {
1204 UpdateAppLaunchersFromPref(); 1198 UpdateAppLaunchersFromPref();
1205 } 1199 }
1206 1200
1207 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { 1201 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() {
1208 base::ThreadTaskRunnerHandle::Get()->PostTask( 1202 base::ThreadTaskRunnerHandle::Get()->PostTask(
1209 FROM_HERE, 1203 FROM_HERE,
1210 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 1204 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
1211 weak_ptr_factory_.GetWeakPtr())); 1205 weak_ptr_factory_.GetWeakPtr()));
1212 } 1206 }
1213 1207
1214 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { 1208 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() {
1215 // There are various functions which will trigger a |SyncPinPosition| call 1209 // There are various functions which will trigger a |SyncPinPosition| call
1216 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu 1210 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu
1217 // model which will use weights to re-arrange the icons to new positions. 1211 // model which will use weights to re-arrange the icons to new positions.
1218 // Since this function is meant to synchronize the "is state" with the 1212 // Since this function is meant to synchronize the "is state" with the
1219 // "sync state", it makes no sense to store any changes by this function back 1213 // "sync state", it makes no sense to store any changes by this function back
1220 // into the pref state. Therefore we tell |persistPinnedState| to ignore any 1214 // into the pref state. Therefore we tell |persistPinnedState| to ignore any
1221 // invocations while we are running. 1215 // invocations while we are running.
1222 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1216 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1223 const std::vector<std::string> pinned_apps = 1217 const std::vector<std::string> pinned_apps =
1224 ash::launcher::GetPinnedAppsFromPrefs(profile_->GetPrefs(), 1218 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(),
1225 launcher_controller_helper_.get()); 1219 launcher_controller_helper());
1226 1220
1227 int index = 0; 1221 int index = 0;
1228 // Skip app list items if it exists. 1222 // Skip app list items if it exists.
1229 if (model_->items()[0].type == ash::TYPE_APP_LIST) 1223 if (model_->items()[0].type == ash::TYPE_APP_LIST)
1230 ++index; 1224 ++index;
1231 1225
1232 // Apply pins in two steps. At the first step, go through the list of apps to 1226 // Apply pins in two steps. At the first step, go through the list of apps to
1233 // pin, move existing pin to current position specified by |index| or create 1227 // pin, move existing pin to current position specified by |index| or create
1234 // the new pin at that position. 1228 // the new pin at that position.
1235 for (const auto& pref_app_id : pinned_apps) { 1229 for (const auto& pref_app_id : pinned_apps) {
1236 // Filter out apps that may be mapped wrongly. 1230 // Filter out apps that may be mapped wrongly.
1237 // TODO(khmel): b/31703859 is to refactore shelf mapping. 1231 // TODO(khmel): b/31703859 is to refactore shelf mapping.
1238 const std::string shelf_app_id = 1232 const std::string shelf_app_id =
1239 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); 1233 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id);
1240 if (shelf_app_id != pref_app_id) 1234 if (shelf_app_id != pref_app_id)
1241 continue; 1235 continue;
1242 1236
1243 // Update apps icon if applicable. 1237 // Update apps icon if applicable.
1244 OnAppUpdated(profile_, pref_app_id); 1238 OnAppUpdated(profile(), pref_app_id);
1245 1239
1246 // Find existing pin or app from the right of current |index|. 1240 // Find existing pin or app from the right of current |index|.
1247 int app_index = index; 1241 int app_index = index;
1248 for (; app_index < model_->item_count(); ++app_index) { 1242 for (; app_index < model_->item_count(); ++app_index) {
1249 const ash::ShelfItem& item = model_->items()[app_index]; 1243 const ash::ShelfItem& item = model_->items()[app_index];
1250 const IDToItemControllerMap::iterator it = 1244 const IDToItemControllerMap::iterator it =
1251 id_to_item_controller_map_.find(item.id); 1245 id_to_item_controller_map_.find(item.id);
1252 if (it != id_to_item_controller_map_.end() && 1246 if (it != id_to_item_controller_map_.end() &&
1253 it->second->app_id() == pref_app_id) { 1247 it->second->app_id() == pref_app_id) {
1254 break; 1248 break;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 controller->type() == LauncherItemController::TYPE_APP) { 1284 controller->type() == LauncherItemController::TYPE_APP) {
1291 UnpinRunningAppInternal(index); 1285 UnpinRunningAppInternal(index);
1292 // Note, item can be moved to the right due weighting in shelf model. 1286 // Note, item can be moved to the right due weighting in shelf model.
1293 DCHECK_GE(model_->ItemIndexByID(item.id), index); 1287 DCHECK_GE(model_->ItemIndexByID(item.id), index);
1294 } else { 1288 } else {
1295 LauncherItemClosed(item.id); 1289 LauncherItemClosed(item.id);
1296 } 1290 }
1297 } 1291 }
1298 } 1292 }
1299 1293
1300 void ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs() {
1301 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) {
1302 ash::WmShelf* shelf = ash::WmShelf::ForWindow(window);
1303 // TODO(jamescook): This check should not be necessary, but otherwise this
1304 // tries to set autohide state on a secondary display during login before
1305 // the ShelfView is created, which is not allowed.
1306 if (shelf->IsShelfInitialized()) {
1307 shelf->SetAutoHideBehavior(ash::launcher::GetShelfAutoHideBehaviorPref(
1308 profile_->GetPrefs(), GetDisplayIDForShelf(shelf)));
1309 }
1310 }
1311 }
1312
1313 void ChromeLauncherControllerImpl::SetShelfAlignmentFromPrefs() {
1314 if (!ash::ShelfWidget::ShelfAlignmentAllowed())
1315 return;
1316
1317 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) {
1318 ash::WmShelf* shelf = ash::WmShelf::ForWindow(window);
1319 // TODO(jamescook): This check should not be necessary, but otherwise this
1320 // tries to set the alignment on a secondary display during login before the
1321 // ShelfLockingManager and ShelfView are created, which is not allowed.
1322 if (shelf->IsShelfInitialized()) {
1323 shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref(
1324 profile_->GetPrefs(), GetDisplayIDForShelf(shelf)));
1325 }
1326 }
1327 }
1328
1329 void ChromeLauncherControllerImpl::SetShelfBehaviorsFromPrefs() {
1330 SetShelfAutoHideBehaviorFromPrefs();
1331 SetShelfAlignmentFromPrefs();
1332 }
1333
1334 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() { 1294 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() {
1335 const PrefService* service = profile_->GetPrefs(); 1295 const PrefService* service = profile()->GetPrefs();
1336 const bool was_enabled = keyboard::IsKeyboardEnabled(); 1296 const bool was_enabled = keyboard::IsKeyboardEnabled();
1337 if (!service->HasPrefPath(prefs::kTouchVirtualKeyboardEnabled)) { 1297 if (!service->HasPrefPath(prefs::kTouchVirtualKeyboardEnabled)) {
1338 keyboard::SetKeyboardShowOverride(keyboard::KEYBOARD_SHOW_OVERRIDE_NONE); 1298 keyboard::SetKeyboardShowOverride(keyboard::KEYBOARD_SHOW_OVERRIDE_NONE);
1339 } else { 1299 } else {
1340 const bool enable = 1300 const bool enable =
1341 service->GetBoolean(prefs::kTouchVirtualKeyboardEnabled); 1301 service->GetBoolean(prefs::kTouchVirtualKeyboardEnabled);
1342 keyboard::SetKeyboardShowOverride( 1302 keyboard::SetKeyboardShowOverride(
1343 enable ? keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED 1303 enable ? keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED
1344 : keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED); 1304 : keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED);
1345 } 1305 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 1443
1484 void ChromeLauncherControllerImpl::SetShelfItemDelegate( 1444 void ChromeLauncherControllerImpl::SetShelfItemDelegate(
1485 ash::ShelfID id, 1445 ash::ShelfID id,
1486 ash::ShelfItemDelegate* item_delegate) { 1446 ash::ShelfItemDelegate* item_delegate) {
1487 DCHECK_GT(id, 0); 1447 DCHECK_GT(id, 0);
1488 DCHECK(item_delegate); 1448 DCHECK(item_delegate);
1489 model_->SetShelfItemDelegate( 1449 model_->SetShelfItemDelegate(
1490 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); 1450 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate));
1491 } 1451 }
1492 1452
1493 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile) {
1494 profile_ = profile;
1495 // Either add the profile to the list of known profiles and make it the active
1496 // one for some functions of LauncherControllerHelper or create a new one.
1497 if (!launcher_controller_helper_.get())
1498 launcher_controller_helper_.reset(new LauncherControllerHelper(profile_));
1499 else
1500 launcher_controller_helper_->SetCurrentUser(profile_);
1501 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
1502 // image is associated with a profile (its loader requires the profile).
1503 // Since icon size changes are possible, the icon could be requested to be
1504 // reloaded. However - having it not multi profile aware would cause problems
1505 // if the icon cache gets deleted upon user switch.
1506 std::unique_ptr<AppIconLoader> extension_app_icon_loader(
1507 new extensions::ExtensionAppIconLoader(
1508 profile_, extension_misc::EXTENSION_ICON_SMALL, this));
1509 app_icon_loaders_.push_back(std::move(extension_app_icon_loader));
1510
1511 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) {
1512 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader(
1513 profile_, extension_misc::EXTENSION_ICON_SMALL, this));
1514 app_icon_loaders_.push_back(std::move(arc_app_icon_loader));
1515 }
1516
1517 pref_change_registrar_.Init(profile_->GetPrefs());
1518 pref_change_registrar_.Add(
1519 prefs::kPolicyPinnedLauncherApps,
1520 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
1521 base::Unretained(this)));
1522 // Handling of prefs::kArcEnabled change should be called deferred to avoid
1523 // race condition when OnAppUninstalledPrepared for Arc apps is called after
1524 // UpdateAppLaunchersFromPref.
1525 pref_change_registrar_.Add(
1526 prefs::kArcEnabled,
1527 base::Bind(
1528 &ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref,
1529 base::Unretained(this)));
1530 pref_change_registrar_.Add(
1531 prefs::kShelfAlignmentLocal,
1532 base::Bind(&ChromeLauncherControllerImpl::SetShelfAlignmentFromPrefs,
1533 base::Unretained(this)));
1534 pref_change_registrar_.Add(
1535 prefs::kShelfAutoHideBehaviorLocal,
1536 base::Bind(
1537 &ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs,
1538 base::Unretained(this)));
1539 pref_change_registrar_.Add(
1540 prefs::kShelfPreferences,
1541 base::Bind(&ChromeLauncherControllerImpl::SetShelfBehaviorsFromPrefs,
1542 base::Unretained(this)));
1543 pref_change_registrar_.Add(
1544 prefs::kTouchVirtualKeyboardEnabled,
1545 base::Bind(
1546 &ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs,
1547 base::Unretained(this)));
1548
1549 std::unique_ptr<LauncherAppUpdater> extension_app_updater(
1550 new LauncherExtensionAppUpdater(this, profile_));
1551 app_updaters_.push_back(std::move(extension_app_updater));
1552
1553 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) {
1554 std::unique_ptr<LauncherAppUpdater> arc_app_updater(
1555 new LauncherArcAppUpdater(this, profile_));
1556 app_updaters_.push_back(std::move(arc_app_updater));
1557 }
1558
1559 app_list::AppListSyncableService* app_service =
1560 app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
1561 if (app_service)
1562 app_service->AddObserverAndStart(this);
1563 }
1564
1565 void ChromeLauncherControllerImpl::SetProfileForTest(Profile* profile) {
1566 profile_ = profile;
1567 }
1568
1569 void ChromeLauncherControllerImpl::ReleaseProfile() { 1453 void ChromeLauncherControllerImpl::ReleaseProfile() {
1570 if (app_sync_ui_state_) 1454 if (app_sync_ui_state_)
1571 app_sync_ui_state_->RemoveObserver(this); 1455 app_sync_ui_state_->RemoveObserver(this);
1572 1456
1573 app_updaters_.clear(); 1457 app_updaters_.clear();
1574 1458
1575 prefs_observer_.reset(); 1459 prefs_observer_.reset();
1576 1460
1577 pref_change_registrar_.RemoveAll(); 1461 pref_change_registrar_.RemoveAll();
1578 1462
1579 app_list::AppListSyncableService* app_service = 1463 app_list::AppListSyncableService* app_service =
1580 app_list::AppListSyncableServiceFactory::GetForProfile(profile_); 1464 app_list::AppListSyncableServiceFactory::GetForProfile(profile());
1581 if (app_service) 1465 if (app_service)
1582 app_service->RemoveObserver(this); 1466 app_service->RemoveObserver(this);
1583 } 1467 }
1584 1468
1585 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp(
1586 const std::string& app_id) {
1587 for (const auto& app_icon_loader : app_icon_loaders_) {
1588 if (app_icon_loader->CanLoadImageForApp(app_id))
1589 return app_icon_loader.get();
1590 }
1591
1592 return nullptr;
1593 }
1594
1595 /////////////////////////////////////////////////////////////////////////////// 1469 ///////////////////////////////////////////////////////////////////////////////
1596 // ash::ShelfModelObserver: 1470 // ash::ShelfModelObserver:
1597 1471
1598 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { 1472 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) {
1599 } 1473 }
1600 1474
1601 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, 1475 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index,
1602 ash::ShelfID id) { 1476 ash::ShelfID id) {
1603 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we 1477 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
1604 // get into this state in the first place. 1478 // get into this state in the first place.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 if (index == -1) 1553 if (index == -1)
1680 continue; 1554 continue;
1681 ash::ShelfItem item = model_->items()[index]; 1555 ash::ShelfItem item = model_->items()[index];
1682 item.image = image; 1556 item.image = image;
1683 if (arc_deferred_launcher_) 1557 if (arc_deferred_launcher_)
1684 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1558 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1685 model_->Set(index, item); 1559 model_->Set(index, item);
1686 // It's possible we're waiting on more than one item, so don't break. 1560 // It's possible we're waiting on more than one item, so don't break.
1687 } 1561 }
1688 } 1562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698