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

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, fix tests 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 app->id() == extension_misc::kEnterpriseWebStoreAppId) && 47 app->id() == extension_misc::kEnterpriseWebStoreAppId) &&
48 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); 48 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon);
49 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy; 49 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy;
50 } 50 }
51 51
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_(NULL),
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
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) {
168 if (profile_ == profile)
169 return;
tapted 2013/09/13 23:12:17 nit: blank line after early return
calamity 2013/09/16 19:45:26 Done.
170 profile_ = profile;
171 model_->DeleteAll();
172 if (tracker_)
173 tracker_->RemoveObserver(this);
174
175 tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_);
176
177 DCHECK(model_ && model_->item_count() == 0);
178
179 PopulateApps();
180 UpdateHighlight();
181
182 // Start observing after model is built.
183 tracker_->AddObserver(this);
184 }
185
175 void AppsModelBuilder::PopulateApps() { 186 void AppsModelBuilder::PopulateApps() {
176 ExtensionService* service = 187 ExtensionService* service =
177 extensions::ExtensionSystem::Get(profile_)->extension_service(); 188 extensions::ExtensionSystem::Get(profile_)->extension_service();
178 if (!service) 189 if (!service)
179 return; 190 return;
180 191
181 Apps apps; 192 Apps apps;
182 AddApps(service->extensions(), &apps); 193 AddApps(service->extensions(), &apps);
183 AddApps(service->disabled_extensions(), &apps); 194 AddApps(service->disabled_extensions(), &apps);
184 AddApps(service->terminated_extensions(), &apps); 195 AddApps(service->terminated_extensions(), &apps);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 326
316 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; 327 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL;
317 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? 328 ExtensionAppItem* next = target_index + 1 < model_->item_count() ?
318 GetAppAt(target_index + 1) : NULL; 329 GetAppAt(target_index + 1) : NULL;
319 GetAppAt(target_index)->Move(prev, next); 330 GetAppAt(target_index)->Move(prev, next);
320 } 331 }
321 332
322 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { 333 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) {
323 NOTREACHED(); 334 NOTREACHED();
324 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698