| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_list/extension_app_model_builder.h" | 5 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 if (apps.empty()) | 214 if (apps.empty()) |
| 215 return; | 215 return; |
| 216 | 216 |
| 217 for (size_t i = 0; i < apps.size(); ++i) | 217 for (size_t i = 0; i < apps.size(); ++i) |
| 218 InsertApp(apps[i]); | 218 InsertApp(apps[i]); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void ExtensionAppModelBuilder::InsertApp(ExtensionAppItem* app) { | 221 void ExtensionAppModelBuilder::InsertApp(ExtensionAppItem* app) { |
| 222 if (service_) { | 222 if (service_) { |
| 223 service_->AddExtensionAppItem(app); | 223 service_->AddItem(app); |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 model_->item_list()->AddItem(app); | 226 model_->item_list()->AddItem(app); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void ExtensionAppModelBuilder::SetHighlightedApp( | 229 void ExtensionAppModelBuilder::SetHighlightedApp( |
| 230 const std::string& extension_id) { | 230 const std::string& extension_id) { |
| 231 if (extension_id == highlight_app_id_) | 231 if (extension_id == highlight_app_id_) |
| 232 return; | 232 return; |
| 233 ExtensionAppItem* old_app = GetExtensionAppItem(highlight_app_id_); | 233 ExtensionAppItem* old_app = GetExtensionAppItem(highlight_app_id_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 void ExtensionAppModelBuilder::OnListItemMoved(size_t from_index, | 265 void ExtensionAppModelBuilder::OnListItemMoved(size_t from_index, |
| 266 size_t to_index, | 266 size_t to_index, |
| 267 app_list::AppListItem* item) { | 267 app_list::AppListItem* item) { |
| 268 // This will get called from AppListItemList::ListItemMoved after | 268 // This will get called from AppListItemList::ListItemMoved after |
| 269 // set_position is called for the item. | 269 // set_position is called for the item. |
| 270 app_list::AppListItemList* item_list = model_->item_list(); | 270 app_list::AppListItemList* item_list = model_->item_list(); |
| 271 if (item->GetAppType() != ExtensionAppItem::kAppType) | 271 if (item->GetAppType() != ExtensionAppItem::kAppType) |
| 272 return; | 272 return; |
| 273 | 273 |
| 274 ExtensionAppItem* extension_item = static_cast<ExtensionAppItem*>(item); | |
| 275 if (service_) { | 274 if (service_) { |
| 276 service_->UpdateExtensionAppItem(extension_item); | 275 service_->UpdateItem(item); |
| 277 return; | 276 return; |
| 278 } | 277 } |
| 279 | 278 |
| 280 ExtensionAppItem* prev = NULL; | 279 ExtensionAppItem* prev = NULL; |
| 281 for (size_t idx = to_index; idx > 0; --idx) { | 280 for (size_t idx = to_index; idx > 0; --idx) { |
| 282 app_list::AppListItem* item = item_list->item_at(idx - 1); | 281 app_list::AppListItem* item = item_list->item_at(idx - 1); |
| 283 if (item->GetAppType() == ExtensionAppItem::kAppType) { | 282 if (item->GetAppType() == ExtensionAppItem::kAppType) { |
| 284 prev = static_cast<ExtensionAppItem*>(item); | 283 prev = static_cast<ExtensionAppItem*>(item); |
| 285 break; | 284 break; |
| 286 } | 285 } |
| 287 } | 286 } |
| 288 ExtensionAppItem* next = NULL; | 287 ExtensionAppItem* next = NULL; |
| 289 for (size_t idx = to_index; idx < item_list->item_count() - 1; ++idx) { | 288 for (size_t idx = to_index; idx < item_list->item_count() - 1; ++idx) { |
| 290 app_list::AppListItem* item = item_list->item_at(idx + 1); | 289 app_list::AppListItem* item = item_list->item_at(idx + 1); |
| 291 if (item->GetAppType() == ExtensionAppItem::kAppType) { | 290 if (item->GetAppType() == ExtensionAppItem::kAppType) { |
| 292 next = static_cast<ExtensionAppItem*>(item); | 291 next = static_cast<ExtensionAppItem*>(item); |
| 293 break; | 292 break; |
| 294 } | 293 } |
| 295 } | 294 } |
| 296 // item->Move will call set_position, overriding the item's position. | 295 // item->Move will call set_position, overriding the item's position. |
| 297 if (prev || next) | 296 if (prev || next) |
| 298 extension_item->Move(prev, next); | 297 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
| 299 } | 298 } |
| OLD | NEW |