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/extension_app_model_builder.h" | 5 #include "chrome/browser/ui/app_list/extension_app_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/install_tracker.h" | 13 #include "chrome/browser/extensions/install_tracker.h" |
14 #include "chrome/browser/extensions/install_tracker_factory.h" | 14 #include "chrome/browser/extensions/install_tracker_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.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/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
19 #include "chrome/common/extensions/extension_set.h" | |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
22 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/extension_set.h" |
23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
24 | 24 |
25 using extensions::Extension; | 25 using extensions::Extension; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 bool ShouldDisplayInAppLauncher(Profile* profile, | 29 bool ShouldDisplayInAppLauncher(Profile* profile, |
30 scoped_refptr<const Extension> app) { | 30 scoped_refptr<const Extension> app) { |
31 // If it's the web store, check the policy. | 31 // If it's the web store, check the policy. |
32 bool blocked_by_policy = | 32 bool blocked_by_policy = |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SetHighlightedApp(extension_id); | 128 SetHighlightedApp(extension_id); |
129 } | 129 } |
130 | 130 |
131 void ExtensionAppModelBuilder::OnShutdown() { | 131 void ExtensionAppModelBuilder::OnShutdown() { |
132 if (tracker_) { | 132 if (tracker_) { |
133 tracker_->RemoveObserver(this); | 133 tracker_->RemoveObserver(this); |
134 tracker_ = NULL; | 134 tracker_ = NULL; |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 void ExtensionAppModelBuilder::AddApps(const ExtensionSet* extensions, | 138 void ExtensionAppModelBuilder::AddApps( |
139 ExtensionAppList* apps) { | 139 const extensions::ExtensionSet* extensions, |
140 for (ExtensionSet::const_iterator app = extensions->begin(); | 140 ExtensionAppList* apps) { |
| 141 for (extensions::ExtensionSet::const_iterator app = extensions->begin(); |
141 app != extensions->end(); ++app) { | 142 app != extensions->end(); ++app) { |
142 if (ShouldDisplayInAppLauncher(profile_, *app)) | 143 if (ShouldDisplayInAppLauncher(profile_, *app)) |
143 apps->push_back(new ExtensionAppItem(profile_, | 144 apps->push_back(new ExtensionAppItem(profile_, |
144 (*app)->id(), | 145 (*app)->id(), |
145 "", | 146 "", |
146 gfx::ImageSkia(), | 147 gfx::ImageSkia(), |
147 (*app)->is_platform_app())); | 148 (*app)->is_platform_app())); |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 void ExtensionAppModelBuilder::BuildModel() { | 152 void ExtensionAppModelBuilder::BuildModel() { |
152 // Delete any extension apps. | 153 // Delete any extension apps. |
153 model_->item_list()->DeleteItemsByType(ExtensionAppItem::kAppType); | 154 model_->item_list()->DeleteItemsByType(ExtensionAppItem::kAppType); |
154 | 155 |
155 if (tracker_) | 156 if (tracker_) |
156 tracker_->RemoveObserver(this); | 157 tracker_->RemoveObserver(this); |
157 | 158 |
158 tracker_ = controller_->GetInstallTrackerFor(profile_); | 159 tracker_ = controller_->GetInstallTrackerFor(profile_); |
159 | 160 |
160 PopulateApps(); | 161 PopulateApps(); |
161 UpdateHighlight(); | 162 UpdateHighlight(); |
162 | 163 |
163 // Start observing after model is built. | 164 // Start observing after model is built. |
164 if (tracker_) | 165 if (tracker_) |
165 tracker_->AddObserver(this); | 166 tracker_->AddObserver(this); |
166 } | 167 } |
167 | 168 |
168 void ExtensionAppModelBuilder::PopulateApps() { | 169 void ExtensionAppModelBuilder::PopulateApps() { |
169 ExtensionSet extensions; | 170 extensions::ExtensionSet extensions; |
170 controller_->GetApps(profile_, &extensions); | 171 controller_->GetApps(profile_, &extensions); |
171 ExtensionAppList apps; | 172 ExtensionAppList apps; |
172 AddApps(&extensions, &apps); | 173 AddApps(&extensions, &apps); |
173 | 174 |
174 if (apps.empty()) | 175 if (apps.empty()) |
175 return; | 176 return; |
176 | 177 |
177 for (size_t i = 0; i < apps.size(); ++i) | 178 for (size_t i = 0; i < apps.size(); ++i) |
178 InsertApp(apps[i]); | 179 InsertApp(apps[i]); |
179 } | 180 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 app_list::AppListItemModel* item = item_list->item_at(idx + 1); | 242 app_list::AppListItemModel* item = item_list->item_at(idx + 1); |
242 if (item->GetAppType() == ExtensionAppItem::kAppType) { | 243 if (item->GetAppType() == ExtensionAppItem::kAppType) { |
243 next = static_cast<ExtensionAppItem*>(item); | 244 next = static_cast<ExtensionAppItem*>(item); |
244 break; | 245 break; |
245 } | 246 } |
246 } | 247 } |
247 // item->Move will call set_position, overriding the item's position. | 248 // item->Move will call set_position, overriding the item's position. |
248 if (prev || next) | 249 if (prev || next) |
249 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 250 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
250 } | 251 } |
OLD | NEW |