| 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/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_service.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 "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
| 27 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/extensions_browser_client.h" |
| 28 #include "extensions/browser/pref_names.h" | 29 #include "extensions/browser/pref_names.h" |
| 29 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_set.h" | 31 #include "extensions/common/extension_set.h" |
| 31 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
| 32 | 33 |
| 33 using extensions::Extension; | 34 using extensions::Extension; |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 bool ShouldDisplayInAppLauncher(Profile* profile, | 38 bool ShouldDisplayInAppLauncher(Profile* profile, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 InitializePrefChangeRegistrar(); | 84 InitializePrefChangeRegistrar(); |
| 84 | 85 |
| 85 BuildModel(); | 86 BuildModel(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ExtensionAppModelBuilder::InitializePrefChangeRegistrar() { | 89 void ExtensionAppModelBuilder::InitializePrefChangeRegistrar() { |
| 89 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 90 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 90 switches::kEnableStreamlinedHostedApps)) | 91 switches::kEnableStreamlinedHostedApps)) |
| 91 return; | 92 return; |
| 92 | 93 |
| 93 const ExtensionService* extension_service = | 94 extensions::ExtensionsBrowserClient* client = |
| 94 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 95 extensions::ExtensionsBrowserClient::Get(); |
| 95 if (!extension_service) | |
| 96 return; | |
| 97 | |
| 98 extension_pref_change_registrar_.Init( | 96 extension_pref_change_registrar_.Init( |
| 99 extension_service->extension_prefs()->pref_service()); | 97 client->GetPrefServiceForContext(profile_)); |
| 100 extension_pref_change_registrar_.Add( | 98 extension_pref_change_registrar_.Add( |
| 101 extensions::pref_names::kExtensions, | 99 extensions::pref_names::kExtensions, |
| 102 base::Bind(&ExtensionAppModelBuilder::OnExtensionPreferenceChanged, | 100 base::Bind(&ExtensionAppModelBuilder::OnExtensionPreferenceChanged, |
| 103 base::Unretained(this))); | 101 base::Unretained(this))); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void ExtensionAppModelBuilder::OnExtensionPreferenceChanged() { | 104 void ExtensionAppModelBuilder::OnExtensionPreferenceChanged() { |
| 107 // TODO(calamity): analyze the performance impact of doing this every | 105 // TODO(calamity): analyze the performance impact of doing this every |
| 108 // extension pref change. | 106 // extension pref change. |
| 109 app_list::AppListItemList* item_list = model_->item_list(); | 107 app_list::AppListItemList* item_list = model_->item_list(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 app_list::AppListItem* item = item_list->item_at(idx + 1); | 311 app_list::AppListItem* item = item_list->item_at(idx + 1); |
| 314 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 312 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
| 315 next = static_cast<ExtensionAppItem*>(item); | 313 next = static_cast<ExtensionAppItem*>(item); |
| 316 break; | 314 break; |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 // item->Move will call set_position, overriding the item's position. | 317 // item->Move will call set_position, overriding the item's position. |
| 320 if (prev || next) | 318 if (prev || next) |
| 321 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 319 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
| 322 } | 320 } |
| OLD | NEW |