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

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: remove binary changes 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;
170
171 profile_ = profile;
172 model_->DeleteAll();
173 if (tracker_)
174 tracker_->RemoveObserver(this);
175
176 tracker_ = extensions::InstallTrackerFactory::GetForProfile(profile_);
177
178 DCHECK(model_ && model_->item_count() == 0);
179
180 PopulateApps();
181 UpdateHighlight();
182
183 // Start observing after model is built.
184 tracker_->AddObserver(this);
185 }
186
175 void AppsModelBuilder::PopulateApps() { 187 void AppsModelBuilder::PopulateApps() {
176 ExtensionService* service = 188 ExtensionService* service =
177 extensions::ExtensionSystem::Get(profile_)->extension_service(); 189 extensions::ExtensionSystem::Get(profile_)->extension_service();
178 if (!service) 190 if (!service)
179 return; 191 return;
180 192
181 Apps apps; 193 Apps apps;
182 AddApps(service->extensions(), &apps); 194 AddApps(service->extensions(), &apps);
183 AddApps(service->disabled_extensions(), &apps); 195 AddApps(service->disabled_extensions(), &apps);
184 AddApps(service->terminated_extensions(), &apps); 196 AddApps(service->terminated_extensions(), &apps);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/apps_model_builder.h ('k') | chrome/browser/ui/app_list/apps_model_builder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698