0

Spanify shared_resources_data_source.cc

Avoid using UNSAFE_BUFFERS() and simplify implementation. Follow-on
from https://crrev.com/c/6344934

Change-Id: I3c921b8e9cb09ece80f432e0b6a8be8f2937398e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6353017
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1432948}
This commit is contained in:
Tom Sepez
2025-03-14 12:56:55 -07:00
committed by Chromium LUCI CQ
parent 7f8a6d28ea
commit ccfe003a4f

@ -6,7 +6,7 @@
#include <set>
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "content/public/browser/web_ui_data_source.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "ui/base/webui/web_ui_util.h"
@ -35,17 +35,12 @@ const std::set<int> GetContentResourceIds() {
// Adds all resources with IDs in |resource_ids| to |resources_map|.
void AddResources(const std::set<int>& resource_ids,
const webui::ResourcePath resources[],
size_t resources_size,
base::span<const webui::ResourcePath> resources,
WebUIDataSource* source) {
for (size_t i = 0; i < resources_size; ++i) {
const auto& resource = UNSAFE_TODO(resources[i]);
const auto it = resource_ids.find(resource.id);
if (it == resource_ids.end())
continue;
source->AddResourcePath(resource.path, resource.id);
for (const auto& resource : resources) {
if (base::Contains(resource_ids, resource.id)) {
source->AddResourcePath(resource.path, resource.id);
}
}
}
#endif // BUILDFLAG(IS_CHROMEOS)
@ -65,8 +60,7 @@ void PopulateSharedResourcesDataSource(WebUIDataSource* source) {
source->AddResourcePaths(kAshWebuiCommonResources);
// Deprecated -lite style mojo bindings.
source->AddResourcePaths(kMojoBindingsResources);
AddResources(GetContentResourceIds(), kContentResources,
kContentResourcesSize, source);
AddResources(GetContentResourceIds(), kContentResources, source);
#endif // BUILDFLAG(IS_CHROMEOS)
}