Skip to content

Commit 104e3c2

Browse files
Paul AdedejiChromium LUCI CQ
authored andcommitted
Shorten uses of "side_panel::customize_chrome::mojom::" with using
To make wallpaper_search_handler.cc more readable, this CL adds using directives for places where: 1. The variable name is incongruent with the mojom definition i.e. thumbnail = ...WallpaperSearchResult versus mojo_descriptor_a = ...::DescriptorA::New(). 2. There is no variable name to derive clarity from i.e. std::move(callback).Run(WallpaperSearchStatus::kRequestThrottled, std::vector<WallpaperSearchResultPtr>()); This is a follow up from https://chromium-review.googlesource.com/c/chromium/src/+/5297002/comment/2ab49b93_d0e194f6/ Change-Id: Ia18f96a51d62f0403170b2aff7cb5ddeeb93edde Bug: 308810065 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5303583 Commit-Queue: Paul Adedeji <[email protected]> Reviewed-by: Tibor Goldschwendt <[email protected]> Cr-Commit-Position: refs/heads/main@{#1267142}
1 parent 3ed37c2 commit 104e3c2

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_handler.cc

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@
6565
#include "ui/gfx/geometry/size.h"
6666
#include "ui/gfx/image/image.h"
6767

68+
using side_panel::customize_chrome::mojom::DescriptorDName;
69+
using side_panel::customize_chrome::mojom::DescriptorDValue;
6870
using side_panel::customize_chrome::mojom::UserFeedback;
71+
using side_panel::customize_chrome::mojom::WallpaperSearchResult;
72+
using side_panel::customize_chrome::mojom::WallpaperSearchResultPtr;
73+
using side_panel::customize_chrome::mojom::WallpaperSearchStatus;
6974

7075
namespace {
7176

@@ -323,28 +328,22 @@ void WallpaperSearchHandler::GetWallpaperSearchResults(
323328
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile_);
324329
if (!identity_manager ||
325330
!identity_manager->HasPrimaryAccount(signin::ConsentLevel::kSignin)) {
326-
std::move(callback).Run(
327-
side_panel::customize_chrome::mojom::WallpaperSearchStatus::kSignedOut,
328-
std::vector<
329-
side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>());
331+
std::move(callback).Run(WallpaperSearchStatus::kSignedOut,
332+
std::vector<WallpaperSearchResultPtr>());
330333
return;
331334
}
332335
#if BUILDFLAG(IS_CHROMEOS)
333336
// Check if user is browsing in guest mode.
334337
if (profile_->IsGuestSession()) {
335-
std::move(callback).Run(
336-
side_panel::customize_chrome::mojom::WallpaperSearchStatus::kSignedOut,
337-
std::vector<
338-
side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>());
338+
std::move(callback).Run(WallpaperSearchStatus::kSignedOut,
339+
std::vector<WallpaperSearchResultPtr>());
339340
return;
340341
}
341342
#endif // BUILDFLAG(IS_CHROMEOS)
342343

343344
callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun(
344-
std::move(callback),
345-
side_panel::customize_chrome::mojom::WallpaperSearchStatus::kError,
346-
std::vector<
347-
side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>());
345+
std::move(callback), WallpaperSearchStatus::kError,
346+
std::vector<WallpaperSearchResultPtr>());
348347
if (!base::FeatureList::IsEnabled(
349348
ntp_features::kCustomizeChromeWallpaperSearch) ||
350349
!base::FeatureList::IsEnabled(
@@ -492,8 +491,7 @@ void WallpaperSearchHandler::SetBackgroundToInspirationImage(
492491

493492
void WallpaperSearchHandler::UpdateHistory() {
494493
const auto& history = wallpaper_search_background_manager_->GetHistory();
495-
std::vector<side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>
496-
thumbnails;
494+
std::vector<WallpaperSearchResultPtr> thumbnails;
497495

498496
auto barrier = base::BarrierCallback<std::pair<SkBitmap, base::Token>>(
499497
history.size(), base::BindOnce(&WallpaperSearchHandler::OnHistoryDecoded,
@@ -707,8 +705,7 @@ void WallpaperSearchHandler::OnDescriptorsJsonParsed(
707705
void WallpaperSearchHandler::OnHistoryDecoded(
708706
std::vector<HistoryEntry> history,
709707
std::vector<std::pair<SkBitmap, base::Token>> results) {
710-
std::vector<side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>
711-
thumbnails;
708+
std::vector<WallpaperSearchResultPtr> thumbnails;
712709

713710
// Use the original history array to order the results.
714711
// O(n^2) but there should never be more than 6 in each vector.
@@ -725,8 +722,7 @@ void WallpaperSearchHandler::OnHistoryDecoded(
725722
const bool success = gfx::PNGCodec::EncodeBGRASkBitmap(
726723
small_bitmap, /*discard_transparency=*/false, &encoded);
727724
if (success) {
728-
auto thumbnail =
729-
side_panel::customize_chrome::mojom::WallpaperSearchResult::New();
725+
auto thumbnail = WallpaperSearchResult::New();
730726
thumbnail->image = base::Base64Encode(encoded);
731727
thumbnail->id = std::move(id);
732728
if (entry.subject) {
@@ -839,9 +835,7 @@ void WallpaperSearchHandler::OnInspirationsJsonParsed(
839835
descriptor_d_dict->FindString("name")) {
840836
if (descriptor_d_name->compare("Yellow") == 0) {
841837
mojo_inspiration_group->descriptors->color =
842-
side_panel::customize_chrome::mojom::DescriptorDValue::NewName(
843-
side_panel::customize_chrome::mojom::DescriptorDName::
844-
kYellow);
838+
DescriptorDValue::NewName(DescriptorDName::kYellow);
845839
}
846840
}
847841
}
@@ -943,11 +937,8 @@ void WallpaperSearchHandler::OnWallpaperSearchResultsRetrieved(
943937
if (result.error().error() ==
944938
optimization_guide::OptimizationGuideModelExecutionError::
945939
ModelExecutionError::kRequestThrottled) {
946-
std::move(callback).Run(
947-
side_panel::customize_chrome::mojom::WallpaperSearchStatus::
948-
kRequestThrottled,
949-
std::vector<
950-
side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>());
940+
std::move(callback).Run(WallpaperSearchStatus::kRequestThrottled,
941+
std::vector<WallpaperSearchResultPtr>());
951942
}
952943
return;
953944
}
@@ -1021,8 +1012,7 @@ void WallpaperSearchHandler::OnWallpaperSearchResultsDecoded(
10211012
std::vector<
10221013
std::pair<optimization_guide::proto::WallpaperSearchImageQuality*,
10231014
SkBitmap>> bitmaps) {
1024-
std::vector<side_panel::customize_chrome::mojom::WallpaperSearchResultPtr>
1025-
thumbnails;
1015+
std::vector<WallpaperSearchResultPtr> thumbnails;
10261016

10271017
for (auto& [image_quality, bitmap] : bitmaps) {
10281018
auto dimensions =
@@ -1035,8 +1025,7 @@ void WallpaperSearchHandler::OnWallpaperSearchResultsDecoded(
10351025
const bool success = gfx::PNGCodec::EncodeBGRASkBitmap(
10361026
small_bitmap, /*discard_transparency=*/false, &encoded);
10371027
if (success) {
1038-
auto thumbnail =
1039-
side_panel::customize_chrome::mojom::WallpaperSearchResult::New();
1028+
auto thumbnail = WallpaperSearchResult::New();
10401029
auto id = base::Token::CreateRandom();
10411030
wallpaper_search_results_[id] =
10421031
std::make_tuple(image_quality, std::nullopt, std::move(bitmap));
@@ -1049,9 +1038,7 @@ void WallpaperSearchHandler::OnWallpaperSearchResultsDecoded(
10491038
UmaHistogramMediumTimes(
10501039
"NewTabPage.WallpaperSearch.GetResultProcessingLatency",
10511040
processing_timer.Elapsed());
1052-
std::move(callback).Run(
1053-
side_panel::customize_chrome::mojom::WallpaperSearchStatus::kOk,
1054-
std::move(thumbnails));
1041+
std::move(callback).Run(WallpaperSearchStatus::kOk, std::move(thumbnails));
10551042
}
10561043

10571044
void WallpaperSearchHandler::LaunchDelayedHatsSurvey() {

0 commit comments

Comments
 (0)