Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
| 32 #include "chrome/browser/chromeos/arc/arc_util.h" | 32 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 33 #include "chrome/browser/defaults.h" | 33 #include "chrome/browser/defaults.h" |
| 34 #include "chrome/browser/extensions/extension_util.h" | 34 #include "chrome/browser/extensions/extension_util.h" |
| 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 36 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 36 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
| 39 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 39 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 40 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 40 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 41 #include "chrome/browser/ui/ash/app_launcher_id.h" | |
| 41 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 42 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
| 42 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 43 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 43 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " | 44 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " |
| 44 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 46 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
| 47 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 48 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" | 49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" |
| 49 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 50 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h " | 51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h " |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 354 |
| 354 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 355 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
| 355 UnpinAndUpdatePrefs(id, true /* update_prefs */); | 356 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
| 356 } | 357 } |
| 357 | 358 |
| 358 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, | 359 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
| 359 bool update_prefs) { | 360 bool update_prefs) { |
| 360 LauncherItemController* controller = GetLauncherItemController(id); | 361 LauncherItemController* controller = GetLauncherItemController(id); |
| 361 CHECK(controller); | 362 CHECK(controller); |
| 362 | 363 |
| 363 if (update_prefs) { | 364 if (update_prefs) |
| 364 ash::launcher::RemovePinPosition( | 365 ash::launcher::RemovePinPosition(profile(), GetAppIDForShelfID(id)); |
| 365 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), | |
| 366 GetLaunchIDForShelfID(id))); | |
| 367 } | |
| 368 | 366 |
| 369 const ash::ShelfItem* item = GetItem(id); | 367 const ash::ShelfItem* item = GetItem(id); |
| 370 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) | 368 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) |
| 371 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 369 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
| 372 else | 370 else |
| 373 LauncherItemClosed(id); | 371 LauncherItemClosed(id); |
| 374 } | 372 } |
| 375 | 373 |
| 376 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 374 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
| 377 const ash::ShelfItem* item = GetItem(id); | 375 const ash::ShelfItem* item = GetItem(id); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 if (ignore_persist_pinned_state_change_) | 1069 if (ignore_persist_pinned_state_change_) |
| 1072 return; | 1070 return; |
| 1073 | 1071 |
| 1074 const int max_index = model_->item_count(); | 1072 const int max_index = model_->item_count(); |
| 1075 const int index = model_->ItemIndexByID(shelf_id); | 1073 const int index = model_->ItemIndexByID(shelf_id); |
| 1076 DCHECK_GT(index, 0); | 1074 DCHECK_GT(index, 0); |
| 1077 | 1075 |
| 1078 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 1076 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
| 1079 DCHECK(!app_id.empty()); | 1077 DCHECK(!app_id.empty()); |
| 1080 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); | 1078 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); |
| 1079 if (!launch_id.empty()) { | |
| 1080 VLOG(2) << "Pinning app '" << app_id << "' with non-empty launch id '" | |
| 1081 << launch_id << "' is not supported."; | |
| 1082 return; | |
| 1083 } | |
|
stevenjb
2017/02/08 18:19:03
Long term I think we are going to need to sync lau
khmel
2017/02/08 20:08:43
Agree, we can leave this code for now.
| |
| 1081 | 1084 |
| 1082 std::string app_id_before; | 1085 std::string app_id_before; |
| 1083 std::string launch_id_before; | 1086 std::vector<std::string> app_ids_after; |
| 1084 std::vector<ash::launcher::AppLauncherId> app_launcher_ids_after; | |
| 1085 | 1087 |
| 1086 for (int i = index - 1; i > 0; --i) { | 1088 for (int i = index - 1; i > 0; --i) { |
| 1087 const ash::ShelfID shelf_id_before = model_->items()[i].id; | 1089 const ash::ShelfID shelf_id_before = model_->items()[i].id; |
| 1088 if (IsPinned(shelf_id_before)) { | 1090 if (IsPinned(shelf_id_before)) { |
| 1089 app_id_before = GetAppIDForShelfID(shelf_id_before); | 1091 app_id_before = GetAppIDForShelfID(shelf_id_before); |
| 1090 DCHECK(!app_id_before.empty()); | 1092 DCHECK(!app_id_before.empty()); |
| 1091 launch_id_before = GetLaunchIDForShelfID(shelf_id_before); | |
| 1092 break; | 1093 break; |
| 1093 } | 1094 } |
| 1094 } | 1095 } |
| 1095 | 1096 |
| 1096 for (int i = index + 1; i < max_index; ++i) { | 1097 for (int i = index + 1; i < max_index; ++i) { |
| 1097 const ash::ShelfID shelf_id_after = model_->items()[i].id; | 1098 const ash::ShelfID shelf_id_after = model_->items()[i].id; |
| 1098 if (IsPinned(shelf_id_after)) { | 1099 if (IsPinned(shelf_id_after)) { |
| 1099 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); | 1100 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); |
| 1100 DCHECK(!app_id_after.empty()); | 1101 DCHECK(!app_id_after.empty()); |
| 1101 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after); | 1102 app_ids_after.push_back(app_id_after); |
| 1102 app_launcher_ids_after.push_back( | |
| 1103 ash::launcher::AppLauncherId(app_id_after, launch_id_after)); | |
| 1104 } | 1103 } |
| 1105 } | 1104 } |
| 1106 | 1105 |
| 1107 ash::launcher::AppLauncherId app_launcher_id_before = | 1106 ash::launcher::SetPinPosition(profile(), app_id, app_id_before, |
| 1108 app_id_before.empty() | 1107 app_ids_after); |
| 1109 ? ash::launcher::AppLauncherId() | |
| 1110 : ash::launcher::AppLauncherId(app_id_before, launch_id_before); | |
| 1111 | |
| 1112 ash::launcher::SetPinPosition(profile(), | |
| 1113 ash::launcher::AppLauncherId(app_id, launch_id), | |
| 1114 app_launcher_id_before, app_launcher_ids_after); | |
| 1115 } | 1108 } |
| 1116 | 1109 |
| 1117 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { | 1110 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { |
| 1118 UpdateAppLaunchersFromPref(); | 1111 UpdateAppLaunchersFromPref(); |
| 1119 } | 1112 } |
| 1120 | 1113 |
| 1121 void ChromeLauncherControllerImpl::OnIsSyncingChanged() { | 1114 void ChromeLauncherControllerImpl::OnIsSyncingChanged() { |
| 1122 UpdateAppLaunchersFromPref(); | 1115 UpdateAppLaunchersFromPref(); |
| 1123 } | 1116 } |
| 1124 | 1117 |
| 1125 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { | 1118 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { |
| 1126 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1119 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1127 FROM_HERE, | 1120 FROM_HERE, |
| 1128 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, | 1121 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, |
| 1129 weak_ptr_factory_.GetWeakPtr())); | 1122 weak_ptr_factory_.GetWeakPtr())); |
| 1130 } | 1123 } |
| 1131 | 1124 |
| 1132 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { | 1125 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
| 1133 // There are various functions which will trigger a |SyncPinPosition| call | 1126 // There are various functions which will trigger a |SyncPinPosition| call |
| 1134 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1127 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
| 1135 // model which will use weights to re-arrange the icons to new positions. | 1128 // model which will use weights to re-arrange the icons to new positions. |
| 1136 // Since this function is meant to synchronize the "is state" with the | 1129 // Since this function is meant to synchronize the "is state" with the |
| 1137 // "sync state", it makes no sense to store any changes by this function back | 1130 // "sync state", it makes no sense to store any changes by this function back |
| 1138 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1131 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
| 1139 // invocations while we are running. | 1132 // invocations while we are running. |
| 1140 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1133 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
| 1141 const std::vector<ash::launcher::AppLauncherId> pinned_apps = | 1134 const std::vector<std::string> pinned_apps = |
| 1142 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), | 1135 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), |
| 1143 launcher_controller_helper()); | 1136 launcher_controller_helper()); |
| 1144 | 1137 |
| 1145 int index = 0; | 1138 int index = 0; |
| 1146 // Skip app list items if it exists. | 1139 // Skip app list items if it exists. |
| 1147 if (model_->items()[0].type == ash::TYPE_APP_LIST) | 1140 if (model_->items()[0].type == ash::TYPE_APP_LIST) |
| 1148 ++index; | 1141 ++index; |
| 1149 | 1142 |
| 1150 // Apply pins in two steps. At the first step, go through the list of apps to | 1143 // Apply pins in two steps. At the first step, go through the list of apps to |
| 1151 // pin, move existing pin to current position specified by |index| or create | 1144 // pin, move existing pin to current position specified by |index| or create |
| 1152 // the new pin at that position. | 1145 // the new pin at that position. |
| 1153 for (const auto& pref_app_launcher_id : pinned_apps) { | 1146 for (const auto& app_id : pinned_apps) { |
| 1154 // Filter out apps that may be mapped wrongly. | 1147 // Filter out apps that may be mapped wrongly. |
| 1155 // TODO(khmel): b/31703859 is to refactore shelf mapping. | 1148 // TODO(khmel): b/31703859 is to refactore shelf mapping. |
| 1156 const std::string app_id = pref_app_launcher_id.app_id(); | |
| 1157 const std::string shelf_app_id = | 1149 const std::string shelf_app_id = |
| 1158 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 1150 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
| 1159 if (shelf_app_id != app_id) | 1151 if (shelf_app_id != app_id) |
| 1160 continue; | 1152 continue; |
| 1161 | 1153 |
| 1162 // Update apps icon if applicable. | 1154 // Update apps icon if applicable. |
| 1163 OnAppUpdated(profile(), app_id); | 1155 OnAppUpdated(profile(), app_id); |
| 1164 | 1156 |
| 1165 // Find existing pin or app from the right of current |index|. | 1157 // Find existing pin or app from the right of current |index|. |
| 1166 int app_index = index; | 1158 int app_index = index; |
| 1167 for (; app_index < model_->item_count(); ++app_index) { | 1159 for (; app_index < model_->item_count(); ++app_index) { |
| 1168 const ash::ShelfItem& item = model_->items()[app_index]; | 1160 const ash::ShelfItem& item = model_->items()[app_index]; |
| 1169 const IDToItemControllerMap::iterator it = | 1161 const IDToItemControllerMap::iterator it = |
| 1170 id_to_item_controller_map_.find(item.id); | 1162 id_to_item_controller_map_.find(item.id); |
| 1171 if (it != id_to_item_controller_map_.end() && | 1163 if (it != id_to_item_controller_map_.end() && |
| 1172 it->second->app_id() == app_id && | 1164 it->second->app_id() == app_id && it->second->launch_id().empty()) { |
| 1173 it->second->launch_id() == pref_app_launcher_id.launch_id()) { | |
| 1174 break; | 1165 break; |
| 1175 } | 1166 } |
| 1176 } | 1167 } |
| 1177 if (app_index < model_->item_count()) { | 1168 if (app_index < model_->item_count()) { |
| 1178 // Found existing pin or running app. | 1169 // Found existing pin or running app. |
| 1179 const ash::ShelfItem item = model_->items()[app_index]; | 1170 const ash::ShelfItem item = model_->items()[app_index]; |
| 1180 if (item.type == ash::TYPE_APP_SHORTCUT || | 1171 if (item.type == ash::TYPE_APP_SHORTCUT || |
| 1181 item.type == ash::TYPE_BROWSER_SHORTCUT) { | 1172 item.type == ash::TYPE_BROWSER_SHORTCUT) { |
| 1182 // Just move to required position or keep it inplace. | 1173 // Just move to required position or keep it inplace. |
| 1183 model_->Move(app_index, index); | 1174 model_->Move(app_index, index); |
| 1184 } else { | 1175 } else { |
| 1185 PinRunningAppInternal(index, item.id); | 1176 PinRunningAppInternal(index, item.id); |
| 1186 } | 1177 } |
| 1187 DCHECK_EQ(model_->ItemIndexByID(item.id), index); | 1178 DCHECK_EQ(model_->ItemIndexByID(item.id), index); |
| 1188 } else { | 1179 } else { |
| 1189 // This is fresh pin. Create new one. | 1180 // This is fresh pin. Create new one. |
| 1190 DCHECK_NE(app_id, extension_misc::kChromeAppId); | 1181 DCHECK_NE(app_id, extension_misc::kChromeAppId); |
| 1191 CreateAppShortcutLauncherItem(pref_app_launcher_id, index); | 1182 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id), |
| 1183 index); | |
| 1192 } | 1184 } |
| 1193 ++index; | 1185 ++index; |
| 1194 } | 1186 } |
| 1195 | 1187 |
| 1196 // At second step remove any pin to the right from the current index. | 1188 // At second step remove any pin to the right from the current index. |
| 1197 while (index < model_->item_count()) { | 1189 while (index < model_->item_count()) { |
| 1198 const ash::ShelfItem item = model_->items()[index]; | 1190 const ash::ShelfItem item = model_->items()[index]; |
| 1199 if (item.type != ash::TYPE_APP_SHORTCUT) { | 1191 if (item.type != ash::TYPE_APP_SHORTCUT) { |
| 1200 ++index; | 1192 ++index; |
| 1201 continue; | 1193 continue; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1490 LauncherItemController* controller = GetLauncherItemController(item.id); | 1482 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1491 if (!controller || controller->image_set_by_controller()) | 1483 if (!controller || controller->image_set_by_controller()) |
| 1492 continue; | 1484 continue; |
| 1493 item.image = image; | 1485 item.image = image; |
| 1494 if (arc_deferred_launcher_) | 1486 if (arc_deferred_launcher_) |
| 1495 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1487 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1496 model_->Set(index, item); | 1488 model_->Set(index, item); |
| 1497 // It's possible we're waiting on more than one item, so don't break. | 1489 // It's possible we're waiting on more than one item, so don't break. |
| 1498 } | 1490 } |
| 1499 } | 1491 } |
| OLD | NEW |