Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/arc/arc_app_item.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | |
| 8 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 7 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 9 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 10 #include "chrome/browser/ui/host_desktop.h" | |
| 8 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 9 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 10 #include "extensions/browser/app_sorting.h" | 13 #include "extensions/browser/app_sorting.h" |
| 11 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
| 12 #include "ui/app_list/app_list_constants.h" | 15 #include "ui/app_list/app_list_constants.h" |
| 13 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
| 14 #include "ui/gfx/image/image_skia_operations.h" | 17 #include "ui/gfx/image/image_skia_operations.h" |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 21 bool g_disable_controller_delegate = false; | |
| 22 | |
| 18 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { | 23 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { |
| 19 const color_utils::HSL shift = {-1, 0, 0.6}; | 24 const color_utils::HSL shift = {-1, 0, 0.6}; |
| 20 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); | 25 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); |
| 21 } | 26 } |
| 22 | 27 |
| 23 extensions::AppSorting* GetAppSorting(content::BrowserContext* context) { | 28 extensions::AppSorting* GetAppSorting(content::BrowserContext* context) { |
| 24 return extensions::ExtensionPrefs::Get(context)->app_sorting(); | 29 return extensions::ExtensionPrefs::Get(context)->app_sorting(); |
| 25 } | 30 } |
| 26 | 31 |
| 27 } // namespace | 32 } // namespace |
| 28 | 33 |
| 29 // static | 34 // static |
| 30 const char ArcAppItem::kItemType[] = "ArcAppItem"; | 35 const char ArcAppItem::kItemType[] = "ArcAppItem"; |
| 31 | 36 |
| 37 // static | |
| 38 void ArcAppItem::DisableContollerDelegateForTesting() { | |
|
xiyuan
2015/12/09 17:20:29
I prefer to have something like
void OverrideAppL
khmel1
2015/12/10 05:19:04
That is nice. Thanks for sharing best practices. I
| |
| 39 g_disable_controller_delegate = true; | |
| 40 } | |
| 41 | |
| 32 ArcAppItem::ArcAppItem( | 42 ArcAppItem::ArcAppItem( |
| 33 content::BrowserContext* context, | 43 content::BrowserContext* context, |
| 34 const app_list::AppListSyncableService::SyncItem* sync_item, | 44 const app_list::AppListSyncableService::SyncItem* sync_item, |
| 35 const std::string& id, | 45 const std::string& id, |
| 36 const std::string& name, | 46 const std::string& name, |
| 37 bool ready) | 47 bool ready) |
| 38 : app_list::AppListItem(id), | 48 : app_list::AppListItem(id), |
| 39 context_(context), | 49 context_(context), |
| 40 ready_(ready) { | 50 ready_(ready) { |
| 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 97 |
| 88 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 98 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 89 if (!bridge_service || | 99 if (!bridge_service || |
| 90 bridge_service->state() != arc::ArcBridgeService::State::READY) { | 100 bridge_service->state() != arc::ArcBridgeService::State::READY) { |
| 91 VLOG(2) << "Cannot launch app: " << app_info->package | 101 VLOG(2) << "Cannot launch app: " << app_info->package |
| 92 << ". Bridge service is not ready."; | 102 << ". Bridge service is not ready."; |
| 93 return; | 103 return; |
| 94 } | 104 } |
| 95 | 105 |
| 96 bridge_service->LaunchApp(app_info->package, app_info->activity); | 106 bridge_service->LaunchApp(app_info->package, app_info->activity); |
| 107 | |
| 108 if (!g_disable_controller_delegate) | |
| 109 GetController()->DismissView(); | |
| 97 } | 110 } |
| 98 | 111 |
| 99 void ArcAppItem::SetReady(bool ready) { | 112 void ArcAppItem::SetReady(bool ready) { |
| 100 if (ready_ == ready) | 113 if (ready_ == ready) |
| 101 return; | 114 return; |
| 102 | 115 |
| 103 ready_ = ready; | 116 ready_ = ready; |
| 104 UpdateIcon(); | 117 UpdateIcon(); |
| 105 } | 118 } |
| 106 | 119 |
| 107 void ArcAppItem::SetName(const std::string& name) { | 120 void ArcAppItem::SetName(const std::string& name) { |
| 108 SetNameAndShortName(name, name); | 121 SetNameAndShortName(name, name); |
| 109 } | 122 } |
| 110 | 123 |
| 111 void ArcAppItem::UpdateIcon() { | 124 void ArcAppItem::UpdateIcon() { |
| 112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 125 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 113 | 126 |
| 114 gfx::ImageSkia icon = arc_app_icon_->image_skia(); | 127 gfx::ImageSkia icon = arc_app_icon_->image_skia(); |
| 115 if (!ready_) | 128 if (!ready_) |
| 116 icon = CreateDisabledIcon(icon); | 129 icon = CreateDisabledIcon(icon); |
| 117 | 130 |
| 118 SetIcon(icon); | 131 SetIcon(icon); |
| 119 } | 132 } |
| 120 | 133 |
| 121 void ArcAppItem::OnIconUpdated() { | 134 void ArcAppItem::OnIconUpdated() { |
| 122 UpdateIcon(); | 135 UpdateIcon(); |
| 123 } | 136 } |
| 137 | |
| 138 AppListControllerDelegate* ArcAppItem::GetController() { | |
| 139 return AppListService::Get(chrome::GetActiveDesktop())-> | |
|
khmel1
2015/12/09 13:42:08
I did similar to ExtensionsAppItem. However I don'
xiyuan
2015/12/09 17:20:29
We cannot put the AppListService etc into ui/ beca
khmel1
2015/12/10 05:19:04
Thanks for confirming that adding base class is ac
| |
| 140 GetControllerDelegate(); | |
| 141 } | |
| OLD | NEW |