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

Side by Side Diff: chrome/browser/ui/app_list/apps_model_builder.cc

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework Created 7 years, 3 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 (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
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 SwitchProfile(profile);
64 } 65 }
65 66
66 AppsModelBuilder::~AppsModelBuilder() { 67 AppsModelBuilder::~AppsModelBuilder() {
67 OnShutdown(); 68 OnShutdown();
68 model_->RemoveObserver(this); 69 model_->RemoveObserver(this);
69 } 70 }
70 71
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( 72 void AppsModelBuilder::OnBeginExtensionInstall(
82 const std::string& extension_id, 73 const std::string& extension_id,
83 const std::string& extension_name, 74 const std::string& extension_name,
84 const gfx::ImageSkia& installing_icon, 75 const gfx::ImageSkia& installing_icon,
85 bool is_app, 76 bool is_app,
86 bool is_platform_app) { 77 bool is_platform_app) {
87 if (!is_app) 78 if (!is_app)
88 return; 79 return;
89 InsertApp(new ExtensionAppItem(profile_, 80 InsertApp(new ExtensionAppItem(profile_,
90 extension_id, 81 extension_id,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (ShouldDisplayInAppLauncher(profile_, *app)) 156 if (ShouldDisplayInAppLauncher(profile_, *app))
166 apps->push_back(new ExtensionAppItem(profile_, 157 apps->push_back(new ExtensionAppItem(profile_,
167 (*app)->id(), 158 (*app)->id(),
168 controller_, 159 controller_,
169 "", 160 "",
170 gfx::ImageSkia(), 161 gfx::ImageSkia(),
171 (*app)->is_platform_app())); 162 (*app)->is_platform_app()));
172 } 163 }
173 } 164 }
174 165
166 void AppsModelBuilder::SwitchProfile(Profile* profile) {
167 profile_ = profile;
168 model_->DeleteAll();
169 if (tracker_)
170 tracker_->RemoveObserver(this);
171
172 tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_);
173
174 DCHECK(model_ && model_->item_count() == 0);
175
176 PopulateApps();
177 UpdateHighlight();
178
179 // Start observing after model is built.
180 tracker_->AddObserver(this);
181 }
182
175 void AppsModelBuilder::PopulateApps() { 183 void AppsModelBuilder::PopulateApps() {
176 ExtensionService* service = 184 ExtensionService* service =
177 extensions::ExtensionSystem::Get(profile_)->extension_service(); 185 extensions::ExtensionSystem::Get(profile_)->extension_service();
178 if (!service) 186 if (!service)
179 return; 187 return;
180 188
181 Apps apps; 189 Apps apps;
182 AddApps(service->extensions(), &apps); 190 AddApps(service->extensions(), &apps);
183 AddApps(service->disabled_extensions(), &apps); 191 AddApps(service->disabled_extensions(), &apps);
184 AddApps(service->terminated_extensions(), &apps); 192 AddApps(service->terminated_extensions(), &apps);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 323
316 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; 324 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL;
317 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? 325 ExtensionAppItem* next = target_index + 1 < model_->item_count() ?
318 GetAppAt(target_index + 1) : NULL; 326 GetAppAt(target_index + 1) : NULL;
319 GetAppAt(target_index)->Move(prev, next); 327 GetAppAt(target_index)->Move(prev, next);
320 } 328 }
321 329
322 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { 330 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) {
323 NOTREACHED(); 331 NOTREACHED();
324 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698