build: remove //chrome/browser/icon_loader source copies (#14955)
* build: remove //chrome/browser/icon_loader source copies * chore: add DCHECK to ensure IconManager is accessed from UI thread
This commit is contained in:
parent
71058fd9a3
commit
2700eaca1e
17 changed files with 25 additions and 560 deletions
|
@ -4,15 +4,13 @@
|
|||
|
||||
#include "chrome/browser/browser_process.h"
|
||||
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
#include "chrome/browser/printing/print_job_manager.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
BrowserProcess* g_browser_process = NULL;
|
||||
|
||||
BrowserProcess::BrowserProcess()
|
||||
: print_job_manager_(new printing::PrintJobManager),
|
||||
icon_manager_(new IconManager) {
|
||||
: print_job_manager_(new printing::PrintJobManager) {
|
||||
g_browser_process = this;
|
||||
}
|
||||
|
||||
|
@ -28,12 +26,6 @@ std::string BrowserProcess::GetApplicationLocale() {
|
|||
return locale_;
|
||||
}
|
||||
|
||||
IconManager* BrowserProcess::GetIconManager() {
|
||||
if (!icon_manager_.get())
|
||||
icon_manager_.reset(new IconManager);
|
||||
return icon_manager_.get();
|
||||
}
|
||||
|
||||
printing::PrintJobManager* BrowserProcess::print_job_manager() {
|
||||
return print_job_manager_.get();
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
#include "base/macros.h"
|
||||
|
||||
class IconManager;
|
||||
|
||||
namespace printing {
|
||||
class PrintJobManager;
|
||||
}
|
||||
|
@ -30,13 +28,11 @@ class BrowserProcess {
|
|||
|
||||
void SetApplicationLocale(const std::string& locale);
|
||||
std::string GetApplicationLocale();
|
||||
IconManager* GetIconManager();
|
||||
|
||||
printing::PrintJobManager* print_job_manager();
|
||||
|
||||
private:
|
||||
std::unique_ptr<printing::PrintJobManager> print_job_manager_;
|
||||
std::unique_ptr<IconManager> icon_manager_;
|
||||
std::string locale_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserProcess);
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "base/task_scheduler/task_traits.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
// static
|
||||
IconLoader* IconLoader::Create(const base::FilePath& file_path,
|
||||
IconSize size,
|
||||
IconLoadedCallback callback) {
|
||||
return new IconLoader(file_path, size, callback);
|
||||
}
|
||||
|
||||
void IconLoader::Start() {
|
||||
target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
||||
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, traits(),
|
||||
base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)));
|
||||
}
|
||||
|
||||
IconLoader::IconLoader(const base::FilePath& file_path,
|
||||
IconSize size,
|
||||
IconLoadedCallback callback)
|
||||
: file_path_(file_path), icon_size_(size), callback_(callback) {}
|
||||
|
||||
IconLoader::~IconLoader() {}
|
||||
|
||||
void IconLoader::ReadGroup() {
|
||||
group_ = GroupForFilepath(file_path_);
|
||||
GetReadIconTaskRunner()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this)));
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_BROWSER_ICON_LOADER_H_
|
||||
#define CHROME_BROWSER_ICON_LOADER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/task_scheduler/task_traits.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// A facility to read a file containing an icon asynchronously in the IO
|
||||
// thread. Returns the icon in the form of an ImageSkia.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class IconLoader {
|
||||
public:
|
||||
// An IconGroup is a class of files that all share the same icon. For all
|
||||
// platforms but Windows, and for most files on Windows, it is the file type
|
||||
// (e.g. all .mp3 files share an icon, all .html files share an icon). On
|
||||
// Windows, for certain file types (.exe, .dll, etc), each file of that type
|
||||
// is assumed to have a unique icon. In that case, each of those files is a
|
||||
// group to itself.
|
||||
using IconGroup = base::FilePath::StringType;
|
||||
|
||||
enum IconSize {
|
||||
SMALL = 0, // 16x16
|
||||
NORMAL, // 32x32
|
||||
LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
|
||||
ALL, // All sizes available
|
||||
};
|
||||
|
||||
// The callback invoked when an icon has been read. The parameters are:
|
||||
// - The icon that was loaded, or null if there was a failure to load it.
|
||||
// - The determined group from the original requested path.
|
||||
using IconLoadedCallback =
|
||||
base::Callback<void(std::unique_ptr<gfx::Image>, const IconGroup&)>;
|
||||
|
||||
// Creates an IconLoader, which owns itself. If the IconLoader might outlive
|
||||
// the caller, be sure to use a weak pointer in the |callback|.
|
||||
static IconLoader* Create(const base::FilePath& file_path,
|
||||
IconSize size,
|
||||
IconLoadedCallback callback);
|
||||
|
||||
// Starts the process of reading the icon. When the reading of the icon is
|
||||
// complete, the IconLoadedCallback callback will be fulfilled, and the
|
||||
// IconLoader will delete itself.
|
||||
void Start();
|
||||
|
||||
private:
|
||||
IconLoader(const base::FilePath& file_path,
|
||||
IconSize size,
|
||||
IconLoadedCallback callback);
|
||||
|
||||
~IconLoader();
|
||||
|
||||
// Given a file path, get the group for the given file.
|
||||
static IconGroup GroupForFilepath(const base::FilePath& file_path);
|
||||
|
||||
// The TaskRunner that ReadIcon() must be called on.
|
||||
static scoped_refptr<base::TaskRunner> GetReadIconTaskRunner();
|
||||
|
||||
void ReadGroup();
|
||||
void ReadIcon();
|
||||
|
||||
// The traits of the tasks posted by this class. These operations may block,
|
||||
// because they are fetching icons from the disk, yet the result will be seen
|
||||
// by the user so they should be prioritized accordingly.
|
||||
static constexpr base::TaskTraits traits() {
|
||||
return {base::MayBlock(), base::TaskPriority::USER_VISIBLE};
|
||||
}
|
||||
|
||||
// The task runner object of the thread in which we notify the delegate.
|
||||
scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_;
|
||||
|
||||
base::FilePath file_path_;
|
||||
|
||||
IconGroup group_;
|
||||
|
||||
IconSize icon_size_;
|
||||
|
||||
IconLoadedCallback callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IconLoader);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_ICON_LOADER_H_
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/nix/mime_util_xdg.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
|
||||
// static
|
||||
IconLoader::IconGroup IconLoader::GroupForFilepath(
|
||||
const base::FilePath& file_path) {
|
||||
return base::nix::GetFileMimeType(file_path);
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
|
||||
// ReadIcon() calls into views::LinuxUI and GTK2 code, so it must be on the UI
|
||||
// thread.
|
||||
return content::BrowserThread::GetTaskRunnerForThread(
|
||||
content::BrowserThread::UI);
|
||||
}
|
||||
|
||||
void IconLoader::ReadIcon() {
|
||||
int size_pixels = 0;
|
||||
switch (icon_size_) {
|
||||
case IconLoader::SMALL:
|
||||
size_pixels = 16;
|
||||
break;
|
||||
case IconLoader::NORMAL:
|
||||
size_pixels = 32;
|
||||
break;
|
||||
case IconLoader::LARGE:
|
||||
size_pixels = 48;
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
std::unique_ptr<gfx::Image> image;
|
||||
|
||||
views::LinuxUI* ui = views::LinuxUI::instance();
|
||||
if (ui) {
|
||||
image = std::make_unique<gfx::Image>(
|
||||
ui->GetIconForContentType(group_, size_pixels));
|
||||
if (image->IsEmpty())
|
||||
image = nullptr;
|
||||
}
|
||||
|
||||
target_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(callback_, base::Passed(&image), group_));
|
||||
delete this;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/gfx/image/image_skia_util_mac.h"
|
||||
|
||||
// static
|
||||
IconLoader::IconGroup IconLoader::GroupForFilepath(
|
||||
const base::FilePath& file_path) {
|
||||
return file_path.Extension();
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
|
||||
// NSWorkspace is thread-safe.
|
||||
return base::CreateTaskRunnerWithTraits(traits());
|
||||
}
|
||||
|
||||
void IconLoader::ReadIcon() {
|
||||
NSString* group = base::SysUTF8ToNSString(group_);
|
||||
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
|
||||
NSImage* icon = [workspace iconForFileType:group];
|
||||
|
||||
std::unique_ptr<gfx::Image> image;
|
||||
|
||||
if (icon_size_ == ALL) {
|
||||
// The NSImage already has all sizes.
|
||||
image = std::make_unique<gfx::Image>([icon retain]);
|
||||
} else {
|
||||
NSSize size = NSZeroSize;
|
||||
switch (icon_size_) {
|
||||
case IconLoader::SMALL:
|
||||
size = NSMakeSize(16, 16);
|
||||
break;
|
||||
case IconLoader::NORMAL:
|
||||
size = NSMakeSize(32, 32);
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size));
|
||||
if (!image_skia.isNull()) {
|
||||
image_skia.MakeThreadSafe();
|
||||
image = std::make_unique<gfx::Image>(image_skia);
|
||||
}
|
||||
}
|
||||
|
||||
target_task_runner_->PostTask(
|
||||
FROM_HERE, base::Bind(callback_, base::Passed(&image), group_));
|
||||
delete this;
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/display/win/dpi.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/icon_util.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
// static
|
||||
IconLoader::IconGroup IconLoader::GroupForFilepath(
|
||||
const base::FilePath& file_path) {
|
||||
if (file_path.MatchesExtension(L".exe") ||
|
||||
file_path.MatchesExtension(L".dll") ||
|
||||
file_path.MatchesExtension(L".ico")) {
|
||||
return file_path.value();
|
||||
}
|
||||
|
||||
return file_path.Extension();
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
|
||||
// Technically speaking, only a thread with COM is needed, not one that has
|
||||
// a COM STA. However, this is what is available for now.
|
||||
return base::CreateCOMSTATaskRunnerWithTraits(traits());
|
||||
}
|
||||
|
||||
void IconLoader::ReadIcon() {
|
||||
int size = 0;
|
||||
switch (icon_size_) {
|
||||
case IconLoader::SMALL:
|
||||
size = SHGFI_SMALLICON;
|
||||
break;
|
||||
case IconLoader::NORMAL:
|
||||
size = 0;
|
||||
break;
|
||||
case IconLoader::LARGE:
|
||||
size = SHGFI_LARGEICON;
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
std::unique_ptr<gfx::Image> image;
|
||||
|
||||
SHFILEINFO file_info = {0};
|
||||
if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
|
||||
sizeof(SHFILEINFO),
|
||||
SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) {
|
||||
std::unique_ptr<SkBitmap> bitmap(
|
||||
IconUtil::CreateSkBitmapFromHICON(file_info.hIcon));
|
||||
if (bitmap.get()) {
|
||||
gfx::ImageSkia image_skia(
|
||||
gfx::ImageSkiaRep(*bitmap, display::win::GetDPIScale()));
|
||||
image_skia.MakeThreadSafe();
|
||||
image = std::make_unique<gfx::Image>(image_skia);
|
||||
DestroyIcon(file_info.hIcon);
|
||||
}
|
||||
}
|
||||
|
||||
target_task_runner_->PostTask(
|
||||
FROM_HERE, base::Bind(callback_, base::Passed(&image), group_));
|
||||
delete this;
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void RunCallbackIfNotCanceled(
|
||||
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
|
||||
const IconManager::IconRequestCallback& callback,
|
||||
gfx::Image* image) {
|
||||
if (is_canceled.Run())
|
||||
return;
|
||||
callback.Run(image);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IconManager::IconManager() : weak_factory_(this) {}
|
||||
|
||||
IconManager::~IconManager() {}
|
||||
|
||||
gfx::Image* IconManager::LookupIconFromFilepath(const base::FilePath& file_path,
|
||||
IconLoader::IconSize size) {
|
||||
auto group_it = group_cache_.find(file_path);
|
||||
if (group_it == group_cache_.end())
|
||||
return nullptr;
|
||||
|
||||
CacheKey key(group_it->second, size);
|
||||
auto icon_it = icon_cache_.find(key);
|
||||
if (icon_it == icon_cache_.end())
|
||||
return nullptr;
|
||||
|
||||
return icon_it->second.get();
|
||||
}
|
||||
|
||||
base::CancelableTaskTracker::TaskId IconManager::LoadIcon(
|
||||
const base::FilePath& file_path,
|
||||
IconLoader::IconSize size,
|
||||
const IconRequestCallback& callback,
|
||||
base::CancelableTaskTracker* tracker) {
|
||||
base::CancelableTaskTracker::IsCanceledCallback is_canceled;
|
||||
base::CancelableTaskTracker::TaskId id =
|
||||
tracker->NewTrackedTaskId(&is_canceled);
|
||||
IconRequestCallback callback_runner =
|
||||
base::Bind(&RunCallbackIfNotCanceled, is_canceled, callback);
|
||||
|
||||
IconLoader* loader = IconLoader::Create(
|
||||
file_path, size,
|
||||
base::Bind(&IconManager::OnIconLoaded, weak_factory_.GetWeakPtr(),
|
||||
callback_runner, file_path, size));
|
||||
loader->Start();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void IconManager::OnIconLoaded(IconRequestCallback callback,
|
||||
base::FilePath file_path,
|
||||
IconLoader::IconSize size,
|
||||
std::unique_ptr<gfx::Image> result,
|
||||
const IconLoader::IconGroup& group) {
|
||||
// Cache the bitmap. Watch out: |result| may be null, which indicates a
|
||||
// failure. We assume that if we have an entry in |icon_cache_| it must not be
|
||||
// null.
|
||||
CacheKey key(group, size);
|
||||
if (result) {
|
||||
callback.Run(result.get());
|
||||
icon_cache_[key] = std::move(result);
|
||||
} else {
|
||||
callback.Run(nullptr);
|
||||
icon_cache_.erase(key);
|
||||
}
|
||||
|
||||
group_cache_[file_path] = group;
|
||||
}
|
||||
|
||||
IconManager::CacheKey::CacheKey(const IconLoader::IconGroup& group,
|
||||
IconLoader::IconSize size)
|
||||
: group(group), size(size) {}
|
||||
|
||||
bool IconManager::CacheKey::operator<(const CacheKey& other) const {
|
||||
return std::tie(group, size) < std::tie(other.group, other.size);
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
//
|
||||
// Class for finding and caching Windows explorer icons. The IconManager
|
||||
// lives on the UI thread but performs icon extraction work on the file thread
|
||||
// to avoid blocking the UI thread with potentially expensive COM and disk
|
||||
// operations.
|
||||
//
|
||||
// Terminology
|
||||
//
|
||||
// Windows files have icons associated with them that can be of two types:
|
||||
// 1. "Per class": the icon used for this file is used for all files with the
|
||||
// same file extension or class. Examples are PDF or MP3 files, which use
|
||||
// the same icon for all files of that type.
|
||||
// 2. "Per instance": the icon used for this file is embedded in the file
|
||||
// itself and is unique. Executable files are typically "per instance".
|
||||
//
|
||||
// Files that end in the following extensions are considered "per instance":
|
||||
// .exe
|
||||
// .dll
|
||||
// .ico
|
||||
// The IconManager will do explicit icon loads on the full path of these files
|
||||
// and cache the results per file. All other file types will be looked up by
|
||||
// file extension and the results will be cached per extension. That way, all
|
||||
// .mp3 files will share one icon, but all .exe files will have their own icon.
|
||||
//
|
||||
// POSIX files don't have associated icons. We query the OS by the file's
|
||||
// mime type.
|
||||
//
|
||||
// The IconManager can be queried in two ways:
|
||||
// 1. A quick, synchronous check of its caches which does not touch the disk:
|
||||
// IconManager::LookupIcon()
|
||||
// 2. An asynchronous icon load from a file on the file thread:
|
||||
// IconManager::LoadIcon()
|
||||
//
|
||||
// When using the second (asynchronous) method, callers must supply a callback
|
||||
// which will be run once the icon has been extracted. The icon manager will
|
||||
// cache the results of the icon extraction so that subsequent lookups will be
|
||||
// fast.
|
||||
//
|
||||
// Icon bitmaps returned should be treated as const since they may be referenced
|
||||
// by other clients. Make a copy of the icon if you need to modify it.
|
||||
|
||||
#ifndef CHROME_BROWSER_ICON_MANAGER_H_
|
||||
#define CHROME_BROWSER_ICON_MANAGER_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/task/cancelable_task_tracker.h"
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
class IconManager {
|
||||
public:
|
||||
IconManager();
|
||||
~IconManager();
|
||||
|
||||
// Synchronous call to examine the internal caches for the icon. Returns the
|
||||
// icon if we have already loaded it, or null if we don't have it and must
|
||||
// load it via LoadIcon(). The returned bitmap is owned by the IconManager and
|
||||
// must not be free'd by the caller. If the caller needs to modify the icon,
|
||||
// it must make a copy and modify the copy.
|
||||
gfx::Image* LookupIconFromFilepath(const base::FilePath& file_path,
|
||||
IconLoader::IconSize size);
|
||||
|
||||
using IconRequestCallback = base::Callback<void(gfx::Image*)>;
|
||||
|
||||
// Asynchronous call to lookup and return the icon associated with file. The
|
||||
// work is done on the file thread, with the callbacks running on the thread
|
||||
// this function is called.
|
||||
//
|
||||
// Note:
|
||||
// 1. This does *not* check the cache.
|
||||
// 2. The returned bitmap pointer is *not* owned by callback. So callback
|
||||
// should never keep it or delete it.
|
||||
// 3. The gfx::Image pointer passed to the callback will be null if decoding
|
||||
// failed.
|
||||
base::CancelableTaskTracker::TaskId LoadIcon(
|
||||
const base::FilePath& file_name,
|
||||
IconLoader::IconSize size,
|
||||
const IconRequestCallback& callback,
|
||||
base::CancelableTaskTracker* tracker);
|
||||
|
||||
private:
|
||||
void OnIconLoaded(IconRequestCallback callback,
|
||||
base::FilePath file_path,
|
||||
IconLoader::IconSize size,
|
||||
std::unique_ptr<gfx::Image> result,
|
||||
const IconLoader::IconGroup& group);
|
||||
|
||||
struct CacheKey {
|
||||
CacheKey(const IconLoader::IconGroup& group, IconLoader::IconSize size);
|
||||
|
||||
// Used as a key in the map below, so we need this comparator.
|
||||
bool operator<(const CacheKey& other) const;
|
||||
|
||||
IconLoader::IconGroup group;
|
||||
IconLoader::IconSize size;
|
||||
};
|
||||
|
||||
std::map<base::FilePath, IconLoader::IconGroup> group_cache_;
|
||||
std::map<CacheKey, std::unique_ptr<gfx::Image>> icon_cache_;
|
||||
|
||||
base::WeakPtrFactory<IconManager> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IconManager);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_ICON_MANAGER_H_
|
Loading…
Add table
Add a link
Reference in a new issue