| 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" |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GetAppAt(index)->UpdateIcon(); | 119 GetAppAt(index)->UpdateIcon(); |
| 129 } | 120 } |
| 130 | 121 |
| 131 void AppsModelBuilder::OnExtensionUninstalled(const Extension* extension) { | 122 void AppsModelBuilder::OnExtensionUninstalled(const Extension* extension) { |
| 132 int index = FindApp(extension->id()); | 123 int index = FindApp(extension->id()); |
| 133 if (index < 0) | 124 if (index < 0) |
| 134 return; | 125 return; |
| 135 model_->DeleteAt(index); | 126 model_->DeleteAt(index); |
| 136 } | 127 } |
| 137 | 128 |
| 138 void AppsModelBuilder::OnAppsReordered() { | 129 void AppsModelBuilder::OnAppListReordered() { |
| 139 ResortApps(); | 130 ResortApps(); |
| 140 } | 131 } |
| 141 | 132 |
| 142 void AppsModelBuilder::OnAppInstalledToAppList( | 133 void AppsModelBuilder::OnAppInstalledToAppList( |
| 143 const std::string& extension_id) { | 134 const std::string& extension_id) { |
| 144 SetHighlightedApp(extension_id); | 135 SetHighlightedApp(extension_id); |
| 145 } | 136 } |
| 146 | 137 |
| 147 void AppsModelBuilder::OnShutdown() { | 138 void AppsModelBuilder::OnShutdown() { |
| 148 if (tracker_) { | 139 if (tracker_) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return; | 182 return; |
| 192 | 183 |
| 193 Apps apps; | 184 Apps apps; |
| 194 AddApps(service->extensions(), &apps); | 185 AddApps(service->extensions(), &apps); |
| 195 AddApps(service->disabled_extensions(), &apps); | 186 AddApps(service->disabled_extensions(), &apps); |
| 196 AddApps(service->terminated_extensions(), &apps); | 187 AddApps(service->terminated_extensions(), &apps); |
| 197 | 188 |
| 198 if (apps.empty()) | 189 if (apps.empty()) |
| 199 return; | 190 return; |
| 200 | 191 |
| 201 service->extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); | 192 service->extension_prefs()->app_list_extension_sorting()-> |
| 193 FixSyncCollisions(); |
| 202 std::sort(apps.begin(), apps.end(), &AppPrecedes); | 194 std::sort(apps.begin(), apps.end(), &AppPrecedes); |
| 203 | 195 |
| 204 for (size_t i = 0; i < apps.size(); ++i) | 196 for (size_t i = 0; i < apps.size(); ++i) |
| 205 model_->Add(apps[i]); | 197 model_->Add(apps[i]); |
| 206 } | 198 } |
| 207 | 199 |
| 208 void AppsModelBuilder::ResortApps() { | 200 void AppsModelBuilder::ResortApps() { |
| 209 // Scan app items in |model_| and put the apps that do not have valid ordinals | 201 // Scan app items in |model_| and put the apps that do not have valid ordinals |
| 210 // into |invalid_ordinal_apps|. This is needed to handle uninstalling a | 202 // into |invalid_ordinal_apps|. This is needed to handle uninstalling a |
| 211 // terminated app case, where there is no unload notification and uninstall | 203 // terminated app case, where there is no unload notification and uninstall |
| 212 // notification comes in after the app's ordinals are cleared. | 204 // notification comes in after the app's ordinals are cleared. |
| 213 // See http://crbug.com/256749. | 205 // See http://crbug.com/256749. |
| 214 Apps apps; | 206 Apps apps; |
| 215 Apps invalid_ordinal_apps; | 207 Apps invalid_ordinal_apps; |
| 216 for (size_t i = 0; i < model_->item_count(); ++i) { | 208 for (size_t i = 0; i < model_->item_count(); ++i) { |
| 217 ExtensionAppItem* app = GetAppAt(i); | 209 ExtensionAppItem* app = GetAppAt(i); |
| 218 if (app->GetPageOrdinal().IsValid() && app->GetAppLaunchOrdinal().IsValid()) | 210 if (app->ExistsInSorting()) |
| 219 apps.push_back(app); | 211 apps.push_back(app); |
| 220 else | 212 else |
| 221 invalid_ordinal_apps.push_back(app); | 213 invalid_ordinal_apps.push_back(app); |
| 222 } | 214 } |
| 223 | 215 |
| 224 std::sort(apps.begin(), apps.end(), &AppPrecedes); | 216 std::sort(apps.begin(), apps.end(), &AppPrecedes); |
| 225 apps.insert( | 217 apps.insert( |
| 226 apps.end(), invalid_ordinal_apps.begin(), invalid_ordinal_apps.end()); | 218 apps.end(), invalid_ordinal_apps.begin(), invalid_ordinal_apps.end()); |
| 227 | 219 |
| 228 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 220 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 319 |
| 328 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 320 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
| 329 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 321 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
| 330 GetAppAt(target_index + 1) : NULL; | 322 GetAppAt(target_index + 1) : NULL; |
| 331 GetAppAt(target_index)->Move(prev, next); | 323 GetAppAt(target_index)->Move(prev, next); |
| 332 } | 324 } |
| 333 | 325 |
| 334 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 326 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
| 335 NOTREACHED(); | 327 NOTREACHED(); |
| 336 } | 328 } |
| OLD | NEW |