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

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

Issue 2680423003: Reduce namespaces for ash::launcher::AppLauncherId (Closed)
Patch Set: Created 3 years, 10 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
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 UnpinAndUpdatePrefs(id, true /* update_prefs */); 356 UnpinAndUpdatePrefs(id, true /* update_prefs */);
357 } 357 }
358 358
359 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, 359 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id,
360 bool update_prefs) { 360 bool update_prefs) {
361 LauncherItemController* controller = GetLauncherItemController(id); 361 LauncherItemController* controller = GetLauncherItemController(id);
362 CHECK(controller); 362 CHECK(controller);
363 363
364 if (update_prefs) { 364 if (update_prefs) {
365 ash::launcher::RemovePinPosition( 365 ash::launcher::RemovePinPosition(
366 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), 366 profile(),
367 GetLaunchIDForShelfID(id))); 367 ash::AppLauncherId(GetAppIDForShelfID(id), GetLaunchIDForShelfID(id)));
368 } 368 }
369 369
370 const ash::ShelfItem* item = GetItem(id); 370 const ash::ShelfItem* item = GetItem(id);
371 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) 371 if (item && (item->status != ash::STATUS_CLOSED || controller->locked()))
372 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 372 UnpinRunningAppInternal(model_->ItemIndexByID(id));
373 else 373 else
374 LauncherItemClosed(id); 374 LauncherItemClosed(id);
375 } 375 }
376 376
377 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 377 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
378 const ash::ShelfItem* item = GetItem(id); 378 const ash::ShelfItem* item = GetItem(id);
379 return item && (item->type == ash::TYPE_APP_SHORTCUT || 379 return item && (item->type == ash::TYPE_APP_SHORTCUT ||
380 item->type == ash::TYPE_BROWSER_SHORTCUT); 380 item->type == ash::TYPE_BROWSER_SHORTCUT);
381 } 381 }
382 382
383 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) { 383 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) {
384 if (!HasShelfIDToAppIDMapping(id)) 384 if (!HasShelfIDToAppIDMapping(id))
385 return; // May happen if item closed with menu open. 385 return; // May happen if item closed with menu open.
386 386
387 if (IsPinned(id)) 387 if (IsPinned(id))
388 Unpin(id); 388 Unpin(id);
389 else 389 else
390 Pin(id); 390 Pin(id);
391 } 391 }
392 392
393 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 393 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
394 ash::ShelfID id = GetShelfIDForAppID(app_id); 394 ash::ShelfID id = GetShelfIDForAppID(app_id);
395 if (id == ash::kInvalidShelfID) { 395 if (id == ash::kInvalidShelfID) {
396 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), 396 CreateAppShortcutLauncherItemWithType(ash::AppLauncherId(app_id),
397 model_->item_count(), ash::TYPE_APP); 397 model_->item_count(), ash::TYPE_APP);
398 id = GetShelfIDForAppID(app_id); 398 id = GetShelfIDForAppID(app_id);
399 } 399 }
400 CHECK(id); 400 CHECK(id);
401 GetLauncherItemController(id)->lock(); 401 GetLauncherItemController(id)->lock();
402 } 402 }
403 403
404 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 404 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
405 const std::string& app_id) { 405 const std::string& app_id) {
406 ash::ShelfID id = GetShelfIDForAppID(app_id); 406 ash::ShelfID id = GetShelfIDForAppID(app_id);
407 CHECK_NE(id, ash::kInvalidShelfID); 407 CHECK_NE(id, ash::kInvalidShelfID);
408 LauncherItemController* controller = GetLauncherItemController(id); 408 LauncherItemController* controller = GetLauncherItemController(id);
409 controller->unlock(); 409 controller->unlock();
410 if (!controller->locked() && !IsPinned(id)) 410 if (!controller->locked() && !IsPinned(id))
411 CloseLauncherItem(id); 411 CloseLauncherItem(id);
412 } 412 }
413 413
414 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { 414 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) {
415 LauncherItemController* controller = GetLauncherItemController(id); 415 LauncherItemController* controller = GetLauncherItemController(id);
416 if (!controller) 416 if (!controller)
417 return; // In case invoked from menu and item closed while menu up. 417 return; // In case invoked from menu and item closed while menu up.
418 418
419 // Launching some items replaces the associated item controller instance, 419 // Launching some items replaces the associated item controller instance,
420 // which destroys the app and launch id strings; making copies avoid crashes. 420 // which destroys the app and launch id strings; making copies avoid crashes.
421 LaunchApp(ash::launcher::AppLauncherId(controller->app_id(), 421 LaunchApp(ash::AppLauncherId(controller->app_id(), controller->launch_id()),
422 controller->launch_id()),
423 ash::LAUNCH_FROM_UNKNOWN, event_flags); 422 ash::LAUNCH_FROM_UNKNOWN, event_flags);
424 } 423 }
425 424
426 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { 425 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) {
427 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 426 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
428 if (!delegate) 427 if (!delegate)
429 return; // May happen if menu closed. 428 return; // May happen if menu closed.
430 delegate->Close(); 429 delegate->Close();
431 } 430 }
432 431
(...skipping 24 matching lines...) Expand all
457 return; 456 return;
458 } 457 }
459 458
460 // Create a temporary application launcher item and use it to see if there are 459 // Create a temporary application launcher item and use it to see if there are
461 // running instances. 460 // running instances.
462 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 461 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
463 AppShortcutLauncherItemController::Create(app_id, std::string(), this)); 462 AppShortcutLauncherItemController::Create(app_id, std::string(), this));
464 if (!app_controller->GetRunningApplications().empty()) 463 if (!app_controller->GetRunningApplications().empty())
465 app_controller->Activate(source); 464 app_controller->Activate(source);
466 else 465 else
467 LaunchApp(ash::launcher::AppLauncherId(app_id), source, event_flags); 466 LaunchApp(ash::AppLauncherId(app_id), source, event_flags);
468 } 467 }
469 468
470 void ChromeLauncherControllerImpl::SetLauncherItemImage( 469 void ChromeLauncherControllerImpl::SetLauncherItemImage(
471 ash::ShelfID shelf_id, 470 ash::ShelfID shelf_id,
472 const gfx::ImageSkia& image) { 471 const gfx::ImageSkia& image) {
473 const ash::ShelfItem* item = GetItem(shelf_id); 472 const ash::ShelfItem* item = GetItem(shelf_id);
474 if (item) { 473 if (item) {
475 ash::ShelfItem new_item = *item; 474 ash::ShelfItem new_item = *item;
476 new_item.image = image; 475 new_item.image = image;
477 model_->Set(model_->ItemIndexByID(shelf_id), new_item); 476 model_->Set(model_->ItemIndexByID(shelf_id), new_item);
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 950
952 // TODO(sky): update unit test so that this test isn't necessary. 951 // TODO(sky): update unit test so that this test isn't necessary.
953 if (ash::Shell::HasInstance()) 952 if (ash::Shell::HasInstance())
954 SetVirtualKeyboardBehaviorFromPrefs(); 953 SetVirtualKeyboardBehaviorFromPrefs();
955 954
956 prefs_observer_ = 955 prefs_observer_ =
957 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); 956 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
958 } 957 }
959 958
960 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 959 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
961 const ash::launcher::AppLauncherId& app_launcher_id, 960 const ash::AppLauncherId& app_launcher_id,
962 int index) { 961 int index) {
963 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, 962 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index,
964 ash::TYPE_APP_SHORTCUT); 963 ash::TYPE_APP_SHORTCUT);
965 } 964 }
966 965
967 /////////////////////////////////////////////////////////////////////////////// 966 ///////////////////////////////////////////////////////////////////////////////
968 // ChromeLauncherControllerImpl private: 967 // ChromeLauncherControllerImpl private:
969 968
970 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 969 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
971 RunningAppListIds list; 970 RunningAppListIds list;
(...skipping 22 matching lines...) Expand all
994 DCHECK_GE(app_index, 0); 993 DCHECK_GE(app_index, 0);
995 if (running_index != app_index) 994 if (running_index != app_index)
996 model_->Move(running_index, app_index); 995 model_->Move(running_index, app_index);
997 running_index++; 996 running_index++;
998 } 997 }
999 } 998 }
1000 } 999 }
1001 1000
1002 ash::ShelfID 1001 ash::ShelfID
1003 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1002 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1004 const ash::launcher::AppLauncherId& app_launcher_id, 1003 const ash::AppLauncherId& app_launcher_id,
1005 int index, 1004 int index,
1006 ash::ShelfItemType shelf_item_type) { 1005 ash::ShelfItemType shelf_item_type) {
1007 AppShortcutLauncherItemController* controller = 1006 AppShortcutLauncherItemController* controller =
1008 AppShortcutLauncherItemController::Create( 1007 AppShortcutLauncherItemController::Create(
1009 app_launcher_id.app_id(), app_launcher_id.launch_id(), this); 1008 app_launcher_id.app_id(), app_launcher_id.launch_id(), this);
1010 ash::ShelfID shelf_id = 1009 ash::ShelfID shelf_id =
1011 InsertAppLauncherItem(controller, app_launcher_id.app_id(), 1010 InsertAppLauncherItem(controller, app_launcher_id.app_id(),
1012 ash::STATUS_CLOSED, index, shelf_item_type); 1011 ash::STATUS_CLOSED, index, shelf_item_type);
1013 return shelf_id; 1012 return shelf_id;
1014 } 1013 }
(...skipping 18 matching lines...) Expand all
1033 // If there is an item, do nothing and return. 1032 // If there is an item, do nothing and return.
1034 if (IsAppPinned(app_id)) 1033 if (IsAppPinned(app_id))
1035 return; 1034 return;
1036 1035
1037 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1036 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1038 if (shelf_id) { 1037 if (shelf_id) {
1039 // App item exists, pin it 1038 // App item exists, pin it
1040 Pin(shelf_id); 1039 Pin(shelf_id);
1041 } else { 1040 } else {
1042 // Otherwise, create a shortcut item for it. 1041 // Otherwise, create a shortcut item for it.
1043 shelf_id = CreateAppShortcutLauncherItem( 1042 shelf_id = CreateAppShortcutLauncherItem(ash::AppLauncherId(app_id),
1044 ash::launcher::AppLauncherId(app_id), model_->item_count()); 1043 model_->item_count());
1045 SyncPinPosition(shelf_id); 1044 SyncPinPosition(shelf_id);
1046 } 1045 }
1047 } 1046 }
1048 1047
1049 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, 1048 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id,
1050 bool update_prefs) { 1049 bool update_prefs) {
1051 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1050 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1052 if (shelf_id && IsPinned(shelf_id)) 1051 if (shelf_id && IsPinned(shelf_id))
1053 UnpinAndUpdatePrefs(shelf_id, update_prefs); 1052 UnpinAndUpdatePrefs(shelf_id, update_prefs);
1054 } 1053 }
(...skipping 25 matching lines...) Expand all
1080 const int max_index = model_->item_count(); 1079 const int max_index = model_->item_count();
1081 const int index = model_->ItemIndexByID(shelf_id); 1080 const int index = model_->ItemIndexByID(shelf_id);
1082 DCHECK_GT(index, 0); 1081 DCHECK_GT(index, 0);
1083 1082
1084 const std::string& app_id = GetAppIDForShelfID(shelf_id); 1083 const std::string& app_id = GetAppIDForShelfID(shelf_id);
1085 DCHECK(!app_id.empty()); 1084 DCHECK(!app_id.empty());
1086 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); 1085 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id);
1087 1086
1088 std::string app_id_before; 1087 std::string app_id_before;
1089 std::string launch_id_before; 1088 std::string launch_id_before;
1090 std::vector<ash::launcher::AppLauncherId> app_launcher_ids_after; 1089 std::vector<ash::AppLauncherId> app_launcher_ids_after;
1091 1090
1092 for (int i = index - 1; i > 0; --i) { 1091 for (int i = index - 1; i > 0; --i) {
1093 const ash::ShelfID shelf_id_before = model_->items()[i].id; 1092 const ash::ShelfID shelf_id_before = model_->items()[i].id;
1094 if (IsPinned(shelf_id_before)) { 1093 if (IsPinned(shelf_id_before)) {
1095 app_id_before = GetAppIDForShelfID(shelf_id_before); 1094 app_id_before = GetAppIDForShelfID(shelf_id_before);
1096 DCHECK(!app_id_before.empty()); 1095 DCHECK(!app_id_before.empty());
1097 launch_id_before = GetLaunchIDForShelfID(shelf_id_before); 1096 launch_id_before = GetLaunchIDForShelfID(shelf_id_before);
1098 break; 1097 break;
1099 } 1098 }
1100 } 1099 }
1101 1100
1102 for (int i = index + 1; i < max_index; ++i) { 1101 for (int i = index + 1; i < max_index; ++i) {
1103 const ash::ShelfID shelf_id_after = model_->items()[i].id; 1102 const ash::ShelfID shelf_id_after = model_->items()[i].id;
1104 if (IsPinned(shelf_id_after)) { 1103 if (IsPinned(shelf_id_after)) {
1105 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); 1104 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after);
1106 DCHECK(!app_id_after.empty()); 1105 DCHECK(!app_id_after.empty());
1107 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after); 1106 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after);
1108 app_launcher_ids_after.push_back( 1107 app_launcher_ids_after.push_back(
1109 ash::launcher::AppLauncherId(app_id_after, launch_id_after)); 1108 ash::AppLauncherId(app_id_after, launch_id_after));
1110 } 1109 }
1111 } 1110 }
1112 1111
1113 ash::launcher::AppLauncherId app_launcher_id_before = 1112 ash::AppLauncherId app_launcher_id_before =
1114 app_id_before.empty() 1113 app_id_before.empty()
1115 ? ash::launcher::AppLauncherId() 1114 ? ash::AppLauncherId()
1116 : ash::launcher::AppLauncherId(app_id_before, launch_id_before); 1115 : ash::AppLauncherId(app_id_before, launch_id_before);
1117 1116
1118 ash::launcher::SetPinPosition(profile(), 1117 ash::launcher::SetPinPosition(profile(),
1119 ash::launcher::AppLauncherId(app_id, launch_id), 1118 ash::AppLauncherId(app_id, launch_id),
1120 app_launcher_id_before, app_launcher_ids_after); 1119 app_launcher_id_before, app_launcher_ids_after);
1121 } 1120 }
1122 1121
1123 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { 1122 void ChromeLauncherControllerImpl::OnSyncModelUpdated() {
1124 UpdateAppLaunchersFromPref(); 1123 UpdateAppLaunchersFromPref();
1125 } 1124 }
1126 1125
1127 void ChromeLauncherControllerImpl::OnIsSyncingChanged() { 1126 void ChromeLauncherControllerImpl::OnIsSyncingChanged() {
1128 UpdateAppLaunchersFromPref(); 1127 UpdateAppLaunchersFromPref();
1129 } 1128 }
1130 1129
1131 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { 1130 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() {
1132 base::ThreadTaskRunnerHandle::Get()->PostTask( 1131 base::ThreadTaskRunnerHandle::Get()->PostTask(
1133 FROM_HERE, 1132 FROM_HERE,
1134 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 1133 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
1135 weak_ptr_factory_.GetWeakPtr())); 1134 weak_ptr_factory_.GetWeakPtr()));
1136 } 1135 }
1137 1136
1138 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { 1137 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() {
1139 // There are various functions which will trigger a |SyncPinPosition| call 1138 // There are various functions which will trigger a |SyncPinPosition| call
1140 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu 1139 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu
1141 // model which will use weights to re-arrange the icons to new positions. 1140 // model which will use weights to re-arrange the icons to new positions.
1142 // Since this function is meant to synchronize the "is state" with the 1141 // Since this function is meant to synchronize the "is state" with the
1143 // "sync state", it makes no sense to store any changes by this function back 1142 // "sync state", it makes no sense to store any changes by this function back
1144 // into the pref state. Therefore we tell |persistPinnedState| to ignore any 1143 // into the pref state. Therefore we tell |persistPinnedState| to ignore any
1145 // invocations while we are running. 1144 // invocations while we are running.
1146 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1145 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1147 const std::vector<ash::launcher::AppLauncherId> pinned_apps = 1146 const std::vector<ash::AppLauncherId> pinned_apps =
1148 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), 1147 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(),
1149 launcher_controller_helper()); 1148 launcher_controller_helper());
1150 1149
1151 int index = 0; 1150 int index = 0;
1152 // Skip app list items if it exists. 1151 // Skip app list items if it exists.
1153 if (model_->items()[0].type == ash::TYPE_APP_LIST) 1152 if (model_->items()[0].type == ash::TYPE_APP_LIST)
1154 ++index; 1153 ++index;
1155 1154
1156 // Apply pins in two steps. At the first step, go through the list of apps to 1155 // Apply pins in two steps. At the first step, go through the list of apps to
1157 // pin, move existing pin to current position specified by |index| or create 1156 // pin, move existing pin to current position specified by |index| or create
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 LauncherItemController* controller = GetLauncherItemController(item.id); 1495 LauncherItemController* controller = GetLauncherItemController(item.id);
1497 if (!controller || controller->image_set_by_controller()) 1496 if (!controller || controller->image_set_by_controller())
1498 continue; 1497 continue;
1499 item.image = image; 1498 item.image = image;
1500 if (arc_deferred_launcher_) 1499 if (arc_deferred_launcher_)
1501 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1500 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1502 model_->Set(index, item); 1501 model_->Set(index, item);
1503 // It's possible we're waiting on more than one item, so don't break. 1502 // It's possible we're waiting on more than one item, so don't break.
1504 } 1503 }
1505 } 1504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698