Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1867)

Unified Diff: chrome/browser/icon_loader.h

Issue 2577273002: Clean up IconLoader. (Closed)
Patch Set: bind Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/icon_loader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/icon_loader.h
diff --git a/chrome/browser/icon_loader.h b/chrome/browser/icon_loader.h
index b2db32545cc1721a00cafc7d9c4e35cf62092785..50d9ef45410dfe754d9d5246f9c072a1ccd346ce 100644
--- a/chrome/browser/icon_loader.h
+++ b/chrome/browser/icon_loader.h
@@ -8,9 +8,9 @@
#include <memory>
#include <string>
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
@@ -22,7 +22,7 @@
// thread. Returns the icon in the form of an ImageSkia.
//
////////////////////////////////////////////////////////////////////////////////
-class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
+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
@@ -39,30 +39,29 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
ALL, // All sizes available
};
- class Delegate {
- public:
- // Invoked when an icon has been read. |source| is the IconLoader. If the
- // icon has been successfully loaded, |result| is non-null. |group| is the
- // determined group from the original requested path.
- virtual void OnImageLoaded(IconLoader* source,
- std::unique_ptr<gfx::Image> result,
- const IconGroup& group) = 0;
-
- protected:
- virtual ~Delegate() {}
- };
-
- IconLoader(const base::FilePath& file_path,
- IconSize size,
- Delegate* delegate);
-
- // Start reading the icon on the file thread.
+ // 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:
- friend class base::RefCountedThreadSafe<IconLoader>;
+ IconLoader(const base::FilePath& file_path,
+ IconSize size,
+ IconLoadedCallback callback);
- virtual ~IconLoader();
+ ~IconLoader();
// Given a file path, get the group for the given file.
static IconGroup GroupForFilepath(const base::FilePath& file_path);
@@ -74,8 +73,6 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
void OnReadGroup();
void ReadIcon();
- void NotifyDelegate();
-
// The task runner object of the thread in which we notify the delegate.
scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_;
@@ -87,7 +84,7 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
std::unique_ptr<gfx::Image> image_;
- Delegate* delegate_;
+ IconLoadedCallback callback_;
DISALLOW_COPY_AND_ASSIGN(IconLoader);
};
« no previous file with comments | « no previous file | chrome/browser/icon_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698