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

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

Issue 2352353002: Add AppLauncherId wrapper for items shown in shelf (Closed)
Patch Set: Review v10 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
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 368
369 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { 369 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) {
370 UnpinAndUpdatePrefs(id, true /* update_prefs */); 370 UnpinAndUpdatePrefs(id, true /* update_prefs */);
371 } 371 }
372 372
373 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, 373 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id,
374 bool update_prefs) { 374 bool update_prefs) {
375 LauncherItemController* controller = GetLauncherItemController(id); 375 LauncherItemController* controller = GetLauncherItemController(id);
376 CHECK(controller); 376 CHECK(controller);
377 377
378 if (update_prefs) 378 if (update_prefs) {
379 ash::launcher::RemovePinPosition(profile(), GetAppIDForShelfID(id)); 379 ash::launcher::RemovePinPosition(
380 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id)));
381 }
380 382
381 if (controller->type() == LauncherItemController::TYPE_APP || 383 if (controller->type() == LauncherItemController::TYPE_APP ||
382 controller->locked()) { 384 controller->locked()) {
383 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 385 UnpinRunningAppInternal(model_->ItemIndexByID(id));
384 } else { 386 } else {
385 LauncherItemClosed(id); 387 LauncherItemClosed(id);
386 } 388 }
387 } 389 }
388 390
389 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 391 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 return; 1152 return;
1151 1153
1152 const int max_index = model_->item_count(); 1154 const int max_index = model_->item_count();
1153 const int index = model_->ItemIndexByID(shelf_id); 1155 const int index = model_->ItemIndexByID(shelf_id);
1154 DCHECK_GT(index, 0); 1156 DCHECK_GT(index, 0);
1155 1157
1156 const std::string& app_id = GetAppIDForShelfID(shelf_id); 1158 const std::string& app_id = GetAppIDForShelfID(shelf_id);
1157 DCHECK(!app_id.empty()); 1159 DCHECK(!app_id.empty());
1158 1160
1159 std::string app_id_before; 1161 std::string app_id_before;
1160 std::vector<std::string> app_ids_after; 1162 std::vector<ash::launcher::AppLauncherId> app_launcher_ids_after;
1161 1163
1162 for (int i = index - 1; i > 0; --i) { 1164 for (int i = index - 1; i > 0; --i) {
1163 const ash::ShelfID shelf_id_before = model_->items()[i].id; 1165 const ash::ShelfID shelf_id_before = model_->items()[i].id;
1164 if (IsPinned(shelf_id_before)) { 1166 if (IsPinned(shelf_id_before)) {
1165 app_id_before = GetAppIDForShelfID(shelf_id_before); 1167 app_id_before = GetAppIDForShelfID(shelf_id_before);
1166 DCHECK(!app_id_before.empty()); 1168 DCHECK(!app_id_before.empty());
1167 break; 1169 break;
1168 } 1170 }
1169 } 1171 }
1170 1172
1171 for (int i = index + 1; i < max_index; ++i) { 1173 for (int i = index + 1; i < max_index; ++i) {
1172 const ash::ShelfID shelf_id_after = model_->items()[i].id; 1174 const ash::ShelfID shelf_id_after = model_->items()[i].id;
1173 if (IsPinned(shelf_id_after)) { 1175 if (IsPinned(shelf_id_after)) {
1174 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); 1176 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after);
1175 DCHECK(!app_id_after.empty()); 1177 DCHECK(!app_id_after.empty());
1176 app_ids_after.push_back(app_id_after); 1178 app_launcher_ids_after.push_back(
1179 ash::launcher::AppLauncherId(app_id_after));
1177 } 1180 }
1178 } 1181 }
1179 1182
1180 ash::launcher::SetPinPosition(profile(), app_id, app_id_before, 1183 ash::launcher::AppLauncherId app_launcher_id_before =
1181 app_ids_after); 1184 app_id_before.empty() ? ash::launcher::AppLauncherId()
1185 : ash::launcher::AppLauncherId(app_id_before);
1186
1187 ash::launcher::SetPinPosition(profile(), ash::launcher::AppLauncherId(app_id),
1188 app_launcher_id_before, app_launcher_ids_after);
1182 } 1189 }
1183 1190
1184 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { 1191 void ChromeLauncherControllerImpl::OnSyncModelUpdated() {
1185 UpdateAppLaunchersFromPref(); 1192 UpdateAppLaunchersFromPref();
1186 } 1193 }
1187 1194
1188 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { 1195 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() {
1189 base::ThreadTaskRunnerHandle::Get()->PostTask( 1196 base::ThreadTaskRunnerHandle::Get()->PostTask(
1190 FROM_HERE, 1197 FROM_HERE,
1191 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 1198 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
1192 weak_ptr_factory_.GetWeakPtr())); 1199 weak_ptr_factory_.GetWeakPtr()));
1193 } 1200 }
1194 1201
1195 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { 1202 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() {
1196 // There are various functions which will trigger a |SyncPinPosition| call 1203 // There are various functions which will trigger a |SyncPinPosition| call
1197 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu 1204 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu
1198 // model which will use weights to re-arrange the icons to new positions. 1205 // model which will use weights to re-arrange the icons to new positions.
1199 // Since this function is meant to synchronize the "is state" with the 1206 // Since this function is meant to synchronize the "is state" with the
1200 // "sync state", it makes no sense to store any changes by this function back 1207 // "sync state", it makes no sense to store any changes by this function back
1201 // into the pref state. Therefore we tell |persistPinnedState| to ignore any 1208 // into the pref state. Therefore we tell |persistPinnedState| to ignore any
1202 // invocations while we are running. 1209 // invocations while we are running.
1203 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1210 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1204 const std::vector<std::string> pinned_apps = 1211 const std::vector<ash::launcher::AppLauncherId> pinned_apps =
1205 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), 1212 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(),
1206 launcher_controller_helper()); 1213 launcher_controller_helper());
1207 1214
1208 int index = 0; 1215 int index = 0;
1209 // Skip app list items if it exists. 1216 // Skip app list items if it exists.
1210 if (model_->items()[0].type == ash::TYPE_APP_LIST) 1217 if (model_->items()[0].type == ash::TYPE_APP_LIST)
1211 ++index; 1218 ++index;
1212 1219
1213 // Apply pins in two steps. At the first step, go through the list of apps to 1220 // Apply pins in two steps. At the first step, go through the list of apps to
1214 // pin, move existing pin to current position specified by |index| or create 1221 // pin, move existing pin to current position specified by |index| or create
1215 // the new pin at that position. 1222 // the new pin at that position.
1216 for (const auto& pref_app_id : pinned_apps) { 1223 for (const auto& pref_app_launcher_id : pinned_apps) {
1217 // Filter out apps that may be mapped wrongly. 1224 // Filter out apps that may be mapped wrongly.
1218 // TODO(khmel): b/31703859 is to refactore shelf mapping. 1225 // TODO(khmel): b/31703859 is to refactore shelf mapping.
1226 const std::string app_launcher_id_str = pref_app_launcher_id.ToString();
1219 const std::string shelf_app_id = 1227 const std::string shelf_app_id =
1220 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); 1228 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(
1221 if (shelf_app_id != pref_app_id) 1229 app_launcher_id_str);
1230 if (shelf_app_id != app_launcher_id_str)
1222 continue; 1231 continue;
1223 1232
1224 // Update apps icon if applicable. 1233 // Update apps icon if applicable.
1225 OnAppUpdated(profile(), pref_app_id); 1234 OnAppUpdated(profile(), app_launcher_id_str);
1226 1235
1227 // Find existing pin or app from the right of current |index|. 1236 // Find existing pin or app from the right of current |index|.
1228 int app_index = index; 1237 int app_index = index;
1229 for (; app_index < model_->item_count(); ++app_index) { 1238 for (; app_index < model_->item_count(); ++app_index) {
1230 const ash::ShelfItem& item = model_->items()[app_index]; 1239 const ash::ShelfItem& item = model_->items()[app_index];
1231 const IDToItemControllerMap::iterator it = 1240 const IDToItemControllerMap::iterator it =
1232 id_to_item_controller_map_.find(item.id); 1241 id_to_item_controller_map_.find(item.id);
1233 if (it != id_to_item_controller_map_.end() && 1242 if (it != id_to_item_controller_map_.end() &&
1234 it->second->app_id() == pref_app_id) { 1243 it->second->app_id() == app_launcher_id_str) {
1235 break; 1244 break;
1236 } 1245 }
1237 } 1246 }
1238 if (app_index < model_->item_count()) { 1247 if (app_index < model_->item_count()) {
1239 // Found existing pin or running app. 1248 // Found existing pin or running app.
1240 const ash::ShelfItem item = model_->items()[app_index]; 1249 const ash::ShelfItem item = model_->items()[app_index];
1241 if (item.type == ash::TYPE_APP_SHORTCUT || 1250 if (item.type == ash::TYPE_APP_SHORTCUT ||
1242 item.type == ash::TYPE_BROWSER_SHORTCUT) { 1251 item.type == ash::TYPE_BROWSER_SHORTCUT) {
1243 // Just move to required position or keep it inplace. 1252 // Just move to required position or keep it inplace.
1244 model_->Move(app_index, index); 1253 model_->Move(app_index, index);
1245 } else { 1254 } else {
1246 PinRunningAppInternal(index, item.id); 1255 PinRunningAppInternal(index, item.id);
1247 } 1256 }
1248 DCHECK_EQ(model_->ItemIndexByID(item.id), index); 1257 DCHECK_EQ(model_->ItemIndexByID(item.id), index);
1249 } else { 1258 } else {
1250 // This is fresh pin. Create new one. 1259 // This is fresh pin. Create new one.
1251 DCHECK_NE(pref_app_id, extension_misc::kChromeAppId); 1260 DCHECK_NE(app_launcher_id_str, extension_misc::kChromeAppId);
1252 CreateAppShortcutLauncherItem(pref_app_id, index); 1261 CreateAppShortcutLauncherItem(app_launcher_id_str, index);
1253 } 1262 }
1254 ++index; 1263 ++index;
1255 } 1264 }
1256 1265
1257 // At second step remove any pin to the right from the current index. 1266 // At second step remove any pin to the right from the current index.
1258 while (index < model_->item_count()) { 1267 while (index < model_->item_count()) {
1259 const ash::ShelfItem item = model_->items()[index]; 1268 const ash::ShelfItem item = model_->items()[index];
1260 if (item.type != ash::TYPE_APP_SHORTCUT) { 1269 if (item.type != ash::TYPE_APP_SHORTCUT) {
1261 ++index; 1270 ++index;
1262 continue; 1271 continue;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 if (index == -1) 1549 if (index == -1)
1541 continue; 1550 continue;
1542 ash::ShelfItem item = model_->items()[index]; 1551 ash::ShelfItem item = model_->items()[index];
1543 item.image = image; 1552 item.image = image;
1544 if (arc_deferred_launcher_) 1553 if (arc_deferred_launcher_)
1545 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1554 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1546 model_->Set(index, item); 1555 model_->Set(index, item);
1547 // It's possible we're waiting on more than one item, so don't break. 1556 // It's possible we're waiting on more than one item, so don't break.
1548 } 1557 }
1549 } 1558 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/chrome_launcher_prefs.cc ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698