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" | |
14 #include "chrome/browser/extensions/extension_ui_util.h" | 13 #include "chrome/browser/extensions/extension_ui_util.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/app_list_controller_delegate.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 18 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 19 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
21 #include "chrome/browser/ui/app_list/extension_app_item.h" | 20 #include "chrome/browser/ui/app_list/extension_app_item.h" |
22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
23 #include "content/public/browser/notification_service.h" | |
24 #include "extensions/browser/extension_prefs.h" | 22 #include "extensions/browser/extension_prefs.h" |
23 #include "extensions/browser/extension_registry.h" | |
25 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
26 #include "extensions/browser/extensions_browser_client.h" | 25 #include "extensions/browser/extensions_browser_client.h" |
27 #include "extensions/browser/pref_names.h" | 26 #include "extensions/browser/pref_names.h" |
28 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
29 #include "extensions/common/extension_set.h" | 28 #include "extensions/common/extension_set.h" |
30 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
31 | 30 |
32 using extensions::Extension; | 31 using extensions::Extension; |
33 | 32 |
34 ExtensionAppModelBuilder::ExtensionAppModelBuilder( | 33 ExtensionAppModelBuilder::ExtensionAppModelBuilder( |
35 AppListControllerDelegate* controller) | 34 AppListControllerDelegate* controller) |
36 : service_(NULL), | 35 : service_(NULL), |
37 profile_(NULL), | 36 profile_(NULL), |
38 controller_(controller), | 37 controller_(controller), |
39 model_(NULL), | 38 model_(NULL), |
40 highlighted_app_pending_(false), | 39 highlighted_app_pending_(false), |
41 tracker_(NULL) { | 40 tracker_(NULL), |
41 extension_registry_observer_(this) { | |
42 } | 42 } |
43 | 43 |
44 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { | 44 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { |
45 OnShutdown(); | 45 OnShutdown(); |
46 if (!service_) | 46 if (!service_) |
47 model_->top_level_item_list()->RemoveObserver(this); | 47 model_->top_level_item_list()->RemoveObserver(this); |
48 } | 48 } |
49 | 49 |
50 void ExtensionAppModelBuilder::InitializeWithService( | 50 void ExtensionAppModelBuilder::InitializeWithService( |
51 app_list::AppListSyncableService* service) { | 51 app_list::AppListSyncableService* service) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 if (!item) | 117 if (!item) |
118 return; | 118 return; |
119 item->SetPercentDownloaded(percent_downloaded); | 119 item->SetPercentDownloaded(percent_downloaded); |
120 } | 120 } |
121 | 121 |
122 void ExtensionAppModelBuilder::OnInstallFailure( | 122 void ExtensionAppModelBuilder::OnInstallFailure( |
123 const std::string& extension_id) { | 123 const std::string& extension_id) { |
124 model_->DeleteItem(extension_id); | 124 model_->DeleteItem(extension_id); |
125 } | 125 } |
126 | 126 |
127 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { | 127 void ExtensionAppModelBuilder::OnExtensionLoaded( |
128 content::BrowserContext* browser_context, | |
129 const extensions::Extension* extension) { | |
128 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | 130 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
129 return; | 131 return; |
130 | 132 |
131 DVLOG(2) << service_ << ": OnExtensionLoaded: " | 133 DVLOG(2) << service_ << ": OnExtensionLoaded: " |
132 << extension->id().substr(0, 8); | 134 << extension->id().substr(0, 8); |
133 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 135 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
134 if (existing_item) { | 136 if (existing_item) { |
135 existing_item->Reload(); | 137 existing_item->Reload(); |
136 if (service_) | 138 if (service_) |
137 service_->UpdateItem(existing_item); | 139 service_->UpdateItem(existing_item); |
138 return; | 140 return; |
139 } | 141 } |
140 | 142 |
141 InsertApp(CreateAppItem(extension->id(), | 143 InsertApp(CreateAppItem(extension->id(), |
142 "", | 144 "", |
143 gfx::ImageSkia(), | 145 gfx::ImageSkia(), |
144 extension->is_platform_app())); | 146 extension->is_platform_app())); |
145 UpdateHighlight(); | 147 UpdateHighlight(); |
146 } | 148 } |
147 | 149 |
148 void ExtensionAppModelBuilder::OnExtensionUnloaded(const Extension* extension) { | 150 void ExtensionAppModelBuilder::OnExtensionUnloaded( |
151 content::BrowserContext* browser_context, | |
152 const extensions::Extension* extension, | |
153 extensions::UnloadedExtensionInfo::Reason reason) { | |
149 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); | 154 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); |
150 if (!item) | 155 if (!item) |
151 return; | 156 return; |
152 item->UpdateIcon(); | 157 item->UpdateIcon(); |
153 } | 158 } |
154 | 159 |
155 void ExtensionAppModelBuilder::OnExtensionUninstalled( | 160 void ExtensionAppModelBuilder::OnExtensionUninstalled( |
156 const Extension* extension) { | 161 content::BrowserContext* browser_context, |
162 const extensions::Extension* extension) { | |
157 if (service_) { | 163 if (service_) { |
158 DVLOG(2) << service_ << ": OnExtensionUninstalled: " | 164 DVLOG(2) << service_ << ": OnExtensionUninstalled: " |
159 << extension->id().substr(0, 8); | 165 << extension->id().substr(0, 8); |
160 service_->RemoveItem(extension->id()); | 166 service_->RemoveItem(extension->id()); |
161 return; | 167 return; |
162 } | 168 } |
163 model_->DeleteItem(extension->id()); | 169 model_->DeleteItem(extension->id()); |
164 } | 170 } |
165 | 171 |
166 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( | 172 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( |
167 const Extension* extension) { | 173 const Extension* extension) { |
168 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | 174 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
169 return; | 175 return; |
170 | 176 |
171 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 177 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
172 if (existing_item) | 178 if (existing_item) |
173 existing_item->Reload(); | 179 existing_item->Reload(); |
174 } | 180 } |
175 | 181 |
176 void ExtensionAppModelBuilder::OnAppInstalledToAppList( | 182 void ExtensionAppModelBuilder::OnAppInstalledToAppList( |
177 const std::string& extension_id) { | 183 const std::string& extension_id) { |
178 SetHighlightedApp(extension_id); | 184 SetHighlightedApp(extension_id); |
179 } | 185 } |
180 | 186 |
181 void ExtensionAppModelBuilder::OnShutdown() { | 187 void ExtensionAppModelBuilder::OnShutdown() { |
not at google - send to devlin
2014/05/30 23:22:17
again strictly speaking you should be listening to
limasdf
2014/06/02 11:49:04
Done. To avoid method overloading issue, I have re
not at google - send to devlin
2014/06/02 19:45:53
OnExtensionShutdown isn't really right. It's not a
| |
182 if (tracker_) { | 188 if (tracker_) { |
183 tracker_->RemoveObserver(this); | 189 tracker_->RemoveObserver(this); |
184 tracker_ = NULL; | 190 tracker_ = NULL; |
185 } | 191 } |
186 } | 192 } |
187 | 193 |
188 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( | 194 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( |
189 const std::string& extension_id, | 195 const std::string& extension_id, |
190 const std::string& extension_name, | 196 const std::string& extension_name, |
191 const gfx::ImageSkia& installing_icon, | 197 const gfx::ImageSkia& installing_icon, |
(...skipping 11 matching lines...) Expand all Loading... | |
203 void ExtensionAppModelBuilder::BuildModel() { | 209 void ExtensionAppModelBuilder::BuildModel() { |
204 DCHECK(!tracker_); | 210 DCHECK(!tracker_); |
205 tracker_ = controller_->GetInstallTrackerFor(profile_); | 211 tracker_ = controller_->GetInstallTrackerFor(profile_); |
206 | 212 |
207 PopulateApps(); | 213 PopulateApps(); |
208 UpdateHighlight(); | 214 UpdateHighlight(); |
209 | 215 |
210 // Start observing after model is built. | 216 // Start observing after model is built. |
211 if (tracker_) | 217 if (tracker_) |
212 tracker_->AddObserver(this); | 218 tracker_->AddObserver(this); |
219 | |
220 extension_registry_observer_.Add( | |
221 extensions::ExtensionRegistry::Get(profile_)); | |
213 } | 222 } |
214 | 223 |
215 void ExtensionAppModelBuilder::PopulateApps() { | 224 void ExtensionAppModelBuilder::PopulateApps() { |
216 extensions::ExtensionSet extensions; | 225 extensions::ExtensionSet extensions; |
217 controller_->GetApps(profile_, &extensions); | 226 controller_->GetApps(profile_, &extensions); |
218 | 227 |
219 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); | 228 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); |
220 app != extensions.end(); ++app) { | 229 app != extensions.end(); ++app) { |
221 if (!extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_)) | 230 if (!extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_)) |
222 continue; | 231 continue; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 app_list::AppListItem* item = item_list->item_at(idx + 1); | 303 app_list::AppListItem* item = item_list->item_at(idx + 1); |
295 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 304 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
296 next = static_cast<ExtensionAppItem*>(item); | 305 next = static_cast<ExtensionAppItem*>(item); |
297 break; | 306 break; |
298 } | 307 } |
299 } | 308 } |
300 // item->Move will call set_position, overriding the item's position. | 309 // item->Move will call set_position, overriding the item's position. |
301 if (prev || next) | 310 if (prev || next) |
302 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 311 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
303 } | 312 } |
OLD | NEW |