| 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/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_sorting.h" | |
| 14 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/extensions/install_tracker.h" | 14 #include "chrome/browser/extensions/install_tracker.h" |
| 16 #include "chrome/browser/extensions/install_tracker_factory.h" | 15 #include "chrome/browser/extensions/install_tracker_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/app_list/extension_app_item.h" | 17 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.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 Loading... |
| 136 model_->DeleteAt(index); | 127 model_->DeleteAt(index); |
| 137 } | 128 } |
| 138 | 129 |
| 139 void AppsModelBuilder::OnExtensionDisabled(const Extension* extension) { | 130 void AppsModelBuilder::OnExtensionDisabled(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 GetAppAt(index)->UpdateIcon(); | 134 GetAppAt(index)->UpdateIcon(); |
| 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 Loading... |
| 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_ordering()-> |
| 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 Apps apps; | 189 Apps apps; |
| 198 for (size_t i = 0; i < model_->item_count(); ++i) | 190 for (size_t i = 0; i < model_->item_count(); ++i) |
| 199 apps.push_back(GetAppAt(i)); | 191 apps.push_back(GetAppAt(i)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 297 |
| 306 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 298 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
| 307 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 299 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
| 308 GetAppAt(target_index + 1) : NULL; | 300 GetAppAt(target_index + 1) : NULL; |
| 309 GetAppAt(target_index)->Move(prev, next); | 301 GetAppAt(target_index)->Move(prev, next); |
| 310 } | 302 } |
| 311 | 303 |
| 312 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 304 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
| 313 NOTREACHED(); | 305 NOTREACHED(); |
| 314 } | 306 } |
| OLD | NEW |