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/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/extensions/extension_ui_util.h" | 14 #include "chrome/browser/extensions/extension_ui_util.h" |
15 #include "chrome/browser/extensions/install_tracker.h" | 15 #include "chrome/browser/extensions/install_tracker.h" |
16 #include "chrome/browser/extensions/install_tracker_factory.h" | 16 #include "chrome/browser/extensions/install_tracker_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
21 #include "chrome/browser/ui/app_list/extension_app_item.h" | 21 #include "chrome/browser/ui/app_list/extension_app_item.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
25 #include "extensions/browser/extension_registry.h" | |
25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
26 #include "extensions/browser/extensions_browser_client.h" | 27 #include "extensions/browser/extensions_browser_client.h" |
27 #include "extensions/browser/pref_names.h" | 28 #include "extensions/browser/pref_names.h" |
28 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
29 #include "extensions/common/extension_set.h" | 30 #include "extensions/common/extension_set.h" |
30 #include "ui/gfx/image/image_skia.h" | 31 #include "ui/gfx/image/image_skia.h" |
31 | 32 |
32 using extensions::Extension; | 33 using extensions::Extension; |
33 | 34 |
34 ExtensionAppModelBuilder::ExtensionAppModelBuilder( | 35 ExtensionAppModelBuilder::ExtensionAppModelBuilder( |
35 AppListControllerDelegate* controller) | 36 AppListControllerDelegate* controller) |
36 : service_(NULL), | 37 : service_(NULL), |
37 profile_(NULL), | 38 profile_(NULL), |
38 controller_(controller), | 39 controller_(controller), |
39 model_(NULL), | 40 model_(NULL), |
40 highlighted_app_pending_(false), | 41 highlighted_app_pending_(false), |
41 tracker_(NULL) { | 42 tracker_(NULL), |
43 extension_registry_observer_(this) { | |
42 } | 44 } |
43 | 45 |
44 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { | 46 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { |
45 OnShutdown(); | 47 OnShutdown(); |
46 if (!service_) | 48 if (!service_) |
47 model_->top_level_item_list()->RemoveObserver(this); | 49 model_->top_level_item_list()->RemoveObserver(this); |
48 } | 50 } |
49 | 51 |
50 void ExtensionAppModelBuilder::InitializeWithService( | 52 void ExtensionAppModelBuilder::InitializeWithService( |
51 app_list::AppListSyncableService* service) { | 53 app_list::AppListSyncableService* service) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 if (!item) | 119 if (!item) |
118 return; | 120 return; |
119 item->SetPercentDownloaded(percent_downloaded); | 121 item->SetPercentDownloaded(percent_downloaded); |
120 } | 122 } |
121 | 123 |
122 void ExtensionAppModelBuilder::OnInstallFailure( | 124 void ExtensionAppModelBuilder::OnInstallFailure( |
123 const std::string& extension_id) { | 125 const std::string& extension_id) { |
124 model_->DeleteItem(extension_id); | 126 model_->DeleteItem(extension_id); |
125 } | 127 } |
126 | 128 |
127 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { | 129 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( |
130 const Extension* extension) { | |
128 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | 131 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
129 return; | 132 return; |
130 | 133 |
134 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | |
135 if (existing_item) | |
136 existing_item->Reload(); | |
not at google - send to devlin
2014/05/29 18:09:29
ugh annoying diff. but it looks right.
limasdf
2014/05/30 21:00:49
rearranged :)
| |
137 } | |
138 | |
139 void ExtensionAppModelBuilder::OnAppInstalledToAppList( | |
140 const std::string& extension_id) { | |
141 SetHighlightedApp(extension_id); | |
142 } | |
143 | |
144 void ExtensionAppModelBuilder::OnShutdown() { | |
145 if (tracker_) { | |
146 tracker_->RemoveObserver(this); | |
147 tracker_ = NULL; | |
148 } | |
149 } | |
150 | |
151 void ExtensionAppModelBuilder::OnExtensionLoaded( | |
152 content::BrowserContext* browser_context, | |
153 const extensions::Extension* extension) { | |
154 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | |
155 return; | |
156 | |
131 DVLOG(2) << service_ << ": OnExtensionLoaded: " | 157 DVLOG(2) << service_ << ": OnExtensionLoaded: " |
132 << extension->id().substr(0, 8); | 158 << extension->id().substr(0, 8); |
133 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 159 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
134 if (existing_item) { | 160 if (existing_item) { |
135 existing_item->Reload(); | 161 existing_item->Reload(); |
136 if (service_) | 162 if (service_) |
137 service_->UpdateItem(existing_item); | 163 service_->UpdateItem(existing_item); |
138 return; | 164 return; |
139 } | 165 } |
140 | 166 |
141 InsertApp(CreateAppItem(extension->id(), | 167 InsertApp(CreateAppItem(extension->id(), |
142 "", | 168 "", |
143 gfx::ImageSkia(), | 169 gfx::ImageSkia(), |
144 extension->is_platform_app())); | 170 extension->is_platform_app())); |
145 UpdateHighlight(); | 171 UpdateHighlight(); |
146 } | 172 } |
147 | 173 |
148 void ExtensionAppModelBuilder::OnExtensionUnloaded(const Extension* extension) { | 174 void ExtensionAppModelBuilder::OnExtensionUnloaded( |
175 content::BrowserContext* browser_context, | |
176 const extensions::Extension* extension, | |
177 extensions::UnloadedExtensionInfo::Reason reason) { | |
149 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); | 178 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); |
150 if (!item) | 179 if (!item) |
151 return; | 180 return; |
152 item->UpdateIcon(); | 181 item->UpdateIcon(); |
153 } | 182 } |
154 | 183 |
155 void ExtensionAppModelBuilder::OnExtensionUninstalled( | 184 void ExtensionAppModelBuilder::OnExtensionUninstalled( |
156 const Extension* extension) { | 185 content::BrowserContext* browser_context, |
186 const extensions::Extension* extension) { | |
157 if (service_) { | 187 if (service_) { |
158 DVLOG(2) << service_ << ": OnExtensionUninstalled: " | 188 DVLOG(2) << service_ << ": OnExtensionUninstalled: " |
159 << extension->id().substr(0, 8); | 189 << extension->id().substr(0, 8); |
160 service_->RemoveItem(extension->id()); | 190 service_->RemoveItem(extension->id()); |
161 return; | 191 return; |
162 } | 192 } |
163 model_->DeleteItem(extension->id()); | 193 model_->DeleteItem(extension->id()); |
164 } | 194 } |
165 | 195 |
166 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( | |
167 const Extension* extension) { | |
168 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | |
169 return; | |
170 | |
171 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | |
172 if (existing_item) | |
173 existing_item->Reload(); | |
174 } | |
175 | |
176 void ExtensionAppModelBuilder::OnAppInstalledToAppList( | |
177 const std::string& extension_id) { | |
178 SetHighlightedApp(extension_id); | |
179 } | |
180 | |
181 void ExtensionAppModelBuilder::OnShutdown() { | |
182 if (tracker_) { | |
183 tracker_->RemoveObserver(this); | |
184 tracker_ = NULL; | |
185 } | |
186 } | |
187 | |
188 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( | 196 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( |
189 const std::string& extension_id, | 197 const std::string& extension_id, |
190 const std::string& extension_name, | 198 const std::string& extension_name, |
191 const gfx::ImageSkia& installing_icon, | 199 const gfx::ImageSkia& installing_icon, |
192 bool is_platform_app) { | 200 bool is_platform_app) { |
193 const app_list::AppListSyncableService::SyncItem* sync_item = | 201 const app_list::AppListSyncableService::SyncItem* sync_item = |
194 service_ ? service_->GetSyncItem(extension_id) : NULL; | 202 service_ ? service_->GetSyncItem(extension_id) : NULL; |
195 return make_scoped_ptr(new ExtensionAppItem(profile_, | 203 return make_scoped_ptr(new ExtensionAppItem(profile_, |
196 sync_item, | 204 sync_item, |
197 extension_id, | 205 extension_id, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 app_list::AppListItem* item = item_list->item_at(idx + 1); | 302 app_list::AppListItem* item = item_list->item_at(idx + 1); |
295 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 303 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
296 next = static_cast<ExtensionAppItem*>(item); | 304 next = static_cast<ExtensionAppItem*>(item); |
297 break; | 305 break; |
298 } | 306 } |
299 } | 307 } |
300 // item->Move will call set_position, overriding the item's position. | 308 // item->Move will call set_position, overriding the item's position. |
301 if (prev || next) | 309 if (prev || next) |
302 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 310 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
303 } | 311 } |
OLD | NEW |