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

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

Issue 2791803002: mash: Move LauncherItemController to ash, rename ShelfItemDelegate. (Closed)
Patch Set: Sync and rebase. Created 3 years, 8 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/wm_shelf.h" 13 #include "ash/common/shelf/wm_shelf.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
16 #include "ash/common/wm_window.h" 16 #include "ash/common/wm_window.h"
17 #include "ash/public/cpp/app_launch_id.h" 17 #include "ash/public/cpp/app_launch_id.h"
18 #include "ash/public/cpp/shelf_item_delegate.h"
18 #include "ash/resources/grit/ash_resources.h" 19 #include "ash/resources/grit/ash_resources.h"
19 #include "ash/root_window_controller.h" 20 #include "ash/root_window_controller.h"
20 #include "ash/shell.h" 21 #include "ash/shell.h"
21 #include "ash/strings/grit/ash_strings.h" 22 #include "ash/strings/grit/ash_strings.h"
22 #include "ash/wm/window_util.h" 23 #include "ash/wm/window_util.h"
23 #include "base/command_line.h" 24 #include "base/command_line.h"
24 #include "base/macros.h" 25 #include "base/macros.h"
25 #include "base/strings/pattern.h" 26 #include "base/strings/pattern.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
(...skipping 17 matching lines...) Expand all
45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" 47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
47 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" 48 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h"
48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 49 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 50 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 51 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 52 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
52 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" 53 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h"
53 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 54 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
54 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" 55 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h"
55 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
56 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr oller.h" 56 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr oller.h"
57 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" 57 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h"
58 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 58 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
59 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 59 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
60 #include "chrome/browser/ui/browser.h" 60 #include "chrome/browser/ui/browser.h"
61 #include "chrome/browser/ui/browser_finder.h" 61 #include "chrome/browser/ui/browser_finder.h"
62 #include "chrome/browser/ui/browser_list.h" 62 #include "chrome/browser/ui/browser_list.h"
63 #include "chrome/browser/ui/browser_tabstrip.h" 63 #include "chrome/browser/ui/browser_tabstrip.h"
64 #include "chrome/browser/ui/browser_window.h" 64 #include "chrome/browser/ui/browser_window.h"
65 #include "chrome/browser/ui/tabs/tab_strip_model.h" 65 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 30 matching lines...) Expand all
96 namespace { 96 namespace {
97 97
98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { 98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) {
99 display::Display display = 99 display::Display display =
100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); 100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow();
101 DCHECK(display.is_valid()); 101 DCHECK(display.is_valid());
102 return display.id(); 102 return display.id();
103 } 103 }
104 104
105 // A callback that does nothing after shelf item selection handling. 105 // A callback that does nothing after shelf item selection handling.
106 void NoopCallback(ash::ShelfAction, base::Optional<MenuItemList>) {} 106 void NoopCallback(ash::ShelfAction, base::Optional<ash::MenuItemList>) {}
107 107
108 // Calls ItemSelected with |source|, default arguments, and no callback. 108 // Calls ItemSelected with |source|, default arguments, and no callback.
109 void SelectItemWithSource(ash::mojom::ShelfItemDelegate* delegate, 109 void SelectItemWithSource(ash::ShelfItemDelegate* delegate,
110 ash::ShelfLaunchSource source) { 110 ash::ShelfLaunchSource source) {
111 delegate->ItemSelected(nullptr, display::kInvalidDisplayId, source, 111 delegate->ItemSelected(nullptr, display::kInvalidDisplayId, source,
112 base::Bind(&NoopCallback)); 112 base::Bind(&NoopCallback));
113 } 113 }
114 114
115 // Returns true if the given |item| has a pinned shelf item type. 115 // Returns true if the given |item| has a pinned shelf item type.
116 bool ItemTypeIsPinned(const ash::ShelfItem& item) { 116 bool ItemTypeIsPinned(const ash::ShelfItem& item) {
117 return item.type == ash::TYPE_PINNED_APP || 117 return item.type == ash::TYPE_PINNED_APP ||
118 item.type == ash::TYPE_BROWSER_SHORTCUT; 118 item.type == ash::TYPE_BROWSER_SHORTCUT;
119 } 119 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 284 }
285 285
286 // Release all profile dependent resources. 286 // Release all profile dependent resources.
287 ReleaseProfile(); 287 ReleaseProfile();
288 288
289 // Get rid of the multi user window manager instance. 289 // Get rid of the multi user window manager instance.
290 chrome::MultiUserWindowManager::DeleteInstance(); 290 chrome::MultiUserWindowManager::DeleteInstance();
291 } 291 }
292 292
293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( 293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem(
294 LauncherItemController* controller, 294 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
295 ash::ShelfItemStatus status) { 295 ash::ShelfItemStatus status) {
296 return InsertAppLauncherItem(controller, status, model_->item_count(), 296 return InsertAppLauncherItem(std::move(item_delegate), status,
297 ash::TYPE_APP); 297 model_->item_count(), ash::TYPE_APP);
298 } 298 }
299 299
300 const ash::ShelfItem* ChromeLauncherControllerImpl::GetItem( 300 const ash::ShelfItem* ChromeLauncherControllerImpl::GetItem(
301 ash::ShelfID id) const { 301 ash::ShelfID id) const {
302 const int index = model_->ItemIndexByID(id); 302 const int index = model_->ItemIndexByID(id);
303 if (index >= 0 && index < model_->item_count()) 303 if (index >= 0 && index < model_->item_count())
304 return &model_->items()[index]; 304 return &model_->items()[index];
305 return nullptr; 305 return nullptr;
306 } 306 }
307 307
(...skipping 10 matching lines...) Expand all
318 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, 318 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id,
319 ash::ShelfItemStatus status) { 319 ash::ShelfItemStatus status) {
320 const ash::ShelfItem* item = GetItem(id); 320 const ash::ShelfItem* item = GetItem(id);
321 if (item && item->status != status) { 321 if (item && item->status != status) {
322 ash::ShelfItem new_item = *item; 322 ash::ShelfItem new_item = *item;
323 new_item.status = status; 323 new_item.status = status;
324 model_->Set(model_->ItemIndexByID(id), new_item); 324 model_->Set(model_->ItemIndexByID(id), new_item);
325 } 325 }
326 } 326 }
327 327
328 void ChromeLauncherControllerImpl::SetItemController( 328 void ChromeLauncherControllerImpl::SetShelfItemDelegate(
329 ash::ShelfID id, 329 ash::ShelfID id,
330 LauncherItemController* controller) { 330 std::unique_ptr<ash::ShelfItemDelegate> item_delegate) {
331 CHECK(controller); 331 CHECK(item_delegate);
332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
333 CHECK(iter != id_to_item_controller_map_.end()); 333 CHECK(iter != id_to_item_controller_map_.end());
334 controller->set_shelf_id(id); 334 item_delegate->set_shelf_id(id);
335 iter->second = controller; 335 iter->second = item_delegate.get();
336 // Existing controller is destroyed and replaced by registering again. 336 model_->SetShelfItemDelegate(id, std::move(item_delegate));
337 SetShelfItemDelegate(id, controller);
338 } 337 }
339 338
340 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { 339 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) {
341 CHECK(id); 340 CHECK(id);
342 if (IsPinned(id)) { 341 if (IsPinned(id)) {
343 // Create a new shortcut controller. 342 // Create a new shortcut delegate.
344 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
345 CHECK(iter != id_to_item_controller_map_.end());
346 LauncherItemController* controller = iter->second;
347 SetItemStatus(id, ash::STATUS_CLOSED); 343 SetItemStatus(id, ash::STATUS_CLOSED);
348 const ash::AppLaunchId& app_launch_id = controller->app_launch_id(); 344 SetShelfItemDelegate(id, AppShortcutLauncherItemController::Create(
349 controller = AppShortcutLauncherItemController::Create(app_launch_id, this); 345 GetItem(id)->app_launch_id));
350 controller->set_shelf_id(id);
351 // Existing controller is destroyed and replaced by registering again.
352 iter->second = controller;
353 SetShelfItemDelegate(id, controller);
354 } else { 346 } else {
355 LauncherItemClosed(id); 347 LauncherItemClosed(id);
356 } 348 }
357 } 349 }
358 350
359 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { 351 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) {
360 const ash::ShelfItem* item = GetItem(id); 352 const ash::ShelfItem* item = GetItem(id);
361 if (item && item->status != ash::STATUS_CLOSED) 353 if (item && item->status != ash::STATUS_CLOSED)
362 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 354 UnpinRunningAppInternal(model_->ItemIndexByID(id));
363 else 355 else
364 LauncherItemClosed(id); 356 LauncherItemClosed(id);
365 } 357 }
366 358
367 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 359 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
368 const ash::ShelfItem* item = GetItem(id); 360 const ash::ShelfItem* item = GetItem(id);
369 return item && ItemTypeIsPinned(*item); 361 return item && ItemTypeIsPinned(*item);
370 } 362 }
371 363
372 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, 364 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id,
373 ash::ShelfItemStatus status) { 365 ash::ShelfItemStatus status) {
374 ash::ShelfID id = GetShelfIDForAppID(app_id); 366 ash::ShelfID id = GetShelfIDForAppID(app_id);
375 const ash::ShelfItem* item = GetItem(id); 367 const ash::ShelfItem* item = GetItem(id);
376 if (item) { 368 if (item) {
377 if (!IsPinned(id) && status == ash::STATUS_CLOSED) 369 if (!IsPinned(id) && status == ash::STATUS_CLOSED)
378 LauncherItemClosed(id); 370 LauncherItemClosed(id);
379 else 371 else
380 SetItemStatus(id, status); 372 SetItemStatus(id, status);
381 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { 373 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) {
382 InsertAppLauncherItem(AppShortcutLauncherItemController::Create( 374 InsertAppLauncherItem(
383 ash::AppLaunchId(app_id), this), 375 AppShortcutLauncherItemController::Create(ash::AppLaunchId(app_id)),
384 status, model_->item_count(), ash::TYPE_APP); 376 status, model_->item_count(), ash::TYPE_APP);
385 } 377 }
386 } 378 }
387 379
388 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { 380 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) {
389 LauncherItemController* controller = GetLauncherItemController(id); 381 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(id);
390 if (!controller) 382 if (!delegate)
391 return; // In case invoked from menu and item closed while menu up. 383 return; // In case invoked from menu and item closed while menu up.
392 384
393 // Launching some items replaces the associated item controller instance, 385 // Launching some items replaces the associated item delegate instance,
394 // which destroys the app and launch id strings; making copies avoid crashes. 386 // which destroys the app and launch id strings; making copies avoid crashes.
395 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()), 387 LaunchApp(ash::AppLaunchId(delegate->app_id(), delegate->launch_id()),
396 ash::LAUNCH_FROM_UNKNOWN, event_flags); 388 ash::LAUNCH_FROM_UNKNOWN, event_flags);
397 } 389 }
398 390
399 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { 391 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) {
400 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 392 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
401 if (!delegate) 393 if (!delegate)
402 return; // May happen if menu closed. 394 return; // May happen if menu closed.
403 delegate->Close(); 395 delegate->Close();
404 } 396 }
405 397
406 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { 398 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) {
407 const ash::ShelfItem* item = GetItem(id); 399 const ash::ShelfItem* item = GetItem(id);
408 return item && item->status != ash::STATUS_CLOSED; 400 return item && item->status != ash::STATUS_CLOSED;
409 } 401 }
410 402
411 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { 403 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) {
412 std::string app_id = GetAppIDForShelfID(id); 404 std::string app_id = GetAppIDForShelfID(id);
413 const Extension* extension = GetExtensionForAppID(app_id, profile()); 405 const Extension* extension = GetExtensionForAppID(app_id, profile());
414 // An extension can be synced / updated at any time and therefore not be 406 // An extension can be synced / updated at any time and therefore not be
415 // available. 407 // available.
416 return extension ? extension->is_platform_app() : false; 408 return extension ? extension->is_platform_app() : false;
417 } 409 }
418 410
419 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, 411 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id,
420 ash::ShelfLaunchSource source, 412 ash::ShelfLaunchSource source,
421 int event_flags) { 413 int event_flags) {
422 // If there is an existing non-shortcut controller for this app, open it. 414 // If there is an existing non-shortcut delegate for this app, open it.
423 ash::ShelfID id = GetShelfIDForAppID(app_id); 415 ash::ShelfID id = GetShelfIDForAppID(app_id);
424 if (id) { 416 if (id) {
425 SelectItemWithSource(model_->GetShelfItemDelegate(id), source); 417 SelectItemWithSource(model_->GetShelfItemDelegate(id), source);
426 return; 418 return;
427 } 419 }
428 420
429 // Create a temporary application launcher item and use it to see if there are 421 // Create a temporary application launcher item and use it to see if there are
430 // running instances. 422 // running instances.
431 ash::AppLaunchId app_launch_id(app_id); 423 ash::AppLaunchId app_launch_id(app_id);
432 std::unique_ptr<AppShortcutLauncherItemController> controller( 424 std::unique_ptr<AppShortcutLauncherItemController> item_delegate =
433 AppShortcutLauncherItemController::Create(app_launch_id, this)); 425 AppShortcutLauncherItemController::Create(app_launch_id);
434 if (!controller->GetRunningApplications().empty()) 426 if (!item_delegate->GetRunningApplications().empty())
435 SelectItemWithSource(controller.get(), source); 427 SelectItemWithSource(item_delegate.get(), source);
436 else 428 else
437 LaunchApp(app_launch_id, source, event_flags); 429 LaunchApp(app_launch_id, source, event_flags);
438 } 430 }
439 431
440 void ChromeLauncherControllerImpl::SetLauncherItemImage( 432 void ChromeLauncherControllerImpl::SetLauncherItemImage(
441 ash::ShelfID shelf_id, 433 ash::ShelfID shelf_id,
442 const gfx::ImageSkia& image) { 434 const gfx::ImageSkia& image) {
443 const ash::ShelfItem* item = GetItem(shelf_id); 435 const ash::ShelfItem* item = GetItem(shelf_id);
444 if (item) { 436 if (item) {
445 ash::ShelfItem new_item = *item; 437 ash::ShelfItem new_item = *item;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 497
506 return id; 498 return id;
507 } 499 }
508 500
509 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( 501 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest(
510 ash::ShelfID id, 502 ash::ShelfID id,
511 const GURL& url) { 503 const GURL& url) {
512 const ash::ShelfItem* item = GetItem(id); 504 const ash::ShelfItem* item = GetItem(id);
513 if (item && !IsPlatformApp(id) && 505 if (item && !IsPlatformApp(id) &&
514 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { 506 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) {
515 LauncherItemController* controller = GetLauncherItemController(id); 507 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(id);
516 DCHECK(controller); 508 AppShortcutLauncherItemController* item_controller =
517 AppShortcutLauncherItemController* app_controller = 509 static_cast<AppShortcutLauncherItemController*>(item_delegate);
518 static_cast<AppShortcutLauncherItemController*>(controller); 510 item_controller->set_refocus_url(url);
519 app_controller->set_refocus_url(url);
520 } else { 511 } else {
521 NOTREACHED() << "Invalid launcher item or type"; 512 NOTREACHED() << "Invalid launcher item or type";
522 } 513 }
523 } 514 }
524 515
525 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( 516 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive(
526 ui::BaseWindow* window, 517 ui::BaseWindow* window,
527 bool allow_minimize) { 518 bool allow_minimize) {
528 // In separated desktop mode we might have to teleport a window back to the 519 // In separated desktop mode we might have to teleport a window back to the
529 // current user. 520 // current user.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 ash::Shell::GetInstance()->CreateKeyboard(); 574 ash::Shell::GetInstance()->CreateKeyboard();
584 } 575 }
585 576
586 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( 577 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession(
587 Profile* profile) { 578 Profile* profile) {
588 // Switch the running applications to the new user. 579 // Switch the running applications to the new user.
589 for (auto& controller : app_window_controllers_) 580 for (auto& controller : app_window_controllers_)
590 controller->AdditionalUserAddedToSession(profile); 581 controller->AdditionalUserAddedToSession(profile);
591 } 582 }
592 583
593 MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( 584 ash::MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting(
594 const ash::ShelfItem& item) { 585 const ash::ShelfItem& item) {
595 LauncherItemController* controller = GetLauncherItemController(item.id); 586 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item.id);
596 return controller ? controller->GetAppMenuItems(ui::EF_NONE) : MenuItemList(); 587 return item_delegate ? item_delegate->GetAppMenuItems(ui::EF_NONE)
588 : ash::MenuItemList();
597 } 589 }
598 590
599 std::vector<content::WebContents*> 591 std::vector<content::WebContents*>
600 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( 592 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId(
601 const std::string& app_id) { 593 const std::string& app_id) {
602 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); 594 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id));
603 // If there is no such item pinned to the launcher, no menu gets created. 595 // If there is no such item pinned to the launcher, no menu gets created.
604 if (!item || item->type != ash::TYPE_PINNED_APP) 596 if (!item || item->type != ash::TYPE_PINNED_APP)
605 return std::vector<content::WebContents*>(); 597 return std::vector<content::WebContents*>();
606 LauncherItemController* controller = GetLauncherItemController(item->id); 598 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item->id);
607 AppShortcutLauncherItemController* app_controller = 599 AppShortcutLauncherItemController* item_controller =
608 static_cast<AppShortcutLauncherItemController*>(controller); 600 static_cast<AppShortcutLauncherItemController*>(item_delegate);
609 return app_controller->GetRunningApplications(); 601 return item_controller->GetRunningApplications();
610 } 602 }
611 603
612 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, 604 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id,
613 int window_index) { 605 int window_index) {
614 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); 606 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id));
615 if (item && 607 if (item &&
616 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { 608 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) {
617 LauncherItemController* controller = GetLauncherItemController(item->id); 609 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item->id);
618 AppWindowLauncherItemController* app_window_controller = 610 AppWindowLauncherItemController* item_controller =
619 controller->AsAppWindowLauncherItemController(); 611 item_delegate->AsAppWindowLauncherItemController();
620 DCHECK(app_window_controller); 612 item_controller->ActivateIndexedApp(window_index);
621 app_window_controller->ActivateIndexedApp(window_index);
622 } 613 }
623 } 614 }
624 615
625 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( 616 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication(
626 content::WebContents* web_contents, 617 content::WebContents* web_contents,
627 const std::string& app_id) { 618 const std::string& app_id) {
628 if ((web_contents_to_app_id_.find(web_contents) != 619 if ((web_contents_to_app_id_.find(web_contents) !=
629 web_contents_to_app_id_.end()) && 620 web_contents_to_app_id_.end()) &&
630 (web_contents_to_app_id_[web_contents] == app_id)) 621 (web_contents_to_app_id_[web_contents] == app_id))
631 return true; 622 return true;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 for (const auto& pair : id_to_item_controller_map_) { 675 for (const auto& pair : id_to_item_controller_map_) {
685 const ash::ShelfItem* item = GetItem(pair.first); 676 const ash::ShelfItem* item = GetItem(pair.first);
686 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT) 677 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT)
687 return static_cast<BrowserShortcutLauncherItemController*>(pair.second); 678 return static_cast<BrowserShortcutLauncherItemController*>(pair.second);
688 } 679 }
689 NOTREACHED() 680 NOTREACHED()
690 << "There should be always be a BrowserShortcutLauncherItemController."; 681 << "There should be always be a BrowserShortcutLauncherItemController.";
691 return nullptr; 682 return nullptr;
692 } 683 }
693 684
694 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( 685 ash::ShelfItemDelegate* ChromeLauncherControllerImpl::GetShelfItemDelegate(
695 const ash::ShelfID id) { 686 const ash::ShelfID id) {
696 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 687 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
697 return iter == id_to_item_controller_map_.end() ? nullptr : iter->second; 688 return iter == id_to_item_controller_map_.end() ? nullptr : iter->second;
698 } 689 }
699 690
700 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( 691 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser(
701 ash::WmShelf* shelf, 692 ash::WmShelf* shelf,
702 const AccountId& account_id) const { 693 const AccountId& account_id) const {
703 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); 694 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id);
704 if (!other_profile || other_profile == profile()) 695 if (!other_profile || other_profile == profile())
(...skipping 23 matching lines...) Expand all
728 user_switch_observer_->OnUserProfileReadyToSwitch(profile); 719 user_switch_observer_->OnUserProfileReadyToSwitch(profile);
729 } 720 }
730 721
731 ArcAppDeferredLauncherController* 722 ArcAppDeferredLauncherController*
732 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { 723 ChromeLauncherControllerImpl::GetArcDeferredLauncher() {
733 return arc_deferred_launcher_.get(); 724 return arc_deferred_launcher_.get();
734 } 725 }
735 726
736 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( 727 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID(
737 ash::ShelfID id) { 728 ash::ShelfID id) {
738 LauncherItemController* controller = GetLauncherItemController(id); 729 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(id);
739 return controller ? controller->launch_id() : base::EmptyString(); 730 return delegate ? delegate->launch_id() : base::EmptyString();
740 } 731 }
741 732
742 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { 733 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) {
743 // The base class implementation updates the helper and app icon loaders. 734 // The base class implementation updates the helper and app icon loaders.
744 ChromeLauncherController::AttachProfile(profile_to_attach); 735 ChromeLauncherController::AttachProfile(profile_to_attach);
745 736
746 pref_change_registrar_.Init(profile()->GetPrefs()); 737 pref_change_registrar_.Init(profile()->GetPrefs());
747 pref_change_registrar_.Add( 738 pref_change_registrar_.Add(
748 prefs::kPolicyPinnedLauncherApps, 739 prefs::kPolicyPinnedLauncherApps,
749 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 740 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 if (ash::Shell::HasInstance()) 924 if (ash::Shell::HasInstance())
934 SetVirtualKeyboardBehaviorFromPrefs(); 925 SetVirtualKeyboardBehaviorFromPrefs();
935 926
936 prefs_observer_ = 927 prefs_observer_ =
937 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); 928 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
938 } 929 }
939 930
940 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 931 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
941 const ash::AppLaunchId& app_launch_id, 932 const ash::AppLaunchId& app_launch_id,
942 int index) { 933 int index) {
943 AppShortcutLauncherItemController* controller = 934 return InsertAppLauncherItem(
944 AppShortcutLauncherItemController::Create(app_launch_id, this); 935 AppShortcutLauncherItemController::Create(app_launch_id),
945 return InsertAppLauncherItem(controller, ash::STATUS_CLOSED, index, 936 ash::STATUS_CLOSED, index, ash::TYPE_PINNED_APP);
946 ash::TYPE_PINNED_APP);
947 } 937 }
948 938
949 /////////////////////////////////////////////////////////////////////////////// 939 ///////////////////////////////////////////////////////////////////////////////
950 // ChromeLauncherControllerImpl private: 940 // ChromeLauncherControllerImpl private:
951 941
952 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 942 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
953 RunningAppListIds list; 943 RunningAppListIds list;
954 for (int i = 0; i < model_->item_count(); i++) { 944 for (int i = 0; i < model_->item_count(); i++) {
955 if (model_->items()[i].type == ash::TYPE_APP) 945 if (model_->items()[i].type == ash::TYPE_APP)
956 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); 946 list.push_back(GetAppIDForShelfID(model_->items()[i].id));
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 : ash::STATUS_RUNNING; 1189 : ash::STATUS_RUNNING;
1200 } else { 1190 } else {
1201 status = ash::STATUS_RUNNING; 1191 status = ash::STATUS_RUNNING;
1202 } 1192 }
1203 } 1193 }
1204 } 1194 }
1205 return status; 1195 return status;
1206 } 1196 }
1207 1197
1208 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( 1198 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem(
1209 LauncherItemController* controller, 1199 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
1210 ash::ShelfItemStatus status, 1200 ash::ShelfItemStatus status,
1211 int index, 1201 int index,
1212 ash::ShelfItemType shelf_item_type) { 1202 ash::ShelfItemType shelf_item_type) {
1213 ash::ShelfID id = model_->next_id(); 1203 ash::ShelfID id = model_->next_id();
1214 CHECK(!GetItem(id)); 1204 CHECK(!GetItem(id));
1215 CHECK(controller); 1205 CHECK(item_delegate);
1216 // Ash's ShelfWindowWatcher handles app panel windows separately. 1206 // Ash's ShelfWindowWatcher handles app panel windows separately.
1217 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); 1207 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type);
1218 id_to_item_controller_map_[id] = controller; 1208 id_to_item_controller_map_[id] = item_delegate.get();
1219 controller->set_shelf_id(id); 1209 item_delegate->set_shelf_id(id);
1220 1210
1221 ash::ShelfItem item; 1211 ash::ShelfItem item;
1222 item.type = shelf_item_type; 1212 item.type = shelf_item_type;
1223 item.app_launch_id = controller->app_launch_id(); 1213 item.app_launch_id = item_delegate->app_launch_id();
1224 item.image = extensions::util::GetDefaultAppIcon(); 1214 item.image = extensions::util::GetDefaultAppIcon();
1225 1215
1226 const std::string& app_id = controller->app_id(); 1216 const std::string& app_id = item_delegate->app_id();
1227 item.title = LauncherControllerHelper::GetAppTitle(profile(), app_id); 1217 item.title = LauncherControllerHelper::GetAppTitle(profile(), app_id);
1228 1218
1229 ash::ShelfItemStatus new_state = GetAppState(app_id); 1219 ash::ShelfItemStatus new_state = GetAppState(app_id);
1230 if (new_state != ash::STATUS_CLOSED) 1220 if (new_state != ash::STATUS_CLOSED)
1231 status = new_state; 1221 status = new_state;
1232 1222
1233 item.status = status; 1223 item.status = status;
1234 model_->AddAt(index, item); 1224 model_->AddAt(index, item);
1235 1225
1236 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1226 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1237 if (app_icon_loader) { 1227 if (app_icon_loader) {
1238 app_icon_loader->FetchImage(app_id); 1228 app_icon_loader->FetchImage(app_id);
1239 app_icon_loader->UpdateImage(app_id); 1229 app_icon_loader->UpdateImage(app_id);
1240 } 1230 }
1241 1231
1242 SetShelfItemDelegate(id, controller); 1232 model_->SetShelfItemDelegate(id, std::move(item_delegate));
1243 return id; 1233 return id;
1244 } 1234 }
1245 1235
1246 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { 1236 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() {
1247 // Do not sync the pin position of the browser shortcut item when it is added; 1237 // Do not sync the pin position of the browser shortcut item when it is added;
1248 // its initial position before prefs have loaded is unimportant and the sync 1238 // its initial position before prefs have loaded is unimportant and the sync
1249 // service may not yet be initialized. 1239 // service may not yet be initialized.
1250 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler(); 1240 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler();
1251 1241
1252 ash::ShelfItem browser_shortcut; 1242 ash::ShelfItem browser_shortcut;
1253 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1243 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1254 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1244 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1255 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1245 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1256 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 1246 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
1257 browser_shortcut.app_launch_id = 1247 browser_shortcut.app_launch_id =
1258 ash::AppLaunchId(extension_misc::kChromeAppId); 1248 ash::AppLaunchId(extension_misc::kChromeAppId);
1259 ash::ShelfID id = model_->next_id(); 1249 ash::ShelfID id = model_->next_id();
1260 model_->AddAt(0, browser_shortcut); 1250 model_->AddAt(0, browser_shortcut);
1261 BrowserShortcutLauncherItemController* controller = 1251 std::unique_ptr<BrowserShortcutLauncherItemController> item_delegate =
1262 new BrowserShortcutLauncherItemController(this, model_); 1252 base::MakeUnique<BrowserShortcutLauncherItemController>(model_);
1263 controller->set_shelf_id(id); 1253 BrowserShortcutLauncherItemController* item_controller = item_delegate.get();
1264 id_to_item_controller_map_[id] = controller; 1254 item_controller->set_shelf_id(id);
1265 // ShelfModel owns BrowserShortcutLauncherItemController. 1255 id_to_item_controller_map_[id] = item_controller;
1266 SetShelfItemDelegate(id, controller); 1256 model_->SetShelfItemDelegate(id, std::move(item_delegate));
1267 controller->UpdateBrowserItemState(); 1257 item_controller->UpdateBrowserItemState();
1268 } 1258 }
1269 1259
1270 bool ChromeLauncherControllerImpl::IsIncognito( 1260 bool ChromeLauncherControllerImpl::IsIncognito(
1271 const content::WebContents* web_contents) const { 1261 const content::WebContents* web_contents) const {
1272 const Profile* profile = 1262 const Profile* profile =
1273 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1263 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1274 return profile->IsOffTheRecord() && !profile->IsGuestSession() && 1264 return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
1275 !profile->IsSystemProfile(); 1265 !profile->IsSystemProfile();
1276 } 1266 }
1277 1267
(...skipping 28 matching lines...) Expand all
1306 } 1296 }
1307 } 1297 }
1308 while (!browser_to_close.empty()) { 1298 while (!browser_to_close.empty()) {
1309 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); 1299 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model();
1310 if (!tab_strip->empty()) 1300 if (!tab_strip->empty())
1311 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 1301 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
1312 browser_to_close.pop_back(); 1302 browser_to_close.pop_back();
1313 } 1303 }
1314 } 1304 }
1315 1305
1316 void ChromeLauncherControllerImpl::SetShelfItemDelegate(
1317 ash::ShelfID id,
1318 ash::mojom::ShelfItemDelegate* item_delegate) {
1319 DCHECK_NE(id, ash::kInvalidShelfID);
1320 DCHECK(item_delegate);
1321 model_->SetShelfItemDelegate(
1322 id, base::WrapUnique<ash::mojom::ShelfItemDelegate>(item_delegate));
1323 }
1324
1325 void ChromeLauncherControllerImpl::ReleaseProfile() { 1306 void ChromeLauncherControllerImpl::ReleaseProfile() {
1326 if (app_sync_ui_state_) 1307 if (app_sync_ui_state_)
1327 app_sync_ui_state_->RemoveObserver(this); 1308 app_sync_ui_state_->RemoveObserver(this);
1328 1309
1329 app_updaters_.clear(); 1310 app_updaters_.clear();
1330 1311
1331 prefs_observer_.reset(); 1312 prefs_observer_.reset();
1332 1313
1333 pref_change_registrar_.RemoveAll(); 1314 pref_change_registrar_.RemoveAll();
1334 1315
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 old_item.app_launch_id.app_id()); 1377 old_item.app_launch_id.app_id());
1397 1378
1398 ash::AppLaunchId app_launch_id(shelf_app_id, 1379 ash::AppLaunchId app_launch_id(shelf_app_id,
1399 old_item.app_launch_id.launch_id()); 1380 old_item.app_launch_id.launch_id());
1400 ash::launcher::RemovePinPosition(profile(), app_launch_id); 1381 ash::launcher::RemovePinPosition(profile(), app_launch_id);
1401 } 1382 }
1402 } 1383 }
1403 1384
1404 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( 1385 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate(
1405 ash::ShelfID id, 1386 ash::ShelfID id,
1406 ash::mojom::ShelfItemDelegate* item_delegate) { 1387 ash::ShelfItemDelegate* item_delegate) {
1407 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we 1388 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
1408 // get into this state in the first place. 1389 // get into this state in the first place.
1409 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1390 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1410 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) 1391 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second)
1411 return; 1392 return;
1412 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; 1393 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id;
1413 id_to_item_controller_map_.erase(iter); 1394 id_to_item_controller_map_.erase(iter);
1414 } 1395 }
1415 1396
1416 /////////////////////////////////////////////////////////////////////////////// 1397 ///////////////////////////////////////////////////////////////////////////////
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 // AppIconLoaderDelegate: 1430 // AppIconLoaderDelegate:
1450 1431
1451 void ChromeLauncherControllerImpl::OnAppImageUpdated( 1432 void ChromeLauncherControllerImpl::OnAppImageUpdated(
1452 const std::string& id, 1433 const std::string& id,
1453 const gfx::ImageSkia& image) { 1434 const gfx::ImageSkia& image) {
1454 // TODO: need to get this working for shortcuts. 1435 // TODO: need to get this working for shortcuts.
1455 for (int index = 0; index < model_->item_count(); ++index) { 1436 for (int index = 0; index < model_->item_count(); ++index) {
1456 ash::ShelfItem item = model_->items()[index]; 1437 ash::ShelfItem item = model_->items()[index];
1457 if (GetAppIDForShelfID(item.id) != id) 1438 if (GetAppIDForShelfID(item.id) != id)
1458 continue; 1439 continue;
1459 LauncherItemController* controller = GetLauncherItemController(item.id); 1440 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(item.id);
1460 if (!controller || controller->image_set_by_controller()) 1441 if (!delegate || delegate->image_set_by_controller())
1461 continue; 1442 continue;
1462 item.image = image; 1443 item.image = image;
1463 if (arc_deferred_launcher_) 1444 if (arc_deferred_launcher_)
1464 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1445 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1465 model_->Set(index, item); 1446 model_->Set(index, item);
1466 // It's possible we're waiting on more than one item, so don't break. 1447 // It's possible we're waiting on more than one item, so don't break.
1467 } 1448 }
1468 } 1449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698