Make gfx::Image instance a local variable.

This follows https://codereview.chromium.org/2709683002
This commit is contained in:
Yury Solovyov 2018-01-08 12:47:25 +03:00
parent c1d68974ab
commit b3743058c0
4 changed files with 18 additions and 12 deletions

View file

@ -82,8 +82,6 @@ class IconLoader {
IconSize icon_size_; IconSize icon_size_;
std::unique_ptr<gfx::Image> image_;
IconLoadedCallback callback_; IconLoadedCallback callback_;
DISALLOW_COPY_AND_ASSIGN(IconLoader); DISALLOW_COPY_AND_ASSIGN(IconLoader);

View file

@ -5,6 +5,7 @@
#include "chrome/browser/icon_loader.h" #include "chrome/browser/icon_loader.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/nix/mime_util_xdg.h" #include "base/nix/mime_util_xdg.h"
#include "ui/views/linux_ui/linux_ui.h" #include "ui/views/linux_ui/linux_ui.h"
@ -38,14 +39,17 @@ void IconLoader::ReadIcon() {
NOTREACHED(); NOTREACHED();
} }
std::unique_ptr<gfx::Image> image;
views::LinuxUI* ui = views::LinuxUI::instance(); views::LinuxUI* ui = views::LinuxUI::instance();
if (ui) { if (ui) {
gfx::Image image = ui->GetIconForContentType(group_, size_pixels); image = base::MakeUnique<gfx::Image>(
if (!image.IsEmpty()) ui->GetIconForContentType(group_, size_pixels));
image_.reset(new gfx::Image(image)); if (image->IsEmpty())
image = nullptr;
} }
target_task_runner_->PostTask( target_task_runner_->PostTask(
FROM_HERE, base::Bind(callback_, base::Passed(&image_), group_)); FROM_HERE, base::Bind(callback_, base::Passed(&image), group_));
delete this; delete this;
} }

View file

@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
@ -30,9 +31,11 @@ void IconLoader::ReadIcon() {
NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSImage* icon = [workspace iconForFileType:group]; NSImage* icon = [workspace iconForFileType:group];
std::unique_ptr<gfx::Image> image;
if (icon_size_ == ALL) { if (icon_size_ == ALL) {
// The NSImage already has all sizes. // The NSImage already has all sizes.
image_.reset(new gfx::Image([icon retain])); image = base::MakeUnique<gfx::Image>([icon retain]);
} else { } else {
NSSize size = NSZeroSize; NSSize size = NSZeroSize;
switch (icon_size_) { switch (icon_size_) {
@ -48,11 +51,11 @@ void IconLoader::ReadIcon() {
gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size));
if (!image_skia.isNull()) { if (!image_skia.isNull()) {
image_skia.MakeThreadSafe(); image_skia.MakeThreadSafe();
image_.reset(new gfx::Image(image_skia)); image = base::MakeUnique<gfx::Image>(image_skia);
} }
} }
target_task_runner_->PostTask( target_task_runner_->PostTask(
FROM_HERE, base::Bind(callback_, base::Passed(&image_), group_)); FROM_HERE, base::Bind(callback_, base::Passed(&image), group_));
delete this; delete this;
} }

View file

@ -8,6 +8,7 @@
#include <shellapi.h> #include <shellapi.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
@ -49,7 +50,7 @@ void IconLoader::ReadIcon() {
NOTREACHED(); NOTREACHED();
} }
image_.reset(); std::unique_ptr<gfx::Image> image;
SHFILEINFO file_info = { 0 }; SHFILEINFO file_info = { 0 };
if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
@ -61,12 +62,12 @@ void IconLoader::ReadIcon() {
gfx::ImageSkia image_skia(gfx::ImageSkiaRep(*bitmap, gfx::ImageSkia image_skia(gfx::ImageSkiaRep(*bitmap,
display::win::GetDPIScale())); display::win::GetDPIScale()));
image_skia.MakeThreadSafe(); image_skia.MakeThreadSafe();
image_.reset(new gfx::Image(image_skia)); image = base::MakeUnique<gfx::Image>(image_skia);
DestroyIcon(file_info.hIcon); DestroyIcon(file_info.hIcon);
} }
} }
target_task_runner_->PostTask( target_task_runner_->PostTask(
FROM_HERE, base::Bind(callback_, base::Passed(&image_), group_)); FROM_HERE, base::Bind(callback_, base::Passed(&image), group_));
delete this; delete this;
} }