| 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_(NULL) { |
| 42 } | 42 } |
| 43 | 43 |
| 44 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { | 44 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() { |
| 45 OnShutdown(); | 45 OnShutdown(); |
| 46 OnShutdown(extension_registry_); |
| 46 if (!service_) | 47 if (!service_) |
| 47 model_->top_level_item_list()->RemoveObserver(this); | 48 model_->top_level_item_list()->RemoveObserver(this); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ExtensionAppModelBuilder::InitializeWithService( | 51 void ExtensionAppModelBuilder::InitializeWithService( |
| 51 app_list::AppListSyncableService* service) { | 52 app_list::AppListSyncableService* service) { |
| 52 DCHECK(!service_ && !profile_); | 53 DCHECK(!service_ && !profile_); |
| 53 model_ = service->model(); | 54 model_ = service->model(); |
| 54 service_ = service; | 55 service_ = service; |
| 55 profile_ = service->profile(); | 56 profile_ = service->profile(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (!item) | 118 if (!item) |
| 118 return; | 119 return; |
| 119 item->SetPercentDownloaded(percent_downloaded); | 120 item->SetPercentDownloaded(percent_downloaded); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void ExtensionAppModelBuilder::OnInstallFailure( | 123 void ExtensionAppModelBuilder::OnInstallFailure( |
| 123 const std::string& extension_id) { | 124 const std::string& extension_id) { |
| 124 model_->DeleteItem(extension_id); | 125 model_->DeleteItem(extension_id); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void ExtensionAppModelBuilder::OnExtensionLoaded(const Extension* extension) { | 128 void ExtensionAppModelBuilder::OnExtensionLoaded( |
| 129 content::BrowserContext* browser_context, |
| 130 const extensions::Extension* extension) { |
| 128 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) | 131 if (!extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile_)) |
| 129 return; | 132 return; |
| 130 | 133 |
| 131 DVLOG(2) << service_ << ": OnExtensionLoaded: " | 134 DVLOG(2) << service_ << ": OnExtensionLoaded: " |
| 132 << extension->id().substr(0, 8); | 135 << extension->id().substr(0, 8); |
| 133 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); | 136 ExtensionAppItem* existing_item = GetExtensionAppItem(extension->id()); |
| 134 if (existing_item) { | 137 if (existing_item) { |
| 135 existing_item->Reload(); | 138 existing_item->Reload(); |
| 136 if (service_) | 139 if (service_) |
| 137 service_->UpdateItem(existing_item); | 140 service_->UpdateItem(existing_item); |
| 138 return; | 141 return; |
| 139 } | 142 } |
| 140 | 143 |
| 141 InsertApp(CreateAppItem(extension->id(), | 144 InsertApp(CreateAppItem(extension->id(), |
| 142 "", | 145 "", |
| 143 gfx::ImageSkia(), | 146 gfx::ImageSkia(), |
| 144 extension->is_platform_app())); | 147 extension->is_platform_app())); |
| 145 UpdateHighlight(); | 148 UpdateHighlight(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 void ExtensionAppModelBuilder::OnExtensionUnloaded(const Extension* extension) { | 151 void ExtensionAppModelBuilder::OnExtensionUnloaded( |
| 152 content::BrowserContext* browser_context, |
| 153 const extensions::Extension* extension, |
| 154 extensions::UnloadedExtensionInfo::Reason reason) { |
| 149 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); | 155 ExtensionAppItem* item = GetExtensionAppItem(extension->id()); |
| 150 if (!item) | 156 if (!item) |
| 151 return; | 157 return; |
| 152 item->UpdateIcon(); | 158 item->UpdateIcon(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 void ExtensionAppModelBuilder::OnExtensionUninstalled( | 161 void ExtensionAppModelBuilder::OnExtensionUninstalled( |
| 156 const Extension* extension) { | 162 content::BrowserContext* browser_context, |
| 163 const extensions::Extension* extension) { |
| 157 if (service_) { | 164 if (service_) { |
| 158 DVLOG(2) << service_ << ": OnExtensionUninstalled: " | 165 DVLOG(2) << service_ << ": OnExtensionUninstalled: " |
| 159 << extension->id().substr(0, 8); | 166 << extension->id().substr(0, 8); |
| 160 service_->RemoveItem(extension->id()); | 167 service_->RemoveItem(extension->id()); |
| 161 return; | 168 return; |
| 162 } | 169 } |
| 163 model_->DeleteItem(extension->id()); | 170 model_->DeleteItem(extension->id()); |
| 164 } | 171 } |
| 165 | 172 |
| 166 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( | 173 void ExtensionAppModelBuilder::OnDisabledExtensionUpdated( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 178 SetHighlightedApp(extension_id); | 185 SetHighlightedApp(extension_id); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void ExtensionAppModelBuilder::OnShutdown() { | 188 void ExtensionAppModelBuilder::OnShutdown() { |
| 182 if (tracker_) { | 189 if (tracker_) { |
| 183 tracker_->RemoveObserver(this); | 190 tracker_->RemoveObserver(this); |
| 184 tracker_ = NULL; | 191 tracker_ = NULL; |
| 185 } | 192 } |
| 186 } | 193 } |
| 187 | 194 |
| 195 void ExtensionAppModelBuilder::OnShutdown( |
| 196 extensions::ExtensionRegistry* registry) { |
| 197 if (!extension_registry_) |
| 198 return; |
| 199 |
| 200 DCHECK_EQ(extension_registry_, registry); |
| 201 extension_registry_->RemoveObserver(this); |
| 202 extension_registry_ = NULL; |
| 203 } |
| 204 |
| 188 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( | 205 scoped_ptr<ExtensionAppItem> ExtensionAppModelBuilder::CreateAppItem( |
| 189 const std::string& extension_id, | 206 const std::string& extension_id, |
| 190 const std::string& extension_name, | 207 const std::string& extension_name, |
| 191 const gfx::ImageSkia& installing_icon, | 208 const gfx::ImageSkia& installing_icon, |
| 192 bool is_platform_app) { | 209 bool is_platform_app) { |
| 193 const app_list::AppListSyncableService::SyncItem* sync_item = | 210 const app_list::AppListSyncableService::SyncItem* sync_item = |
| 194 service_ ? service_->GetSyncItem(extension_id) : NULL; | 211 service_ ? service_->GetSyncItem(extension_id) : NULL; |
| 195 return make_scoped_ptr(new ExtensionAppItem(profile_, | 212 return make_scoped_ptr(new ExtensionAppItem(profile_, |
| 196 sync_item, | 213 sync_item, |
| 197 extension_id, | 214 extension_id, |
| 198 extension_name, | 215 extension_name, |
| 199 installing_icon, | 216 installing_icon, |
| 200 is_platform_app)); | 217 is_platform_app)); |
| 201 } | 218 } |
| 202 | 219 |
| 203 void ExtensionAppModelBuilder::BuildModel() { | 220 void ExtensionAppModelBuilder::BuildModel() { |
| 204 DCHECK(!tracker_); | 221 DCHECK(!tracker_); |
| 205 tracker_ = controller_->GetInstallTrackerFor(profile_); | 222 tracker_ = controller_->GetInstallTrackerFor(profile_); |
| 223 extension_registry_ = extensions::ExtensionRegistry::Get(profile_); |
| 206 | 224 |
| 207 PopulateApps(); | 225 PopulateApps(); |
| 208 UpdateHighlight(); | 226 UpdateHighlight(); |
| 209 | 227 |
| 210 // Start observing after model is built. | 228 // Start observing after model is built. |
| 211 if (tracker_) | 229 if (tracker_) |
| 212 tracker_->AddObserver(this); | 230 tracker_->AddObserver(this); |
| 231 |
| 232 if (extension_registry_) |
| 233 extension_registry_->AddObserver(this); |
| 213 } | 234 } |
| 214 | 235 |
| 215 void ExtensionAppModelBuilder::PopulateApps() { | 236 void ExtensionAppModelBuilder::PopulateApps() { |
| 216 extensions::ExtensionSet extensions; | 237 extensions::ExtensionSet extensions; |
| 217 controller_->GetApps(profile_, &extensions); | 238 controller_->GetApps(profile_, &extensions); |
| 218 | 239 |
| 219 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); | 240 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); |
| 220 app != extensions.end(); ++app) { | 241 app != extensions.end(); ++app) { |
| 221 if (!extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_)) | 242 if (!extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_)) |
| 222 continue; | 243 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); | 315 app_list::AppListItem* item = item_list->item_at(idx + 1); |
| 295 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 316 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
| 296 next = static_cast<ExtensionAppItem*>(item); | 317 next = static_cast<ExtensionAppItem*>(item); |
| 297 break; | 318 break; |
| 298 } | 319 } |
| 299 } | 320 } |
| 300 // item->Move will call set_position, overriding the item's position. | 321 // item->Move will call set_position, overriding the item's position. |
| 301 if (prev || next) | 322 if (prev || next) |
| 302 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 323 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
| 303 } | 324 } |
| OLD | NEW |