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/profiles/profile.h" |
7 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 8 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
8 #include "components/arc/arc_bridge_service.h" | 9 #include "components/arc/arc_bridge_service.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "extensions/browser/app_sorting.h" | |
11 #include "extensions/browser/extension_prefs.h" | |
12 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
13 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/gfx/image/image_skia_operations.h" | |
15 | |
16 namespace { | |
17 | |
18 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { | |
19 const color_utils::HSL shift = {-1, 0, 0.6}; | |
20 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); | |
21 } | |
22 | |
23 extensions::AppSorting* GetAppSorting(content::BrowserContext* context) { | |
24 return extensions::ExtensionPrefs::Get(context)->app_sorting(); | |
25 } | |
26 | |
27 } // namespace | |
28 | 13 |
29 // static | 14 // static |
30 const char ArcAppItem::kItemType[] = "ArcAppItem"; | 15 const char ArcAppItem::kItemType[] = "ArcAppItem"; |
31 | 16 |
32 ArcAppItem::ArcAppItem( | 17 ArcAppItem::ArcAppItem( |
33 content::BrowserContext* context, | 18 Profile* profile, |
34 const app_list::AppListSyncableService::SyncItem* sync_item, | 19 const app_list::AppListSyncableService::SyncItem* sync_item, |
35 const std::string& id, | 20 const std::string& id, |
36 const std::string& name, | 21 const std::string& name, |
37 bool ready) | 22 bool ready) |
38 : app_list::AppListItem(id), | 23 : ChromeAppListItem(profile, id), |
39 context_(context), | |
40 ready_(ready) { | 24 ready_(ready) { |
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
42 | 26 |
43 arc_app_icon_.reset(new ArcAppIcon(context_, | 27 arc_app_icon_.reset(new ArcAppIcon(profile, |
44 id, | 28 id, |
45 app_list::kGridIconDimension, | 29 app_list::kGridIconDimension, |
46 this)); | 30 this)); |
47 | 31 |
48 SetName(name); | 32 SetName(name); |
49 UpdateIcon(); | 33 UpdateIcon(); |
50 | 34 UpdateFromSync(sync_item); |
51 if (sync_item && sync_item->item_ordinal.IsValid()) { | |
52 // An existing synced position exists, use that. | |
53 set_position(sync_item->item_ordinal); | |
54 } else { | |
55 // There is an ExtensionAppItem that uses extension::AppSorting to order | |
56 // its element. There is no commonly available sorting mechanism for app | |
57 // ordering so use the only one available from extension subsystem. | |
58 // Page is is the earliest non-full page. | |
59 const syncer::StringOrdinal& page = | |
60 GetAppSorting(context_)->GetNaturalAppPageOrdinal(); | |
61 // And get next available pos in this page. | |
62 const syncer::StringOrdinal& pos = | |
63 GetAppSorting(context_)->CreateNextAppLaunchOrdinal(page); | |
64 set_position(pos); | |
65 } | |
66 } | 35 } |
67 | 36 |
68 ArcAppItem::~ArcAppItem() { | 37 ArcAppItem::~ArcAppItem() { |
69 } | 38 } |
70 | 39 |
71 const char* ArcAppItem::GetItemType() const { | 40 const char* ArcAppItem::GetItemType() const { |
72 return ArcAppItem::kItemType; | 41 return ArcAppItem::kItemType; |
73 } | 42 } |
74 | 43 |
75 void ArcAppItem::Activate(int event_flags) { | 44 void ArcAppItem::Activate(int event_flags) { |
76 if (!ready()) { | 45 if (!ready()) { |
77 VLOG(2) << "Cannot launch not-ready app:" << id() << "."; | 46 VLOG(2) << "Cannot launch not-ready app:" << id() << "."; |
78 return; | 47 return; |
79 } | 48 } |
80 | 49 |
81 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); | 50 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); |
82 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id()); | 51 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id()); |
83 if (!app_info) { | 52 if (!app_info) { |
84 VLOG(2) << "Cannot launch unavailable app:" << id() << "."; | 53 VLOG(2) << "Cannot launch unavailable app:" << id() << "."; |
85 return; | 54 return; |
86 } | 55 } |
87 | 56 |
88 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | 57 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
89 if (!bridge_service || | 58 if (!bridge_service || |
90 bridge_service->state() != arc::ArcBridgeService::State::READY) { | 59 bridge_service->state() != arc::ArcBridgeService::State::READY) { |
91 VLOG(2) << "Cannot launch app: " << app_info->package | 60 VLOG(2) << "Cannot launch app: " << app_info->package |
(...skipping 22 matching lines...) Expand all Loading... |
114 gfx::ImageSkia icon = arc_app_icon_->image_skia(); | 83 gfx::ImageSkia icon = arc_app_icon_->image_skia(); |
115 if (!ready_) | 84 if (!ready_) |
116 icon = CreateDisabledIcon(icon); | 85 icon = CreateDisabledIcon(icon); |
117 | 86 |
118 SetIcon(icon); | 87 SetIcon(icon); |
119 } | 88 } |
120 | 89 |
121 void ArcAppItem::OnIconUpdated() { | 90 void ArcAppItem::OnIconUpdated() { |
122 UpdateIcon(); | 91 UpdateIcon(); |
123 } | 92 } |
OLD | NEW |