| 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 namespace arc { | 21 namespace arc { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const size_t kSmallIconSizeInDip = 16; | 25 const size_t kSmallIconSizeInDip = 16; |
| 26 const size_t kLargeIconSizeInDip = 20; | 26 const size_t kLargeIconSizeInDip = 20; |
| 27 const size_t kMaxIconSizeInPx = 200; | 27 const size_t kMaxIconSizeInPx = 200; |
| 28 | 28 |
| 29 const int kMinInstanceVersion = 3; // see intent_helper.mojom | 29 const int kMinInstanceVersion = 3; // see intent_helper.mojom |
| 30 | 30 |
| 31 mojom::IntentHelperInstance* GetIntentHelperInstance( | |
| 32 ActivityIconLoader::GetResult* out_error_code) { | |
| 33 DCHECK(out_error_code); | |
| 34 ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 35 if (!bridge_service) { | |
| 36 VLOG(2) << "ARC bridge is not ready."; | |
| 37 *out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_SUPPORTED; | |
| 38 return nullptr; | |
| 39 } | |
| 40 mojom::IntentHelperInstance* intent_helper_instance = | |
| 41 bridge_service->intent_helper()->instance(); | |
| 42 if (!intent_helper_instance) { | |
| 43 VLOG(2) << "ARC intent helper instance is not ready."; | |
| 44 *out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_READY; | |
| 45 return nullptr; | |
| 46 } | |
| 47 if (bridge_service->intent_helper()->version() < kMinInstanceVersion) { | |
| 48 VLOG(1) << "ARC intent helper instance is too old."; | |
| 49 *out_error_code = ActivityIconLoader::GetResult::FAILED_ARC_NOT_SUPPORTED; | |
| 50 return nullptr; | |
| 51 } | |
| 52 return intent_helper_instance; | |
| 53 } | |
| 54 | |
| 55 ui::ScaleFactor GetSupportedScaleFactor() { | 31 ui::ScaleFactor GetSupportedScaleFactor() { |
| 56 std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors(); | 32 std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors(); |
| 57 DCHECK(!scale_factors.empty()); | 33 DCHECK(!scale_factors.empty()); |
| 58 return scale_factors.back(); | 34 return scale_factors.back(); |
| 59 } | 35 } |
| 60 | 36 |
| 61 } // namespace | 37 } // namespace |
| 62 | 38 |
| 63 ActivityIconLoader::Icons::Icons(const gfx::Image& icon16, | 39 ActivityIconLoader::Icons::Icons(const gfx::Image& icon16, |
| 64 const gfx::Image& icon20) | 40 const gfx::Image& icon20) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 result->insert(std::make_pair(activity, it->second)); | 81 result->insert(std::make_pair(activity, it->second)); |
| 106 } | 82 } |
| 107 } | 83 } |
| 108 | 84 |
| 109 if (activities_to_fetch.empty()) { | 85 if (activities_to_fetch.empty()) { |
| 110 // If there's nothing to fetch, run the callback now. | 86 // If there's nothing to fetch, run the callback now. |
| 111 cb.Run(std::move(result)); | 87 cb.Run(std::move(result)); |
| 112 return GetResult::SUCCEEDED_SYNC; | 88 return GetResult::SUCCEEDED_SYNC; |
| 113 } | 89 } |
| 114 | 90 |
| 115 GetResult error_code = GetResult::FAILED_ARC_NOT_SUPPORTED; | 91 ArcIntentHelperBridge::GetResult error_code; |
| 116 mojom::IntentHelperInstance* instance = GetIntentHelperInstance(&error_code); | 92 mojom::IntentHelperInstance* instance = |
| 93 ArcIntentHelperBridge::GetIntentHelperInstance(kMinInstanceVersion, |
| 94 &error_code); |
| 117 if (!instance) { | 95 if (!instance) { |
| 118 // The mojo channel is not yet ready (or not supported at all). Run the | 96 // The mojo channel is not yet ready (or not supported at all). Run the |
| 119 // callback with |result| that could be empty. | 97 // callback with |result| that could be empty. |
| 120 cb.Run(std::move(result)); | 98 cb.Run(std::move(result)); |
| 121 return error_code; | 99 switch (error_code) { |
| 100 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_READY: |
| 101 return GetResult(GetResult::FAILED_ARC_NOT_READY); |
| 102 case ArcIntentHelperBridge::GetResult::FAILED_ARC_NOT_SUPPORTED: |
| 103 return GetResult(GetResult::FAILED_ARC_NOT_SUPPORTED); |
| 104 } |
| 105 NOTREACHED(); |
| 122 } | 106 } |
| 123 | 107 |
| 124 // Fetch icons from ARC. | 108 // Fetch icons from ARC. |
| 125 instance->RequestActivityIcons( | 109 instance->RequestActivityIcons( |
| 126 std::move(activities_to_fetch), mojom::ScaleFactor(scale_factor_), | 110 std::move(activities_to_fetch), mojom::ScaleFactor(scale_factor_), |
| 127 base::Bind(&ActivityIconLoader::OnIconsReady, this, base::Passed(&result), | 111 base::Bind(&ActivityIconLoader::OnIconsReady, this, base::Passed(&result), |
| 128 cb)); | 112 cb)); |
| 129 return GetResult::SUCCEEDED_ASYNC; | 113 return GetResult::SUCCEEDED_ASYNC; |
| 130 } | 114 } |
| 131 | 115 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 cached_icons_.erase(kv.first); | 198 cached_icons_.erase(kv.first); |
| 215 cached_icons_.insert(std::make_pair(kv.first, kv.second)); | 199 cached_icons_.insert(std::make_pair(kv.first, kv.second)); |
| 216 } | 200 } |
| 217 | 201 |
| 218 // Merge the results that were obtained from cache before doing IPC. | 202 // Merge the results that were obtained from cache before doing IPC. |
| 219 result->insert(cached_result->begin(), cached_result->end()); | 203 result->insert(cached_result->begin(), cached_result->end()); |
| 220 cb.Run(std::move(result)); | 204 cb.Run(std::move(result)); |
| 221 } | 205 } |
| 222 | 206 |
| 223 } // namespace arc | 207 } // namespace arc |
| OLD | NEW |