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_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/install_tracker.h" | 14 #include "chrome/browser/extensions/install_tracker.h" |
15 #include "chrome/browser/extensions/install_tracker_factory.h" | 15 #include "chrome/browser/extensions/install_tracker_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/app_list/extension_app_item.h" | 17 #include "chrome/browser/ui/app_list/extension_app_item.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
21 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
22 | 24 |
23 using extensions::Extension; | 25 using extensions::Extension; |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) { | 29 bool AppPrecedes(const ExtensionAppItem* app1, const ExtensionAppItem* app2) { |
28 const syncer::StringOrdinal& page1 = app1->GetPageOrdinal(); | 30 const syncer::StringOrdinal& page1 = app1->GetPageOrdinal(); |
29 const syncer::StringOrdinal& page2 = app2->GetPageOrdinal(); | 31 const syncer::StringOrdinal& page2 = app2->GetPageOrdinal(); |
30 if (page1.LessThan(page2)) | 32 if (page1.LessThan(page2)) |
31 return true; | 33 return true; |
32 | 34 |
33 if (page1.Equals(page2)) | 35 if (page1.Equals(page2)) |
34 return app1->GetAppLaunchOrdinal().LessThan(app2->GetAppLaunchOrdinal()); | 36 return app1->GetAppLaunchOrdinal().LessThan(app2->GetAppLaunchOrdinal()); |
35 | 37 |
36 return false; | 38 return false; |
37 } | 39 } |
38 | 40 |
| 41 bool ShouldDisplayInAppLauncher(Profile* profile, |
| 42 scoped_refptr<const Extension> app) { |
| 43 // If it's the web store, check the policy. |
| 44 bool blocked_by_policy = |
| 45 (app->id() == extension_misc::kWebStoreAppId || |
| 46 app->id() == extension_misc::kEnterpriseWebStoreAppId) && |
| 47 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); |
| 48 return app->ShouldDisplayInAppLauncher() && !blocked_by_policy; |
| 49 } |
| 50 |
39 } // namespace | 51 } // namespace |
40 | 52 |
41 AppsModelBuilder::AppsModelBuilder(Profile* profile, | 53 AppsModelBuilder::AppsModelBuilder(Profile* profile, |
42 app_list::AppListModel::Apps* model, | 54 app_list::AppListModel::Apps* model, |
43 AppListControllerDelegate* controller) | 55 AppListControllerDelegate* controller) |
44 : profile_(profile), | 56 : profile_(profile), |
45 controller_(controller), | 57 controller_(controller), |
46 model_(model), | 58 model_(model), |
47 ignore_changes_(false) { | 59 ignore_changes_(false) { |
48 extensions::InstallTracker* tracker = | 60 extensions::InstallTracker* tracker = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void AppsModelBuilder::OnInstallFailure(const std::string& extension_id) { | 122 void AppsModelBuilder::OnInstallFailure(const std::string& extension_id) { |
111 int i = FindApp(extension_id); | 123 int i = FindApp(extension_id); |
112 if (i == -1) | 124 if (i == -1) |
113 return; | 125 return; |
114 model_->DeleteAt(i); | 126 model_->DeleteAt(i); |
115 } | 127 } |
116 | 128 |
117 void AppsModelBuilder::AddApps(const ExtensionSet* extensions, Apps* apps) { | 129 void AppsModelBuilder::AddApps(const ExtensionSet* extensions, Apps* apps) { |
118 for (ExtensionSet::const_iterator app = extensions->begin(); | 130 for (ExtensionSet::const_iterator app = extensions->begin(); |
119 app != extensions->end(); ++app) { | 131 app != extensions->end(); ++app) { |
120 if ((*app)->ShouldDisplayInAppLauncher()) | 132 if (ShouldDisplayInAppLauncher(profile_, *app)) |
121 apps->push_back(new ExtensionAppItem(profile_, | 133 apps->push_back(new ExtensionAppItem(profile_, |
122 (*app)->id(), | 134 (*app)->id(), |
123 controller_, | 135 controller_, |
124 "", | 136 "", |
125 gfx::ImageSkia())); | 137 gfx::ImageSkia())); |
126 } | 138 } |
127 } | 139 } |
128 | 140 |
129 void AppsModelBuilder::PopulateApps() { | 141 void AppsModelBuilder::PopulateApps() { |
130 ExtensionService* service = | 142 ExtensionService* service = |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 297 |
286 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 298 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
287 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 299 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
288 GetAppAt(target_index + 1) : NULL; | 300 GetAppAt(target_index + 1) : NULL; |
289 GetAppAt(target_index)->Move(prev, next); | 301 GetAppAt(target_index)->Move(prev, next); |
290 } | 302 } |
291 | 303 |
292 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 304 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
293 NOTREACHED(); | 305 NOTREACHED(); |
294 } | 306 } |
OLD | NEW |