Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_item.cc

Issue 1507873006: Implement base class for app_list items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restor UpdateFromOrdering Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/app_sorting.h"
11 #include "extensions/browser/extension_prefs.h"
12 #include "ui/app_list/app_list_constants.h" 12 #include "ui/app_list/app_list_constants.h"
13 #include "ui/gfx/color_utils.h" 13 #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 14
29 // static 15 // static
30 const char ArcAppItem::kItemType[] = "ArcAppItem"; 16 const char ArcAppItem::kItemType[] = "ArcAppItem";
31 17
32 ArcAppItem::ArcAppItem( 18 ArcAppItem::ArcAppItem(
33 content::BrowserContext* context, 19 Profile* profile,
34 const app_list::AppListSyncableService::SyncItem* sync_item, 20 const app_list::AppListSyncableService::SyncItem* sync_item,
35 const std::string& id, 21 const std::string& id,
36 const std::string& name, 22 const std::string& name,
37 bool ready) 23 bool ready)
38 : app_list::AppListItem(id), 24 : ChromeAppListItem(profile, id),
39 context_(context),
40 ready_(ready) { 25 ready_(ready) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
42 27
43 arc_app_icon_.reset(new ArcAppIcon(context_, 28 arc_app_icon_.reset(new ArcAppIcon(profile,
44 id, 29 id,
45 app_list::kGridIconDimension, 30 app_list::kGridIconDimension,
46 this)); 31 this));
47 32
48 SetName(name); 33 SetName(name);
49 UpdateIcon(); 34 UpdateIcon();
50 35 if (sync_item && sync_item->item_ordinal.IsValid())
51 if (sync_item && sync_item->item_ordinal.IsValid()) { 36 UpdateFromSync(sync_item);
52 // An existing synced position exists, use that. 37 else
53 set_position(sync_item->item_ordinal); 38 UpdatePositionFromOrdering();
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 } 39 }
67 40
68 ArcAppItem::~ArcAppItem() { 41 ArcAppItem::~ArcAppItem() {
69 } 42 }
70 43
71 const char* ArcAppItem::GetItemType() const { 44 const char* ArcAppItem::GetItemType() const {
72 return ArcAppItem::kItemType; 45 return ArcAppItem::kItemType;
73 } 46 }
74 47
75 void ArcAppItem::Activate(int event_flags) { 48 void ArcAppItem::Activate(int event_flags) {
76 if (!ready()) { 49 if (!ready()) {
77 VLOG(2) << "Cannot launch not-ready app:" << id() << "."; 50 VLOG(2) << "Cannot launch not-ready app:" << id() << ".";
78 return; 51 return;
79 } 52 }
80 53
81 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); 54 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
82 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id()); 55 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id());
83 if (!app_info) { 56 if (!app_info) {
84 VLOG(2) << "Cannot launch unavailable app:" << id() << "."; 57 VLOG(2) << "Cannot launch unavailable app:" << id() << ".";
85 return; 58 return;
86 } 59 }
87 60
88 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); 61 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
89 if (!bridge_service || 62 if (!bridge_service ||
90 bridge_service->state() != arc::ArcBridgeService::State::READY) { 63 bridge_service->state() != arc::ArcBridgeService::State::READY) {
91 VLOG(2) << "Cannot launch app: " << app_info->package 64 VLOG(2) << "Cannot launch app: " << app_info->package
(...skipping 19 matching lines...) Expand all
111 void ArcAppItem::UpdateIcon() { 84 void ArcAppItem::UpdateIcon() {
112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
113 86
114 gfx::ImageSkia icon = arc_app_icon_->image_skia(); 87 gfx::ImageSkia icon = arc_app_icon_->image_skia();
115 if (!ready_) 88 if (!ready_)
116 icon = CreateDisabledIcon(icon); 89 icon = CreateDisabledIcon(icon);
117 90
118 SetIcon(icon); 91 SetIcon(icon);
119 } 92 }
120 93
94 void ArcAppItem::UpdatePositionFromOrdering() {
95 // There is an ExtensionAppItem that uses extension::AppSorting to order
96 // its element. There is no commonly available sorting mechanism for app
97 // ordering so use the only one available from extension subsystem.
98 // Page is is the earliest non-full page.
xiyuan 2015/12/10 16:57:47 nit: remove one "is".
khmel1 2015/12/11 06:05:48 Done.
99 const syncer::StringOrdinal& page =
100 GetAppSorting()->GetNaturalAppPageOrdinal();
101 // And get next available pos in this page.
102 const syncer::StringOrdinal& pos =
103 GetAppSorting()->CreateNextAppLaunchOrdinal(page);
104 set_position(pos);
105 }
106
121 void ArcAppItem::OnIconUpdated() { 107 void ArcAppItem::OnIconUpdated() {
122 UpdateIcon(); 108 UpdateIcon();
123 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698