| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_icon_loader.h" | 5 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #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" |
| 9 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 9 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
| 10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return true; | 26 return true; |
| 27 return ArcAppListPrefs::Get(profile())->IsRegistered(app_id); | 27 return ArcAppListPrefs::Get(profile())->IsRegistered(app_id); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void ArcAppIconLoader::FetchImage(const std::string& app_id) { | 30 void ArcAppIconLoader::FetchImage(const std::string& app_id) { |
| 31 if (icon_map_.find(app_id) != icon_map_.end()) | 31 if (icon_map_.find(app_id) != icon_map_.end()) |
| 32 return; // Already loading the image. | 32 return; // Already loading the image. |
| 33 | 33 |
| 34 // Note, ARC icon is available only for 48x48 dips. In case |icon_size_| | 34 // Note, ARC icon is available only for 48x48 dips. In case |icon_size_| |
| 35 // differs from this size, re-scale is required. | 35 // differs from this size, re-scale is required. |
| 36 scoped_ptr<ArcAppIcon> icon(new ArcAppIcon(profile(), | 36 std::unique_ptr<ArcAppIcon> icon( |
| 37 app_id, | 37 new ArcAppIcon(profile(), app_id, app_list::kGridIconDimension, this)); |
| 38 app_list::kGridIconDimension, | |
| 39 this)); | |
| 40 icon->image_skia().EnsureRepsForSupportedScales(); | 38 icon->image_skia().EnsureRepsForSupportedScales(); |
| 41 icon_map_[app_id] = std::move(icon); | 39 icon_map_[app_id] = std::move(icon); |
| 42 UpdateImage(app_id); | 40 UpdateImage(app_id); |
| 43 } | 41 } |
| 44 | 42 |
| 45 void ArcAppIconLoader::ClearImage(const std::string& app_id) { | 43 void ArcAppIconLoader::ClearImage(const std::string& app_id) { |
| 46 icon_map_.erase(app_id); | 44 icon_map_.erase(app_id); |
| 47 } | 45 } |
| 48 | 46 |
| 49 void ArcAppIconLoader::UpdateImage(const std::string& app_id) { | 47 void ArcAppIconLoader::UpdateImage(const std::string& app_id) { |
| 50 AppIDToIconMap::iterator it = icon_map_.find(app_id); | 48 AppIDToIconMap::iterator it = icon_map_.find(app_id); |
| 51 if (it == icon_map_.end()) | 49 if (it == icon_map_.end()) |
| 52 return; | 50 return; |
| 53 | 51 |
| 54 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = | 52 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 55 ArcAppListPrefs::Get(profile())->GetApp(app_id); | 53 ArcAppListPrefs::Get(profile())->GetApp(app_id); |
| 56 if (!app_info || !app_info->ready) { | 54 if (!app_info || !app_info->ready) { |
| 57 delegate()->OnAppImageUpdated(app_id, | 55 delegate()->OnAppImageUpdated(app_id, |
| 58 ChromeAppListItem::CreateDisabledIcon(it->second->image_skia())); | 56 ChromeAppListItem::CreateDisabledIcon(it->second->image_skia())); |
| 59 } else { | 57 } else { |
| 60 delegate()->OnAppImageUpdated(app_id, it->second->image_skia()); | 58 delegate()->OnAppImageUpdated(app_id, it->second->image_skia()); |
| 61 } | 59 } |
| 62 | 60 |
| 63 } | 61 } |
| 64 | 62 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 UpdateImage(app_id); | 73 UpdateImage(app_id); |
| 76 } | 74 } |
| 77 | 75 |
| 78 void ArcAppIconLoader::OnAppIconUpdated(const std::string& app_id, | 76 void ArcAppIconLoader::OnAppIconUpdated(const std::string& app_id, |
| 79 ui::ScaleFactor scale_factor) { | 77 ui::ScaleFactor scale_factor) { |
| 80 AppIDToIconMap::const_iterator it = icon_map_.find(app_id); | 78 AppIDToIconMap::const_iterator it = icon_map_.find(app_id); |
| 81 if (it == icon_map_.end()) | 79 if (it == icon_map_.end()) |
| 82 return; | 80 return; |
| 83 it->second->LoadForScaleFactor(scale_factor); | 81 it->second->LoadForScaleFactor(scale_factor); |
| 84 } | 82 } |
| OLD | NEW |