diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index caaee9d25cb3..5f878aace1c6 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -30,6 +30,7 @@ #include "base/path_service.h" #include "base/strings/string_util.h" #include "brightray/browser/brightray_paths.h" +#include "chrome/browser/icon_manager.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_accessibility_state.h" #include "content/public/browser/client_certificate_delegate.h" @@ -314,6 +315,26 @@ struct Converter { } }; +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + IconLoader::IconSize* out) { + std::string icon_size_string; + if (!ConvertFromV8(isolate, val, &icon_size_string)) + return false; + if (icon_size_string == "small") + *out = IconLoader::IconSize::SMALL; + else if (icon_size_string == "normal") + *out = IconLoader::IconSize::NORMAL; + else if (icon_size_string == "large") + *out = IconLoader::IconSize::LARGE; + else + return false; + return true; + } +}; + template<> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, @@ -462,6 +483,11 @@ int ImportIntoCertStore( } #endif +void OnIconDataAvailable(const App::FileIconCallback& callback, + gfx::Image* icon) { + callback.Run(icon ? *icon : gfx::Image()); +} + } // namespace App::App(v8::Isolate* isolate) { @@ -841,6 +867,19 @@ JumpListResult App::SetJumpList(v8::Local val, } #endif // defined(OS_WIN) +void App::GetFileIcon(const base::FilePath& path, + IconLoader::IconSize icon_size, + const FileIconCallback& callback) { + IconManager* icon_manager = IconManager::GetInstance(); + gfx::Image* icon = icon_manager->LookupIconFromFilepath(path, icon_size); + if (icon) { + callback.Run(*icon); + } else { + icon_manager->LoadIcon(path, icon_size, + base::Bind(&OnIconDataAvailable, callback)); + } +} + // static mate::Handle App::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new App(isolate)); @@ -909,7 +948,8 @@ void App::BuildPrototype( .SetMethod("isAccessibilitySupportEnabled", &App::IsAccessibilitySupportEnabled) .SetMethod("disableHardwareAcceleration", - &App::DisableHardwareAcceleration); + &App::DisableHardwareAcceleration) + .SetMethod("getFileIcon", &App::GetFileIcon); } } // namespace api diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index c7e62927c594..b42b201fff36 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -13,6 +13,7 @@ #include "atom/browser/browser.h" #include "atom/browser/browser_observer.h" #include "atom/common/native_mate_converters/callback.h" +#include "chrome/browser/icon_loader.h" #include "chrome/browser/process_singleton.h" #include "content/public/browser/gpu_data_manager_observer.h" #include "native_mate/handle.h" @@ -43,6 +44,8 @@ class App : public AtomBrowserClient::Delegate, public BrowserObserver, public content::GpuDataManagerObserver { public: + using FileIconCallback = base::Callback; + static mate::Handle Create(v8::Isolate* isolate); static void BuildPrototype(v8::Isolate* isolate, @@ -129,6 +132,9 @@ class App : public AtomBrowserClient::Delegate, void ImportCertificate(const base::DictionaryValue& options, const net::CompletionCallback& callback); #endif + void GetFileIcon(const base::FilePath& path, + IconLoader::IconSize icon_size, + const FileIconCallback& callback); #if defined(OS_WIN) // Get the current Jump List settings. diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 33c38eac00e4..1d4e20e3cfc8 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -17,7 +17,6 @@ #include "base/files/file_util.h" #include "base/strings/pattern.h" #include "base/strings/string_util.h" -#include "atom/common/fileicon_fetcher.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "net/base/data_url.h" @@ -303,23 +302,6 @@ gfx::Size NativeImage::GetSize() { return image_.Size(); } -void NativeImage::CreateFromFileIcon(v8::Isolate* isolate, - const base::FilePath& path, - const IconLoadedCallback& callback) { - IconLoader::IconSize icon_size = IconLoader::IconSize::NORMAL; - float scale_factor = 1.0f; - auto onready = base::Bind(&NativeImage::OnIconLoaded, - base::Unretained(isolate), - callback); - FileIconFetcher::FetchFileIcon(path, scale_factor, icon_size, onready); -} - -void NativeImage::OnIconLoaded(v8::Isolate* isolate, - const IconLoadedCallback& callback, - gfx::Image& image) { - callback.Run(Create(isolate, image)); -} - float NativeImage::GetAspectRatio() { gfx::Size size = GetSize(); if (size.IsEmpty()) @@ -533,8 +515,6 @@ void Initialize(v8::Local exports, v8::Local unused, mate::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("createEmpty", &atom::api::NativeImage::CreateEmpty); dict.SetMethod("createFromPath", &atom::api::NativeImage::CreateFromPath); - dict.SetMethod("createFromFileIcon", - &atom::api::NativeImage::CreateFromFileIcon); dict.SetMethod("createFromBuffer", &atom::api::NativeImage::CreateFromBuffer); dict.SetMethod("createFromDataURL", &atom::api::NativeImage::CreateFromDataURL); diff --git a/atom/common/api/atom_api_native_image.h b/atom/common/api/atom_api_native_image.h index 2b8cbf7a2ed2..ee1b5f5d4b81 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -38,7 +38,6 @@ namespace atom { namespace api { class NativeImage : public mate::Wrappable { - using IconLoadedCallback = base::Callback)>; public: static mate::Handle CreateEmpty(v8::Isolate* isolate); static mate::Handle Create( @@ -53,9 +52,6 @@ class NativeImage : public mate::Wrappable { mate::Arguments* args, v8::Local buffer); static mate::Handle CreateFromDataURL( v8::Isolate* isolate, const GURL& url); - static void CreateFromFileIcon(v8::Isolate* isolate, - const base::FilePath& path, - const IconLoadedCallback& callback); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -90,9 +86,6 @@ class NativeImage : public mate::Wrappable { gfx::Size GetSize(); float GetAspectRatio(); - static void OnIconLoaded(v8::Isolate* isolate, - const IconLoadedCallback& callback, - gfx::Image& image); // Mark the image as template image. void SetTemplateImage(bool setAsTemplate); // Determine if the image is a template image. diff --git a/atom/common/fileicon_fetcher.cc b/atom/common/fileicon_fetcher.cc deleted file mode 100644 index a0b3b73808ef..000000000000 --- a/atom/common/fileicon_fetcher.cc +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2016 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/common/fileicon_fetcher.h" - -#include "base/bind.h" -#include "base/callback.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted_memory.h" -#include "base/message_loop/message_loop.h" -#include "base/strings/string_split.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "net/base/escape.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/webui/web_ui_util.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_skia.h" -#include "url/gurl.h" - -void FileIconFetcher::FetchFileIcon(const base::FilePath& path, - float scale_factor, - IconLoader::IconSize icon_size, - const IconFetchedCallback& callback) { - IconManager* im = g_browser_process->icon_manager(); - gfx::Image* icon = im->LookupIconFromFilepath(path, icon_size); - - if (icon) { - scoped_refptr icon_data(new base::RefCountedBytes); - gfx::PNGCodec::EncodeBGRASkBitmap( - icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(), - false, - &icon_data->data()); - - callback.Run(icon_data.get()); - } else { - // Attach the ChromeURLDataManager request ID to the history request. - IconRequestDetails details; - details.callback = callback; - details.scale_factor = scale_factor; - - // Icon was not in cache, go fetch it slowly. - im->LoadIcon(path, - icon_size, - base::Bind(&FileIconFetcher::OnFileIconDataAvailable, details), - &cancelable_task_tracker_); - } -} - -void FileIconFetcher::OnFileIconDataAvailable(const IconRequestDetails& details, - gfx::Image* icon) { - if (icon) { - scoped_refptr icon_data(new base::RefCountedBytes); - gfx::PNGCodec::EncodeBGRASkBitmap( - icon->ToImageSkia()->GetRepresentation( - details.scale_factor).sk_bitmap(), - false, - &icon_data->data()); - - details.callback.Run(icon_data.get()); - } else { - details.callback.Run(NULL); - } -} - - -FileIconFetcher::IconRequestDetails::IconRequestDetails() : scale_factor(1.0f) { -} - -FileIconFetcher::IconRequestDetails::IconRequestDetails( - const IconRequestDetails& other) = default; - -FileIconFetcher::IconRequestDetails::~IconRequestDetails() { -} diff --git a/atom/common/fileicon_fetcher.h b/atom/common/fileicon_fetcher.h deleted file mode 100644 index f8b0024126f6..000000000000 --- a/atom/common/fileicon_fetcher.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2016 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_API_FILEICON_FETCHER_H_ -#define ATOM_COMMON_API_FILEICON_FETCHER_H_ - -#include - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/task/cancelable_task_tracker.h" -#include "chrome/browser/icon_manager.h" -#include "content/public/browser/url_data_source.h" - -namespace gfx { -class Image; -} - -class FileIconFetcher { - using IconFetchedCallback = base::Callback; - public: - static void FetchFileIcon(const base::FilePath& path, - float scale_factor, - IconLoader::IconSize icon_size, - const IconFetchedCallback& callback); - - private: - struct IconRequestDetails { - IconRequestDetails(); - IconRequestDetails(const IconRequestDetails& other); - ~IconRequestDetails(); - - // The callback to run with the response. - IconFetchedCallback callback; - - // The requested scale factor to respond with. - float scale_factor; - }; - // Called when favicon data is available from the history backend. - static void OnFileIconDataAvailable(const IconRequestDetails& details, - gfx::Image* icon); - - // Tracks tasks requesting file icons. - static base::CancelableTaskTracker cancelable_task_tracker_; -}; - -#endif // ATOM_COMMON_API_FILEICON_FETCHER_H_ diff --git a/chromium_src/chrome/browser/browser_process.cc b/chromium_src/chrome/browser/browser_process.cc index bed32469a6c0..a38d55f87159 100644 --- a/chromium_src/chrome/browser/browser_process.cc +++ b/chromium_src/chrome/browser/browser_process.cc @@ -5,7 +5,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/printing/print_job_manager.h" -#include "chrome/browser/icon_manager.h" #include "ui/base/l10n/l10n_util.h" BrowserProcess* g_browser_process = NULL; @@ -13,8 +12,6 @@ BrowserProcess* g_browser_process = NULL; BrowserProcess::BrowserProcess() : print_job_manager_(new printing::PrintJobManager) { g_browser_process = this; - - icon_manager_.reset(new IconManager); } BrowserProcess::~BrowserProcess() { @@ -28,7 +25,3 @@ std::string BrowserProcess::GetApplicationLocale() { printing::PrintJobManager* BrowserProcess::print_job_manager() { return print_job_manager_.get(); } - -IconManager* BrowserProcess::icon_manager() { - return icon_manager_.get(); -} diff --git a/chromium_src/chrome/browser/browser_process.h b/chromium_src/chrome/browser/browser_process.h index 9f28045c387c..a21371efb2ba 100644 --- a/chromium_src/chrome/browser/browser_process.h +++ b/chromium_src/chrome/browser/browser_process.h @@ -31,11 +31,9 @@ class BrowserProcess { std::string GetApplicationLocale(); printing::PrintJobManager* print_job_manager(); - IconManager* icon_manager(); private: std::unique_ptr print_job_manager_; - std::unique_ptr icon_manager_; DISALLOW_COPY_AND_ASSIGN(BrowserProcess); }; diff --git a/chromium_src/chrome/browser/icon_loader.cc b/chromium_src/chrome/browser/icon_loader.cc index 979ee5772c15..afc5d8016ea0 100644 --- a/chromium_src/chrome/browser/icon_loader.cc +++ b/chromium_src/chrome/browser/icon_loader.cc @@ -18,15 +18,14 @@ IconLoader::IconLoader(const base::FilePath& file_path, icon_size_(size), delegate_(delegate) {} -IconLoader::~IconLoader() { -} +IconLoader::~IconLoader() {} void IconLoader::Start() { target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, - base::Bind(&IconLoader::ReadGroup, this), - base::Bind(&IconLoader::OnReadGroup, this)); + base::Bind(&IconLoader::ReadGroup, this), + base::Bind(&IconLoader::OnReadGroup, this)); } void IconLoader::ReadGroup() { @@ -37,7 +36,7 @@ void IconLoader::OnReadGroup() { if (IsIconMutableFromFilepath(file_path_) || !delegate_->OnGroupLoaded(this, group_)) { BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE, - base::Bind(&IconLoader::ReadIcon, this)); + base::Bind(&IconLoader::ReadIcon, this)); } } diff --git a/chromium_src/chrome/browser/icon_loader_auralinux.cc b/chromium_src/chrome/browser/icon_loader_auralinux.cc new file mode 100644 index 000000000000..2a1b0d868f47 --- /dev/null +++ b/chromium_src/chrome/browser/icon_loader_auralinux.cc @@ -0,0 +1,55 @@ +// 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 +IconGroupID IconLoader::ReadGroupIDFromFilepath( + const base::FilePath& filepath) { + return base::nix::GetFileMimeType(filepath); +} + +// static +bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) { + return false; +} + +// static +content::BrowserThread::ID IconLoader::ReadIconThreadID() { + // ReadIcon() calls into views::LinuxUI and GTK2 code, so it must be on the UI + // thread. + return 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(); + } + + views::LinuxUI* ui = views::LinuxUI::instance(); + if (ui) { + gfx::Image image = ui->GetIconForContentType(group_, size_pixels); + if (!image.IsEmpty()) + image_.reset(new gfx::Image(image)); + } + + target_task_runner_->PostTask(FROM_HERE, + base::Bind(&IconLoader::NotifyDelegate, this)); +} diff --git a/chromium_src/chrome/browser/icon_loader_mac.mm b/chromium_src/chrome/browser/icon_loader_mac.mm new file mode 100644 index 000000000000..a9dd42566b9e --- /dev/null +++ b/chromium_src/chrome/browser/icon_loader_mac.mm @@ -0,0 +1,62 @@ +// 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 + +#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/threading/thread.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_util_mac.h" + +// static +IconGroupID IconLoader::ReadGroupIDFromFilepath( + const base::FilePath& filepath) { + return filepath.Extension(); +} + +// static +bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) { + return false; +} + +// static +content::BrowserThread::ID IconLoader::ReadIconThreadID() { + return content::BrowserThread::FILE; +} + +void IconLoader::ReadIcon() { + NSString* group = base::SysUTF8ToNSString(group_); + NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; + NSImage* icon = [workspace iconForFileType:group]; + + if (icon_size_ == ALL) { + // The NSImage already has all sizes. + image_.reset(new 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_.reset(new gfx::Image(image_skia)); + } + } + + target_task_runner_->PostTask(FROM_HERE, + base::Bind(&IconLoader::NotifyDelegate, this)); +} diff --git a/chromium_src/chrome/browser/icon_loader_win.cc b/chromium_src/chrome/browser/icon_loader_win.cc new file mode 100644 index 000000000000..079c1f4828d2 --- /dev/null +++ b/chromium_src/chrome/browser/icon_loader_win.cc @@ -0,0 +1,75 @@ +// 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 +#include + +#include "base/bind.h" +#include "base/message_loop/message_loop.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 +IconGroupID IconLoader::ReadGroupIDFromFilepath( + const base::FilePath& filepath) { + if (!IsIconMutableFromFilepath(filepath)) + return filepath.Extension(); + return filepath.value(); +} + +// static +bool IconLoader::IsIconMutableFromFilepath(const base::FilePath& filepath) { + return filepath.MatchesExtension(L".exe") || + filepath.MatchesExtension(L".dll") || + filepath.MatchesExtension(L".ico"); +} + +// static +content::BrowserThread::ID IconLoader::ReadIconThreadID() { + return content::BrowserThread::FILE; +} + +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(); + } + + image_.reset(); + + SHFILEINFO file_info = {0}; + if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, + sizeof(SHFILEINFO), + SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) { + std::unique_ptr bitmap( + IconUtil::CreateSkBitmapFromHICON(file_info.hIcon)); + if (bitmap.get()) { + gfx::ImageSkia image_skia( + gfx::ImageSkiaRep(*bitmap, display::win::GetDPIScale())); + image_skia.MakeThreadSafe(); + image_.reset(new gfx::Image(image_skia)); + DestroyIcon(file_info.hIcon); + } + } + + // Always notify the delegate, regardless of success. + target_task_runner_->PostTask(FROM_HERE, + base::Bind(&IconLoader::NotifyDelegate, this)); +} diff --git a/chromium_src/chrome/browser/icon_manager.cc b/chromium_src/chrome/browser/icon_manager.cc index 6596ab311234..17e362c534f3 100644 --- a/chromium_src/chrome/browser/icon_manager.cc +++ b/chromium_src/chrome/browser/icon_manager.cc @@ -13,30 +13,21 @@ #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 - struct IconManager::ClientRequest { IconRequestCallback callback; base::FilePath file_path; IconLoader::IconSize size; }; -IconManager::IconManager() { +// static +IconManager* IconManager::GetInstance() { + return base::Singleton::get(); } +IconManager::IconManager() {} + IconManager::~IconManager() { - base::STLDeleteValues(&icon_cache_); + STLDeleteValues(&icon_cache_); } gfx::Image* IconManager::LookupIconFromFilepath(const base::FilePath& file_name, @@ -54,33 +45,23 @@ gfx::Image* IconManager::LookupIconFromGroup(const IconGroupID& group, if (it != icon_cache_.end()) return it->second; - return NULL; + return nullptr; } -base::CancelableTaskTracker::TaskId IconManager::LoadIcon( - const base::FilePath& file_name, - IconLoader::IconSize size, - const IconRequestCallback& callback, - base::CancelableTaskTracker* tracker) { +void IconManager::LoadIcon(const base::FilePath& file_name, + IconLoader::IconSize size, + const IconRequestCallback& callback) { IconLoader* loader = new IconLoader(file_name, size, this); loader->AddRef(); loader->Start(); - base::CancelableTaskTracker::IsCanceledCallback is_canceled; - base::CancelableTaskTracker::TaskId id = - tracker->NewTrackedTaskId(&is_canceled); - IconRequestCallback callback_runner = base::Bind( - &RunCallbackIfNotCanceled, is_canceled, callback); - - ClientRequest client_request = { callback_runner, file_name, size }; + ClientRequest client_request = {callback, file_name, size}; requests_[loader] = client_request; - return id; } // IconLoader::Delegate implementation ----------------------------------------- -bool IconManager::OnGroupLoaded(IconLoader* loader, - const IconGroupID& group) { +bool IconManager::OnGroupLoaded(IconLoader* loader, const IconGroupID& group) { ClientRequests::iterator rit = requests_.find(loader); if (rit == requests_.end()) { NOTREACHED(); @@ -95,8 +76,9 @@ bool IconManager::OnGroupLoaded(IconLoader* loader, return OnImageLoaded(loader, result, group); } -bool IconManager::OnImageLoaded( - IconLoader* loader, gfx::Image* result, const IconGroupID& group) { +bool IconManager::OnImageLoaded(IconLoader* loader, + gfx::Image* result, + const IconGroupID& group) { ClientRequests::iterator rit = requests_.find(loader); // Balances the AddRef() in LoadIcon(). @@ -139,10 +121,8 @@ bool IconManager::OnImageLoaded( IconManager::CacheKey::CacheKey(const IconGroupID& group, IconLoader::IconSize size) - : group(group), - size(size) { -} + : group(group), size(size) {} -bool IconManager::CacheKey::operator<(const CacheKey &other) const { +bool IconManager::CacheKey::operator<(const CacheKey& other) const { return std::tie(group, size) < std::tie(other.group, other.size); } diff --git a/chromium_src/chrome/browser/icon_manager.h b/chromium_src/chrome/browser/icon_manager.h index 0b5ec07d4161..dd6de8252756 100644 --- a/chromium_src/chrome/browser/icon_manager.h +++ b/chromium_src/chrome/browser/icon_manager.h @@ -49,15 +49,13 @@ #include "base/files/file_path.h" #include "base/macros.h" -#include "base/task/cancelable_task_tracker.h" +#include "base/memory/singleton.h" #include "chrome/browser/icon_loader.h" #include "ui/gfx/image/image.h" class IconManager : public IconLoader::Delegate { public: - IconManager(); - ~IconManager() override; - + static IconManager* GetInstance(); // Synchronous call to examine the internal caches for the icon. Returns the // icon if we have already loaded it, NULL if we don't have it and must load // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must @@ -78,11 +76,9 @@ class IconManager : public IconLoader::Delegate { // should never keep it or delete it. // 3. The gfx::Image pointer passed to the callback may be NULL if decoding // failed. - base::CancelableTaskTracker::TaskId LoadIcon( - const base::FilePath& file_name, - IconLoader::IconSize size, - const IconRequestCallback& callback, - base::CancelableTaskTracker* tracker); + void LoadIcon(const base::FilePath& file_name, + IconLoader::IconSize size, + const IconRequestCallback& callback); // IconLoader::Delegate interface. bool OnGroupLoaded(IconLoader* loader, const IconGroupID& group) override; @@ -91,11 +87,16 @@ class IconManager : public IconLoader::Delegate { const IconGroupID& group) override; private: + friend struct base::DefaultSingletonTraits; + + IconManager(); + ~IconManager() override; + struct CacheKey { CacheKey(const IconGroupID& group, IconLoader::IconSize size); // Used as a key in the map below, so we need this comparator. - bool operator<(const CacheKey &other) const; + bool operator<(const CacheKey& other) const; IconGroupID group; IconLoader::IconSize size; diff --git a/filenames.gypi b/filenames.gypi index 232fd66666c7..74cef968cd68 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -404,8 +404,6 @@ 'atom/common/crash_reporter/win/crash_service_main.h', 'atom/common/draggable_region.cc', 'atom/common/draggable_region.h', - 'atom/common/fileicon_fetcher.cc', - 'atom/common/fileicon_fetcher.h', 'atom/common/google_api_key.h', 'atom/common/key_weak_map.h', 'atom/common/keyboard_util.cc', @@ -476,11 +474,14 @@ 'chromium_src/chrome/browser/browser_process.h', 'chromium_src/chrome/browser/chrome_process_finder_win.cc', 'chromium_src/chrome/browser/chrome_process_finder_win.h', - 'chromium_src/chrome/browser/chrome_notification_types.h', + 'chromium_src/chrome/browser/icon_loader_auralinux.cc', + 'chromium_src/chrome/browser/icon_loader_mac.mm', + 'chromium_src/chrome/browser/icon_loader_win.cc', 'chromium_src/chrome/browser/icon_loader.cc', 'chromium_src/chrome/browser/icon_loader.h', 'chromium_src/chrome/browser/icon_manager.cc', 'chromium_src/chrome/browser/icon_manager.h', + 'chromium_src/chrome/browser/chrome_notification_types.h', 'chromium_src/chrome/browser/extensions/global_shortcut_listener.cc', 'chromium_src/chrome/browser/extensions/global_shortcut_listener.h', 'chromium_src/chrome/browser/extensions/global_shortcut_listener_mac.mm',