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/extensions/extension_ui_util.h" | 13 #include "chrome/browser/extensions/extension_ui_util.h" |
14 #include "chrome/browser/extensions/install_tracker.h" | 14 #include "chrome/browser/extensions/install_tracker.h" |
15 #include "chrome/browser/extensions/install_tracker_factory.h" | 15 #include "chrome/browser/extensions/install_tracker_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
18 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 18 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
19 #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" |
20 #include "chrome/browser/ui/app_list/extension_app_item.h" | 20 #include "chrome/browser/ui/app_list/extension_app_item.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" |
22 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
25 #include "extensions/browser/extensions_browser_client.h" | 26 #include "extensions/browser/extensions_browser_client.h" |
26 #include "extensions/browser/pref_names.h" | 27 #include "extensions/browser/pref_names.h" |
27 #include "extensions/common/constants.h" | 28 #include "extensions/common/constants.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 #include "ui/gfx/image/image_skia_operations.h" | 32 #include "ui/gfx/image/image_skia_operations.h" |
(...skipping 17 matching lines...) Expand all Loading... |
49 if (!service_) | 50 if (!service_) |
50 model_->top_level_item_list()->RemoveObserver(this); | 51 model_->top_level_item_list()->RemoveObserver(this); |
51 } | 52 } |
52 | 53 |
53 void ExtensionAppModelBuilder::InitializeWithService( | 54 void ExtensionAppModelBuilder::InitializeWithService( |
54 app_list::AppListSyncableService* service) { | 55 app_list::AppListSyncableService* service) { |
55 DCHECK(!service_ && !profile_); | 56 DCHECK(!service_ && !profile_); |
56 model_ = service->model(); | 57 model_ = service->model(); |
57 service_ = service; | 58 service_ = service; |
58 profile_ = service->profile(); | 59 profile_ = service->profile(); |
59 InitializePrefChangeRegistrar(); | 60 InitializePrefChangeRegistrars(); |
60 | 61 |
61 BuildModel(); | 62 BuildModel(); |
62 } | 63 } |
63 | 64 |
64 void ExtensionAppModelBuilder::InitializeWithProfile( | 65 void ExtensionAppModelBuilder::InitializeWithProfile( |
65 Profile* profile, | 66 Profile* profile, |
66 app_list::AppListModel* model) { | 67 app_list::AppListModel* model) { |
67 DCHECK(!service_ && !profile_); | 68 DCHECK(!service_ && !profile_); |
68 model_ = model; | 69 model_ = model; |
69 model_->top_level_item_list()->AddObserver(this); | 70 model_->top_level_item_list()->AddObserver(this); |
70 profile_ = profile; | 71 profile_ = profile; |
71 InitializePrefChangeRegistrar(); | 72 InitializePrefChangeRegistrars(); |
72 | 73 |
73 BuildModel(); | 74 BuildModel(); |
74 } | 75 } |
75 | 76 |
76 void ExtensionAppModelBuilder::InitializePrefChangeRegistrar() { | 77 void ExtensionAppModelBuilder::InitializePrefChangeRegistrars() { |
| 78 profile_pref_change_registrar_.Init(profile_->GetPrefs()); |
| 79 profile_pref_change_registrar_.Add( |
| 80 prefs::kHideWebStoreIcon, |
| 81 base::Bind(&ExtensionAppModelBuilder::OnProfilePreferenceChanged, |
| 82 base::Unretained(this))); |
| 83 |
77 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 84 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
78 switches::kEnableStreamlinedHostedApps)) | 85 switches::kEnableStreamlinedHostedApps)) |
79 return; | 86 return; |
80 | 87 |
81 // TODO(calamity): analyze the performance impact of doing this every | 88 // TODO(calamity): analyze the performance impact of doing this every |
82 // extension pref change. | 89 // extension pref change. |
83 extensions::ExtensionsBrowserClient* client = | 90 extensions::ExtensionsBrowserClient* client = |
84 extensions::ExtensionsBrowserClient::Get(); | 91 extensions::ExtensionsBrowserClient::Get(); |
85 extension_pref_change_registrar_.Init( | 92 extension_pref_change_registrar_.Init( |
86 client->GetPrefServiceForContext(profile_)); | 93 client->GetPrefServiceForContext(profile_)); |
87 extension_pref_change_registrar_.Add( | 94 extension_pref_change_registrar_.Add( |
88 extensions::pref_names::kExtensions, | 95 extensions::pref_names::kExtensions, |
89 base::Bind(&ExtensionAppModelBuilder::OnExtensionPreferenceChanged, | 96 base::Bind(&ExtensionAppModelBuilder::OnExtensionPreferenceChanged, |
90 base::Unretained(this))); | 97 base::Unretained(this))); |
91 } | 98 } |
92 | 99 |
| 100 void ExtensionAppModelBuilder::OnProfilePreferenceChanged() { |
| 101 extensions::ExtensionSet extensions; |
| 102 controller_->GetApps(profile_, &extensions); |
| 103 |
| 104 for (extensions::ExtensionSet::const_iterator app = extensions.begin(); |
| 105 app != extensions.end(); ++app) { |
| 106 bool should_display = |
| 107 extensions::ui_util::ShouldDisplayInAppLauncher(*app, profile_); |
| 108 bool does_display = GetExtensionAppItem((*app)->id()) != NULL; |
| 109 |
| 110 if (should_display == does_display) |
| 111 continue; |
| 112 |
| 113 if (should_display) { |
| 114 InsertApp(CreateAppItem((*app)->id(), |
| 115 "", |
| 116 gfx::ImageSkia(), |
| 117 (*app)->is_platform_app())); |
| 118 } else { |
| 119 if (service_) |
| 120 service_->RemoveItem((*app)->id()); |
| 121 else |
| 122 model_->DeleteItem((*app)->id()); |
| 123 } |
| 124 } |
| 125 } |
| 126 |
93 void ExtensionAppModelBuilder::OnExtensionPreferenceChanged() { | 127 void ExtensionAppModelBuilder::OnExtensionPreferenceChanged() { |
94 model_->NotifyExtensionPreferenceChanged(); | 128 model_->NotifyExtensionPreferenceChanged(); |
95 } | 129 } |
96 | 130 |
97 void ExtensionAppModelBuilder::OnBeginExtensionInstall( | 131 void ExtensionAppModelBuilder::OnBeginExtensionInstall( |
98 const ExtensionInstallParams& params) { | 132 const ExtensionInstallParams& params) { |
99 if (!params.is_app || params.is_ephemeral) | 133 if (!params.is_app || params.is_ephemeral) |
100 return; | 134 return; |
101 | 135 |
102 DVLOG(2) << service_ << ": OnBeginExtensionInstall: " | 136 DVLOG(2) << service_ << ": OnBeginExtensionInstall: " |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 app_list::AppListItem* item = item_list->item_at(idx + 1); | 361 app_list::AppListItem* item = item_list->item_at(idx + 1); |
328 if (item->GetItemType() == ExtensionAppItem::kItemType) { | 362 if (item->GetItemType() == ExtensionAppItem::kItemType) { |
329 next = static_cast<ExtensionAppItem*>(item); | 363 next = static_cast<ExtensionAppItem*>(item); |
330 break; | 364 break; |
331 } | 365 } |
332 } | 366 } |
333 // item->Move will call set_position, overriding the item's position. | 367 // item->Move will call set_position, overriding the item's position. |
334 if (prev || next) | 368 if (prev || next) |
335 static_cast<ExtensionAppItem*>(item)->Move(prev, next); | 369 static_cast<ExtensionAppItem*>(item)->Move(prev, next); |
336 } | 370 } |
OLD | NEW |