Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/arc/intent_helper/activity_icon_loader.h" | 5 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 namespace arc { | 22 namespace arc { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 constexpr size_t kSmallIconSizeInDip = 16; | 26 constexpr size_t kSmallIconSizeInDip = 16; |
| 27 constexpr size_t kLargeIconSizeInDip = 20; | 27 constexpr size_t kLargeIconSizeInDip = 20; |
| 28 constexpr size_t kMaxIconSizeInPx = 200; | 28 constexpr size_t kMaxIconSizeInPx = 200; |
| 29 constexpr char kPngDataUrlPrefix[] = "data:image/png;base64,"; | 29 constexpr char kPngDataUrlPrefix[] = "data:image/png;base64,"; |
| 30 | 30 |
| 31 constexpr int kMinInstanceVersion = 3; // see intent_helper.mojom | |
| 32 | |
| 33 ui::ScaleFactor GetSupportedScaleFactor() { | 31 ui::ScaleFactor GetSupportedScaleFactor() { |
| 34 std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors(); | 32 std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors(); |
| 35 DCHECK(!scale_factors.empty()); | 33 DCHECK(!scale_factors.empty()); |
| 36 return scale_factors.back(); | 34 return scale_factors.back(); |
| 37 } | 35 } |
| 38 | 36 |
| 37 // Returns an instance for calling RequestActivityIcons(). | |
| 38 mojom::IntentHelperInstance* GetInstance( | |
|
Luis Héctor Chávez
2017/01/06 23:46:28
Can we name this GetInstanceForRequestActivityIcon
Yusuke Sato
2017/01/07 00:25:14
Done.
| |
| 39 ArcIntentHelperBridge::GetResult* out_error_code) { | |
| 40 if (!ArcIntentHelperBridge::IsIntentHelperAvailable(out_error_code)) | |
| 41 return nullptr; | |
| 42 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | |
| 43 ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), | |
| 44 RequestActivityIcons); | |
| 45 if (!instance && out_error_code) { | |
| 46 *out_error_code = | |
| 47 ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_SUPPORTED; | |
| 48 } | |
| 49 return instance; | |
| 50 } | |
| 51 | |
| 39 } // namespace | 52 } // namespace |
| 40 | 53 |
| 41 ActivityIconLoader::Icons::Icons( | 54 ActivityIconLoader::Icons::Icons( |
| 42 const gfx::Image& icon16, | 55 const gfx::Image& icon16, |
| 43 const gfx::Image& icon20, | 56 const gfx::Image& icon20, |
| 44 const scoped_refptr<base::RefCountedData<GURL>>& icon16_dataurl) | 57 const scoped_refptr<base::RefCountedData<GURL>>& icon16_dataurl) |
| 45 : icon16(icon16), icon20(icon20), icon16_dataurl(icon16_dataurl) {} | 58 : icon16(icon16), icon20(icon20), icon16_dataurl(icon16_dataurl) {} |
| 46 | 59 |
| 47 ActivityIconLoader::Icons::Icons(const Icons& other) = default; | 60 ActivityIconLoader::Icons::Icons(const Icons& other) = default; |
| 48 | 61 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 } | 103 } |
| 91 } | 104 } |
| 92 | 105 |
| 93 if (activities_to_fetch.empty()) { | 106 if (activities_to_fetch.empty()) { |
| 94 // If there's nothing to fetch, run the callback now. | 107 // If there's nothing to fetch, run the callback now. |
| 95 cb.Run(std::move(result)); | 108 cb.Run(std::move(result)); |
| 96 return GetResult::SUCCEEDED_SYNC; | 109 return GetResult::SUCCEEDED_SYNC; |
| 97 } | 110 } |
| 98 | 111 |
| 99 ArcIntentHelperBridge::GetResult error_code; | 112 ArcIntentHelperBridge::GetResult error_code; |
| 100 auto* instance = ArcIntentHelperBridge::GetIntentHelperInstanceWithErrorCode( | 113 auto* instance = GetInstance(&error_code); |
| 101 "RequestActivityIcons", kMinInstanceVersion, &error_code); | |
| 102 if (!instance) { | 114 if (!instance) { |
| 103 // The mojo channel is not yet ready (or not supported at all). Run the | 115 // The mojo channel is not yet ready (or not supported at all). Run the |
| 104 // callback with |result| that could be empty. | 116 // callback with |result| that could be empty. |
| 105 cb.Run(std::move(result)); | 117 cb.Run(std::move(result)); |
| 106 switch (error_code) { | 118 switch (error_code) { |
| 107 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_READY: | 119 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_READY: |
| 108 return GetResult(GetResult::FAILED_ARC_NOT_READY); | 120 return GetResult(GetResult::FAILED_ARC_NOT_READY); |
| 109 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_SUPPORTED: | 121 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_SUPPORTED: |
| 110 return GetResult(GetResult::FAILED_ARC_NOT_SUPPORTED); | 122 return GetResult(GetResult::FAILED_ARC_NOT_SUPPORTED); |
| 111 } | 123 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 cached_icons_.erase(kv.first); | 234 cached_icons_.erase(kv.first); |
| 223 cached_icons_.insert(std::make_pair(kv.first, kv.second)); | 235 cached_icons_.insert(std::make_pair(kv.first, kv.second)); |
| 224 } | 236 } |
| 225 | 237 |
| 226 // Merge the results that were obtained from cache before doing IPC. | 238 // Merge the results that were obtained from cache before doing IPC. |
| 227 result->insert(cached_result->begin(), cached_result->end()); | 239 result->insert(cached_result->begin(), cached_result->end()); |
| 228 cb.Run(std::move(result)); | 240 cb.Run(std::move(result)); |
| 229 } | 241 } |
| 230 | 242 |
| 231 } // namespace arc | 243 } // namespace arc |
| OLD | NEW |