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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 ExtensionAppModelBuilder::ExtensionAppModelBuilder( | 42 ExtensionAppModelBuilder::ExtensionAppModelBuilder( |
43 Profile* profile, | 43 Profile* profile, |
44 app_list::AppListModel* model, | 44 app_list::AppListModel* model, |
45 AppListControllerDelegate* controller) | 45 AppListControllerDelegate* controller) |
46 : profile_(NULL), | 46 : profile_(NULL), |
47 controller_(controller), | 47 controller_(controller), |
48 model_(model), | 48 model_(model), |
49 highlighted_app_pending_(false), | 49 highlighted_app_pending_(false), |
50 tracker_(NULL) { | 50 tracker_(NULL) { |
| 51 model_->apps()->AddObserver(this); |
51 SwitchProfile(profile); // Builds the model. | 52 SwitchProfile(profile); // Builds the model. |
52 } | 53 } |
53 | 54 |
54 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { | 55 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { |
55 OnShutdown(); | 56 OnShutdown(); |
| 57 model_->apps()->RemoveObserver(this); |
56 } | 58 } |
57 | 59 |
58 void ExtensionAppModelBuilder::OnBeginExtensionInstall( | 60 void ExtensionAppModelBuilder::OnBeginExtensionInstall( |
59 const std::string& extension_id, | 61 const std::string& extension_id, |
60 const std::string& extension_name, | 62 const std::string& extension_name, |
61 const gfx::ImageSkia& installing_icon, | 63 const gfx::ImageSkia& installing_icon, |
62 bool is_app, | 64 bool is_app, |
63 bool is_platform_app) { | 65 bool is_platform_app) { |
64 if (!is_app) | 66 if (!is_app) |
65 return; | 67 return; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void ExtensionAppModelBuilder::UpdateHighlight() { | 234 void ExtensionAppModelBuilder::UpdateHighlight() { |
233 DCHECK(model_); | 235 DCHECK(model_); |
234 if (!highlighted_app_pending_ || highlight_app_id_.empty()) | 236 if (!highlighted_app_pending_ || highlight_app_id_.empty()) |
235 return; | 237 return; |
236 ExtensionAppItem* item = GetExtensionAppItem(highlight_app_id_); | 238 ExtensionAppItem* item = GetExtensionAppItem(highlight_app_id_); |
237 if (!item) | 239 if (!item) |
238 return; | 240 return; |
239 item->SetHighlighted(true); | 241 item->SetHighlighted(true); |
240 highlighted_app_pending_ = false; | 242 highlighted_app_pending_ = false; |
241 } | 243 } |
| 244 |
| 245 void ExtensionAppModelBuilder::ListItemsAdded(size_t start, size_t count) { |
| 246 } |
| 247 |
| 248 void ExtensionAppModelBuilder::ListItemsRemoved(size_t start, size_t count) { |
| 249 } |
| 250 |
| 251 void ExtensionAppModelBuilder::ListItemMoved(size_t index, |
| 252 size_t target_index) { |
| 253 app_list::AppListModel::Apps* app_list = model_->apps(); |
| 254 app_list::AppListItemModel* item = app_list->GetItemAt(target_index); |
| 255 if (item->GetAppType() != ExtensionAppItem::kAppType) |
| 256 return; |
| 257 |
| 258 ExtensionAppItem* prev = NULL; |
| 259 for (size_t idx = target_index; idx > 1; --idx) { |
| 260 app_list::AppListItemModel* item = app_list->GetItemAt(idx - 1); |
| 261 if (item->GetAppType() == ExtensionAppItem::kAppType) { |
| 262 prev = static_cast<ExtensionAppItem*>(item); |
| 263 break; |
| 264 } |
| 265 } |
| 266 ExtensionAppItem* next = NULL; |
| 267 for (size_t idx = target_index; idx < app_list->item_count() - 1; ++idx) { |
| 268 app_list::AppListItemModel* item = app_list->GetItemAt(idx + 1); |
| 269 if (item->GetAppType() == ExtensionAppItem::kAppType) { |
| 270 next = static_cast<ExtensionAppItem*>(item); |
| 271 break; |
| 272 } |
| 273 } |
| 274 if (prev || next) |
| 275 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
| 276 } |
| 277 |
| 278 void ExtensionAppModelBuilder::ListItemsChanged(size_t start, size_t count) { |
| 279 NOTREACHED(); |
| 280 } |
OLD | NEW |