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/apps_model_builder.h" | 5 #include "chrome/browser/ui/app_list/apps_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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 if (ShouldDisplayInAppLauncher(profile_, *app)) | 165 if (ShouldDisplayInAppLauncher(profile_, *app)) |
166 apps->push_back(new ExtensionAppItem(profile_, | 166 apps->push_back(new ExtensionAppItem(profile_, |
167 (*app)->id(), | 167 (*app)->id(), |
168 controller_, | 168 controller_, |
169 "", | 169 "", |
170 gfx::ImageSkia(), | 170 gfx::ImageSkia(), |
171 (*app)->is_platform_app())); | 171 (*app)->is_platform_app())); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
| 175 void AppsModelBuilder::SetProfile(Profile* profile) { |
| 176 profile_ = profile; |
| 177 model_->DeleteAll(); |
| 178 if (tracker_) { |
| 179 tracker_->RemoveObserver(this); |
| 180 tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_); |
| 181 } |
| 182 Build(); |
| 183 } |
| 184 |
175 void AppsModelBuilder::PopulateApps() { | 185 void AppsModelBuilder::PopulateApps() { |
176 ExtensionService* service = | 186 ExtensionService* service = |
177 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 187 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
178 if (!service) | 188 if (!service) |
179 return; | 189 return; |
180 | 190 |
181 Apps apps; | 191 Apps apps; |
182 AddApps(service->extensions(), &apps); | 192 AddApps(service->extensions(), &apps); |
183 AddApps(service->disabled_extensions(), &apps); | 193 AddApps(service->disabled_extensions(), &apps); |
184 AddApps(service->terminated_extensions(), &apps); | 194 AddApps(service->terminated_extensions(), &apps); |
185 | 195 |
186 if (apps.empty()) | 196 if (apps.empty()) |
187 return; | 197 return; |
188 | 198 |
189 service->extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); | 199 service->extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); |
190 std::sort(apps.begin(), apps.end(), &AppPrecedes); | 200 std::sort(apps.begin(), apps.end(), &AppPrecedes); |
191 | 201 |
192 for (size_t i = 0; i < apps.size(); ++i) | 202 ScopedVector<app_list::AppListItemModel> items; |
193 model_->Add(apps[i]); | 203 items.assign(apps.begin(), apps.end()); |
| 204 |
| 205 model_->AddAll(items.Pass()); |
194 } | 206 } |
195 | 207 |
196 void AppsModelBuilder::ResortApps() { | 208 void AppsModelBuilder::ResortApps() { |
197 // Scan app items in |model_| and put the apps that do not have valid ordinals | 209 // Scan app items in |model_| and put the apps that do not have valid ordinals |
198 // into |invalid_ordinal_apps|. This is needed to handle uninstalling a | 210 // into |invalid_ordinal_apps|. This is needed to handle uninstalling a |
199 // terminated app case, where there is no unload notification and uninstall | 211 // terminated app case, where there is no unload notification and uninstall |
200 // notification comes in after the app's ordinals are cleared. | 212 // notification comes in after the app's ordinals are cleared. |
201 // See http://crbug.com/256749. | 213 // See http://crbug.com/256749. |
202 Apps apps; | 214 Apps apps; |
203 Apps invalid_ordinal_apps; | 215 Apps invalid_ordinal_apps; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 327 |
316 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 328 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
317 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 329 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
318 GetAppAt(target_index + 1) : NULL; | 330 GetAppAt(target_index + 1) : NULL; |
319 GetAppAt(target_index)->Move(prev, next); | 331 GetAppAt(target_index)->Move(prev, next); |
320 } | 332 } |
321 | 333 |
322 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 334 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
323 NOTREACHED(); | 335 NOTREACHED(); |
324 } | 336 } |
OLD | NEW |