 Chromium Code Reviews
 Chromium Code Reviews Issue 1413153007:
  arc-app-launcher: Minimal support for ARC app launcher.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1413153007:
  arc-app-launcher: Minimal support for ARC app launcher.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/app_list/arc_app_item.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/app_list/arc_app_prefs.h" | |
| 8 #include "components/arc/arc_bridge_service.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "ui/gfx/color_utils.h" | |
| 11 #include "ui/gfx/image/image_skia_operations.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const int kIconDimension = 48; | |
| 
xiyuan
2015/11/11 22:15:50
Should we use app_list::kGridIconDimension instead
 
khmel1
2015/11/12 08:05:29
Yes. this is much better. I used extension icon as
 | |
| 16 | |
| 17 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { | |
| 18 const color_utils::HSL shift = {-1, 0, 0.6}; | |
| 19 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 // static | |
| 25 const char ArcAppItem::kItemType[] = "ArcAppItem"; | |
| 26 | |
| 27 ArcAppItem::ArcAppItem( | |
| 28 content::BrowserContext* context, | |
| 29 const app_list::AppListSyncableService::SyncItem* sync_item, | |
| 30 const std::string& id, | |
| 31 const std::string& name, | |
| 32 bool ready) | |
| 33 : app_list::AppListItem(id), | |
| 34 context_(context), | |
| 35 ready_(ready) { | |
| 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 37 | |
| 38 icon_.reset(new ArcAppIcon(context_, id, kIconDimension, this)); | |
| 39 | |
| 40 SetName(name); | |
| 41 UpdateIcon(); | |
| 42 | |
| 43 if (sync_item && sync_item->item_ordinal.IsValid()) { | |
| 44 // An existing synced position exists, use that. | |
| 45 set_position(sync_item->item_ordinal); | |
| 46 } else { | |
| 47 // TODO(khmel): Investigate how to integrate with extensions::AppSorting | |
| 48 set_position(syncer::StringOrdinal("nq")); | |
| 
xiyuan
2015/11/11 22:15:50
Can we leave position unset instead of using a har
 
khmel1
2015/11/12 08:05:29
Done.
 | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 ArcAppItem::~ArcAppItem() { | |
| 53 } | |
| 54 | |
| 55 const char* ArcAppItem::GetItemType() const { | |
| 56 return ArcAppItem::kItemType; | |
| 57 } | |
| 58 | |
| 59 void ArcAppItem::Activate(int event_flags) { | |
| 60 DCHECK(ready_); | |
| 61 | |
| 62 ArcAppPrefs* prefs = ArcAppPrefs::Get(context_); | |
| 63 scoped_ptr<ArcAppPrefs::AppInfo> app_info = prefs->GetApp(id()); | |
| 64 DCHECK(app_info != nullptr); | |
| 
xiyuan
2015/11/11 22:15:50
nit: DCHECK_NE(app_info, nullptr)
 
khmel1
2015/11/12 08:05:29
Done. Added LOG(ERROR) below
 | |
| 65 if (!app_info) { | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 70 if (!bridge_service || | |
| 71 bridge_service->state() != arc::ArcBridgeService::State::READY) { | |
| 72 LOG(ERROR) << "Cannot launch app: " << app_info->package | |
| 73 << ". Bridge service is not ready."; | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 bridge_service->LaunchApp(app_info->package, app_info->activity); | |
| 78 } | |
| 79 | |
| 80 void ArcAppItem::SetReady(bool ready) { | |
| 81 if (ready_ == ready) { | |
| 82 return; | |
| 83 } | |
| 84 ready_ = ready; | |
| 85 UpdateIcon(); | |
| 86 } | |
| 87 | |
| 88 void ArcAppItem::SetName(const std::string& name) { | |
| 89 SetNameAndShortName(name, name); | |
| 90 } | |
| 91 | |
| 92 void ArcAppItem::UpdateIcon() { | |
| 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 94 | |
| 95 gfx::ImageSkia icon = icon_->image_skia(); | |
| 96 if (!ready_) { | |
| 97 icon = CreateDisabledIcon(icon); | |
| 98 } | |
| 99 | |
| 100 SetIcon(icon); | |
| 101 } | |
| 102 | |
| 103 void ArcAppItem::OnIconUpdated() { | |
| 
xiyuan
2015/11/11 22:15:50
ArcAppItem should observe its |icon_|. Otherwise,
 
khmel1
2015/11/12 08:05:30
Sorry, I don't understand clear you. When I create
 
xiyuan
2015/11/12 17:32:44
You are right. ArcAppItem is passed in |arc_app_ic
 | |
| 104 UpdateIcon(); | |
| 105 } | |
| OLD | NEW |