Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 AppsModelBuilder::AppsModelBuilder(Profile* profile, | 54 AppsModelBuilder::AppsModelBuilder(Profile* profile, |
| 55 app_list::AppListModel::Apps* model, | 55 app_list::AppListModel::Apps* model, |
| 56 AppListControllerDelegate* controller) | 56 AppListControllerDelegate* controller) |
| 57 : profile_(profile), | 57 : profile_(profile), |
| 58 controller_(controller), | 58 controller_(controller), |
| 59 model_(model), | 59 model_(model), |
| 60 highlighted_app_pending_(false), | 60 highlighted_app_pending_(false), |
| 61 ignore_changes_(false), | 61 ignore_changes_(false), |
| 62 tracker_(extensions::InstallTrackerFactory::GetForProfile(profile_)) { | 62 tracker_(NULL) { |
| 63 model_->AddObserver(this); | 63 model_->AddObserver(this); |
| 64 // Build the model. | |
| 65 SwitchProfile(profile); | |
| 64 } | 66 } |
| 65 | 67 |
| 66 AppsModelBuilder::~AppsModelBuilder() { | 68 AppsModelBuilder::~AppsModelBuilder() { |
| 67 OnShutdown(); | 69 OnShutdown(); |
| 68 model_->RemoveObserver(this); | 70 model_->RemoveObserver(this); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void AppsModelBuilder::Build() { | |
| 72 DCHECK(model_ && model_->item_count() == 0); | |
| 73 | |
| 74 PopulateApps(); | |
| 75 UpdateHighlight(); | |
| 76 | |
| 77 // Start observing after model is built. | |
| 78 tracker_->AddObserver(this); | |
| 79 } | |
| 80 | |
| 81 void AppsModelBuilder::OnBeginExtensionInstall( | 73 void AppsModelBuilder::OnBeginExtensionInstall( |
| 82 const std::string& extension_id, | 74 const std::string& extension_id, |
| 83 const std::string& extension_name, | 75 const std::string& extension_name, |
| 84 const gfx::ImageSkia& installing_icon, | 76 const gfx::ImageSkia& installing_icon, |
| 85 bool is_app, | 77 bool is_app, |
| 86 bool is_platform_app) { | 78 bool is_platform_app) { |
| 87 if (!is_app) | 79 if (!is_app) |
| 88 return; | 80 return; |
| 89 InsertApp(new ExtensionAppItem(profile_, | 81 InsertApp(new ExtensionAppItem(profile_, |
| 90 extension_id, | 82 extension_id, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 if (ShouldDisplayInAppLauncher(profile_, *app)) | 157 if (ShouldDisplayInAppLauncher(profile_, *app)) |
| 166 apps->push_back(new ExtensionAppItem(profile_, | 158 apps->push_back(new ExtensionAppItem(profile_, |
| 167 (*app)->id(), | 159 (*app)->id(), |
| 168 controller_, | 160 controller_, |
| 169 "", | 161 "", |
| 170 gfx::ImageSkia(), | 162 gfx::ImageSkia(), |
| 171 (*app)->is_platform_app())); | 163 (*app)->is_platform_app())); |
| 172 } | 164 } |
| 173 } | 165 } |
| 174 | 166 |
| 167 void AppsModelBuilder::SwitchProfile(Profile* profile) { | |
|
xiyuan
2013/09/11 05:01:49
nit: return early if profile_ == profile
calamity
2013/09/13 18:02:35
Done.
| |
| 168 profile_ = profile; | |
| 169 model_->DeleteAll(); | |
| 170 if (tracker_) | |
| 171 tracker_->RemoveObserver(this); | |
| 172 | |
| 173 tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_); | |
| 174 | |
| 175 DCHECK(model_ && model_->item_count() == 0); | |
| 176 | |
| 177 PopulateApps(); | |
| 178 UpdateHighlight(); | |
| 179 | |
| 180 // Start observing after model is built. | |
| 181 tracker_->AddObserver(this); | |
| 182 } | |
| 183 | |
| 175 void AppsModelBuilder::PopulateApps() { | 184 void AppsModelBuilder::PopulateApps() { |
| 176 ExtensionService* service = | 185 ExtensionService* service = |
| 177 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 186 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 178 if (!service) | 187 if (!service) |
| 179 return; | 188 return; |
| 180 | 189 |
| 181 Apps apps; | 190 Apps apps; |
| 182 AddApps(service->extensions(), &apps); | 191 AddApps(service->extensions(), &apps); |
| 183 AddApps(service->disabled_extensions(), &apps); | 192 AddApps(service->disabled_extensions(), &apps); |
| 184 AddApps(service->terminated_extensions(), &apps); | 193 AddApps(service->terminated_extensions(), &apps); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 324 |
| 316 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 325 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
| 317 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 326 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
| 318 GetAppAt(target_index + 1) : NULL; | 327 GetAppAt(target_index + 1) : NULL; |
| 319 GetAppAt(target_index)->Move(prev, next); | 328 GetAppAt(target_index)->Move(prev, next); |
| 320 } | 329 } |
| 321 | 330 |
| 322 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 331 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
| 323 NOTREACHED(); | 332 NOTREACHED(); |
| 324 } | 333 } |
| OLD | NEW |