Commit e1bd1195 authored by David Jacobo's avatar David Jacobo Committed by Commit Bot

Remove IsSwapElementsNeeded

Removing IsSwapElementsNeeded since this functionality is no longer
needed, also removing the test for this.

Bug: 678141
Test: Build.
Change-Id: I86c34578d39ec75b2c79a0151cc04ef8366a31e0
Reviewed-on: https://chromium-review.googlesource.com/748709Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: David Jacobo <djacobo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513247}
parent dba82b5d
......@@ -398,15 +398,9 @@ void OnUrlHandlerList(int render_process_host_id,
return; // the |url| has been handled.
}
// Otherwise, retrieve icons of the activities. First, swap |handler| elements
// to ensure Chrome is visible in the UI by default. Since this function is
// for handling external protocols, Chrome is rarely in the list, but if the
// |url| is intent: with fallback or geo:, for example, it may be.
std::pair<size_t, size_t> indices;
if (ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
std::swap(handlers[indices.first], handlers[indices.second]);
// Then request the icons.
// Otherwise, retrieve icons of the activities. Since this function is for
// handling external protocols, Chrome is rarely in the list, but if the |url|
// is intent: with fallback or geo:, for example, it may be.
std::vector<ArcIntentHelperBridge::ActivityName> activities;
for (const auto& handler : handlers) {
activities.emplace_back(handler->package_name, handler->activity_name);
......
......@@ -431,26 +431,6 @@ size_t ArcNavigationThrottle::FindPreferredAppForTesting(
return FindPreferredApp(handlers, GURL());
}
// static
bool ArcNavigationThrottle::IsSwapElementsNeeded(
const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
std::pair<size_t, size_t>* out_indices) {
size_t chrome_app_index = 0;
for (size_t i = 0; i < handlers.size(); ++i) {
if (ArcIntentHelperBridge::IsIntentHelperPackage(
handlers[i]->package_name)) {
chrome_app_index = i;
break;
}
}
if (chrome_app_index < ArcNavigationThrottle::kMaxAppResults)
return false;
*out_indices = std::make_pair(ArcNavigationThrottle::kMaxAppResults - 1,
chrome_app_index);
return true;
}
// static
void ArcNavigationThrottle::AsyncShowIntentPickerBubble(const Browser* browser,
const GURL& url) {
......
......@@ -111,14 +111,6 @@ class ArcNavigationThrottle : public content::NavigationThrottle {
static bool IsAppAvailable(
const std::vector<mojom::IntentHandlerInfoPtr>& handlers);
// Swaps Chrome app with any app in row |kMaxAppResults-1| iff its index is
// bigger, thus ensuring the user can always see Chrome without scrolling.
// When swap is needed, fills |out_indices| and returns true. If |handlers|
// do not have Chrome, returns false.
static bool IsSwapElementsNeeded(
const std::vector<mojom::IntentHandlerInfoPtr>& handlers,
std::pair<size_t, size_t>* out_indices);
static bool IsAppAvailableForTesting(
const std::vector<mojom::IntentHandlerInfoPtr>& handlers);
static size_t FindPreferredAppForTesting(
......
......@@ -229,55 +229,4 @@ TEST(ArcNavigationThrottleTest, TestGetDestinationPlatform) {
ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND));
}
TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) {
std::pair<size_t, size_t> indices;
for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) {
// When Chrome is the first element, swap is unnecessary.
std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0);
EXPECT_FALSE(
ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
// When Chrome is within the first |kMaxAppResults| elements, swap is
// unnecessary.
handlers = CreateArray(i, i - 1);
EXPECT_FALSE(
ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
}
for (size_t i = ArcNavigationThrottle::kMaxAppResults + 1;
i < ArcNavigationThrottle::kMaxAppResults * 2; ++i) {
// When Chrome is within the first |kMaxAppResults| elements, swap is
// unnecessary.
std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0);
EXPECT_FALSE(
ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
// When Chrome is the |kMaxAppResults|-th element, swap is unnecessary.
handlers = CreateArray(i, ArcNavigationThrottle::kMaxAppResults - 1);
EXPECT_FALSE(
ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
// When Chrome is not within the first |kMaxAppResults| elements, swap is
// necessary.
handlers = CreateArray(i, i - 1);
indices.first = indices.second = 0;
EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i;
EXPECT_EQ(i - 1, indices.second) << i;
}
for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) {
// When Chrome does not exist in |handlers|, swap is unnecessary.
std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i);
EXPECT_FALSE(
ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
<< i;
}
}
} // namespace arc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment