Commit 88201ec9 authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

Simplify ChromeComponentExtensionResourceManager serving of generated files.

With the addition of the |resource_path| grd attribute, there is
no longer a need to manually handle generated paths in
ChromeComponentExtensionResourceManager.

This is in preparation of auto-generating the grd file for the PDF
Viewer.

Bug: 1132403
Change-Id: I7d788c5cfaa3da21471a76bf4dd7585a56339ef3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2614130Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841486}
parent d258b5ff
......@@ -153,28 +153,13 @@ ChromeComponentExtensionResourceManager::Data::Data() {
void ChromeComponentExtensionResourceManager::Data::AddComponentResourceEntries(
const GritResourceMap* entries,
size_t size) {
base::FilePath gen_folder_path = base::FilePath().AppendASCII(
"@out_folder@/gen/chrome/browser/resources/");
gen_folder_path = gen_folder_path.NormalizePathSeparators();
for (size_t i = 0; i < size; ++i) {
base::FilePath resource_path =
base::FilePath().AppendASCII(entries[i].name);
resource_path = resource_path.NormalizePathSeparators();
if (!gen_folder_path.IsParent(resource_path)) {
DCHECK(!base::Contains(path_to_resource_id_, resource_path));
path_to_resource_id_[resource_path] = entries[i].value;
} else {
// If the resource is a generated file, strip the generated folder's path,
// so that it can be served from a normal URL (as if it were not
// generated).
base::FilePath effective_path =
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
gen_folder_path.value().length()));
DCHECK(!base::Contains(path_to_resource_id_, effective_path));
path_to_resource_id_[effective_path] = entries[i].value;
}
DCHECK(!base::Contains(path_to_resource_id_, resource_path));
path_to_resource_id_[resource_path] = entries[i].value;
}
}
......
......@@ -80,38 +80,4 @@ TEST_F(ChromeComponentExtensionResourceManagerTest,
#endif
}
TEST_F(ChromeComponentExtensionResourceManagerTest,
IsComponentExtensionResource_Generated) {
// Check that the file being used for testing is indeed a generated resource.
int generated_resource_id = IDR_PDF_SHARED_VARS_JS;
bool found_resource = false;
for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
if (kComponentExtensionResources[i].value == generated_resource_id) {
ASSERT_TRUE(base::StartsWith(kComponentExtensionResources[i].name,
"@out_folder@",
base::CompareCase::SENSITIVE));
found_resource = true;
break;
}
}
ASSERT_TRUE(found_resource);
const ComponentExtensionResourceManager* resource_manager =
ExtensionsBrowserClient::Get()->GetComponentExtensionResourceManager();
ASSERT_TRUE(resource_manager);
base::FilePath resources_dir;
base::PathService::Get(chrome::DIR_RESOURCES, &resources_dir);
base::FilePath extension_path = resources_dir.AppendASCII("pdf");
base::FilePath resource_path =
base::FilePath().AppendASCII("elements/shared-vars.js");
// Check that the resource is classified as a component resource.
int resource_id = 0;
ASSERT_TRUE(resource_manager->IsComponentExtensionResource(
extension_path, resource_path, &resource_id));
ASSERT_EQ(generated_resource_id, resource_id);
}
} // namespace extensions
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