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

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

Issue 17038002: Separate the NTP app ordering from the app list app ordering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework + fix tests Created 7 years, 4 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"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_sorting.h"
15 #include "chrome/browser/extensions/extension_system.h" 14 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/extensions/install_tracker.h" 15 #include "chrome/browser/extensions/install_tracker.h"
17 #include "chrome/browser/extensions/install_tracker_factory.h" 16 #include "chrome/browser/extensions/install_tracker_factory.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/app_list/extension_app_item.h" 18 #include "chrome/browser/ui/app_list/extension_app_item.h"
20 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
24 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
25 24
26 using extensions::Extension; 25 using extensions::Extension;
27 26
28 namespace { 27 namespace {
29 28
30 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) { 29 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) {
31 const syncer::StringOrdinal& page1 = app1->GetPageOrdinal(); 30 return app1->Precedes(app2);
32 const syncer::StringOrdinal& page2 = app2->GetPageOrdinal();
33 if (page1.LessThan(page2))
34 return true;
35
36 if (page1.Equals(page2))
37 return app1->GetAppLaunchOrdinal().LessThan(app2->GetAppLaunchOrdinal());
38
39 return false;
40 } 31 }
41 32
42 bool ShouldDisplayInAppLauncher(Profile* profile, 33 bool ShouldDisplayInAppLauncher(Profile* profile,
43 scoped_refptr<const Extension> app) { 34 scoped_refptr<const Extension> app) {
44 // If it's the web store, check the policy. 35 // If it's the web store, check the policy.
45 bool blocked_by_policy = 36 bool blocked_by_policy =
46 (app->id() == extension_misc::kWebStoreAppId || 37 (app->id() == extension_misc::kWebStoreAppId ||
47 app->id() == extension_misc::kEnterpriseWebStoreAppId) && 38 app->id() == extension_misc::kEnterpriseWebStoreAppId) &&
48 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); 39 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon);
49 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy; 40 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 GetAppAt(index)->UpdateIcon(); 127 GetAppAt(index)->UpdateIcon();
137 } 128 }
138 129
139 void AppsModelBuilder::OnExtensionUninstalled(const Extension* extension) { 130 void AppsModelBuilder::OnExtensionUninstalled(const Extension* extension) {
140 int index = FindApp(extension->id()); 131 int index = FindApp(extension->id());
141 if (index < 0) 132 if (index < 0)
142 return; 133 return;
143 model_->DeleteAt(index); 134 model_->DeleteAt(index);
144 } 135 }
145 136
146 void AppsModelBuilder::OnAppsReordered() { 137 void AppsModelBuilder::OnAppListReordered() {
147 ResortApps(); 138 ResortApps();
148 } 139 }
149 140
150 void AppsModelBuilder::OnAppInstalledToAppList( 141 void AppsModelBuilder::OnAppInstalledToAppList(
151 const std::string& extension_id) { 142 const std::string& extension_id) {
152 SetHighlightedApp(extension_id); 143 SetHighlightedApp(extension_id);
153 } 144 }
154 145
155 void AppsModelBuilder::OnShutdown() { 146 void AppsModelBuilder::OnShutdown() {
156 if (tracker_) { 147 if (tracker_) {
(...skipping 22 matching lines...) Expand all
179 return; 170 return;
180 171
181 Apps apps; 172 Apps apps;
182 AddApps(service->extensions(), &apps); 173 AddApps(service->extensions(), &apps);
183 AddApps(service->disabled_extensions(), &apps); 174 AddApps(service->disabled_extensions(), &apps);
184 AddApps(service->terminated_extensions(), &apps); 175 AddApps(service->terminated_extensions(), &apps);
185 176
186 if (apps.empty()) 177 if (apps.empty())
187 return; 178 return;
188 179
189 service->extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); 180 service->extension_prefs()->app_list_extension_sorting()->
181 FixSyncCollisions();
190 std::sort(apps.begin(), apps.end(), &AppPrecedes); 182 std::sort(apps.begin(), apps.end(), &AppPrecedes);
191 183
192 for (size_t i = 0; i < apps.size(); ++i) 184 for (size_t i = 0; i < apps.size(); ++i)
193 model_->Add(apps[i]); 185 model_->Add(apps[i]);
194 } 186 }
195 187
196 void AppsModelBuilder::ResortApps() { 188 void AppsModelBuilder::ResortApps() {
197 // Scan app items in |model_| and put the apps that do not have valid ordinals 189 // 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 190 // into |invalid_ordinal_apps|. This is needed to handle uninstalling a
199 // terminated app case, where there is no unload notification and uninstall 191 // terminated app case, where there is no unload notification and uninstall
200 // notification comes in after the app's ordinals are cleared. 192 // notification comes in after the app's ordinals are cleared.
201 // See http://crbug.com/256749. 193 // See http://crbug.com/256749.
202 Apps apps; 194 Apps apps;
203 Apps invalid_ordinal_apps; 195 Apps invalid_ordinal_apps;
204 for (size_t i = 0; i < model_->item_count(); ++i) { 196 for (size_t i = 0; i < model_->item_count(); ++i) {
205 ExtensionAppItem* app = GetAppAt(i); 197 ExtensionAppItem* app = GetAppAt(i);
206 if (app->GetPageOrdinal().IsValid() && app->GetAppLaunchOrdinal().IsValid()) 198 if (app->ExistsInSorting())
207 apps.push_back(app); 199 apps.push_back(app);
208 else 200 else
209 invalid_ordinal_apps.push_back(app); 201 invalid_ordinal_apps.push_back(app);
210 } 202 }
211 203
212 std::sort(apps.begin(), apps.end(), &AppPrecedes); 204 std::sort(apps.begin(), apps.end(), &AppPrecedes);
213 apps.insert( 205 apps.insert(
214 apps.end(), invalid_ordinal_apps.begin(), invalid_ordinal_apps.end()); 206 apps.end(), invalid_ordinal_apps.begin(), invalid_ordinal_apps.end());
215 207
216 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 208 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 307
316 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; 308 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL;
317 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? 309 ExtensionAppItem* next = target_index + 1 < model_->item_count() ?
318 GetAppAt(target_index + 1) : NULL; 310 GetAppAt(target_index + 1) : NULL;
319 GetAppAt(target_index)->Move(prev, next); 311 GetAppAt(target_index)->Move(prev, next);
320 } 312 }
321 313
322 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { 314 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) {
323 NOTREACHED(); 315 NOTREACHED();
324 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698