Commit 10be2c7a authored by nancy's avatar nancy Committed by Commit Bot

Factor the loading of compressed icons out to a function.

BUG=988321

Change-Id: I5cf9fff36c7cdb9aaf777172f3169035e0a05d3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730413Reviewed-by: default avatarNigel Tao <nigeltao@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683455}
parent 0962ad45
...@@ -114,6 +114,52 @@ void RunCallbackWithCompressedData( ...@@ -114,6 +114,52 @@ void RunCallbackWithCompressedData(
std::move(callback).Run(apps::mojom::IconValue::New()); std::move(callback).Run(apps::mojom::IconValue::New());
} }
void RunCallbackWithCompressedDataFromExtension(
const extensions::Extension* extension,
extensions::ExtensionResource ext_resource,
int size_hint_in_dip,
int default_icon_resource,
bool is_placeholder_icon,
apps::IconEffects icon_effects,
apps::mojom::Publisher::LoadIconCallback callback) {
// Load some component extensions' icons from statically compiled
// resources (built into the Chrome binary), and other extensions'
// icons (whether component extensions or otherwise) from files on
// disk.
//
// For the kUncompressed case, RunCallbackWithUncompressedImage
// calls extensions::ImageLoader::LoadImageAsync, which already handles
// that distinction. We can't use LoadImageAsync here, because the
// caller has asked for compressed icons (i.e. PNG-formatted data), not
// uncompressed (i.e. a gfx::ImageSkia).
if (extension && extension->location() == extensions::Manifest::COMPONENT) {
int resource_id = 0;
const extensions::ComponentExtensionResourceManager* manager =
extensions::ExtensionsBrowserClient::Get()
->GetComponentExtensionResourceManager();
if (manager &&
manager->IsComponentExtensionResource(
extension->path(), ext_resource.relative_path(), &resource_id)) {
base::StringPiece data =
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
resource_id);
RunCallbackWithCompressedData(
size_hint_in_dip, default_icon_resource, is_placeholder_icon,
icon_effects, std::move(callback),
std::vector<uint8_t>(data.begin(), data.end()));
return;
}
}
// Try and load data from the resource file.
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&CompressedDataFromResource, std::move(ext_resource)),
base::BindOnce(&RunCallbackWithCompressedData, size_hint_in_dip,
default_icon_resource, is_placeholder_icon, icon_effects,
std::move(callback)));
}
// Like RunCallbackWithCompressedData, but calls "fallback(callback)" if the // Like RunCallbackWithCompressedData, but calls "fallback(callback)" if the
// data is empty. // data is empty.
void RunCallbackWithCompressedDataWithFallback( void RunCallbackWithCompressedDataWithFallback(
...@@ -260,43 +306,10 @@ void LoadIconFromExtension(apps::mojom::IconCompression icon_compression, ...@@ -260,43 +306,10 @@ void LoadIconFromExtension(apps::mojom::IconCompression icon_compression,
} }
case apps::mojom::IconCompression::kCompressed: { case apps::mojom::IconCompression::kCompressed: {
// Load some component extensions' icons from statically compiled RunCallbackWithCompressedDataFromExtension(
// resources (built into the Chrome binary), and other extensions' extension, std::move(ext_resource), size_hint_in_dip,
// icons (whether component extensions or otherwise) from files on default_icon_resource, is_placeholder_icon, icon_effects,
// disk. std::move(callback));
//
// For the kUncompressed case above, RunCallbackWithUncompressedImage
// calls extensions::ImageLoader::LoadImageAsync, which already handles
// that distinction. We can't use LoadImageAsync here, because the
// caller has asked for compressed icons (i.e. PNG-formatted data), not
// uncompressed (i.e. a gfx::ImageSkia).
if (extension->location() == extensions::Manifest::COMPONENT) {
int resource_id = 0;
const extensions::ComponentExtensionResourceManager* manager =
extensions::ExtensionsBrowserClient::Get()
->GetComponentExtensionResourceManager();
if (manager && manager->IsComponentExtensionResource(
extension->path(), ext_resource.relative_path(),
&resource_id)) {
base::StringPiece data =
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
resource_id);
RunCallbackWithCompressedData(
size_hint_in_dip, default_icon_resource, is_placeholder_icon,
icon_effects, std::move(callback),
std::vector<uint8_t>(data.begin(), data.end()));
return;
}
}
// Try and load data from the resource file.
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&CompressedDataFromResource,
std::move(ext_resource)),
base::BindOnce(&RunCallbackWithCompressedData, size_hint_in_dip,
default_icon_resource, is_placeholder_icon,
icon_effects, std::move(callback)));
return; return;
} }
} }
......
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