blob: 52df888dac209283a3821dbfccfa1f0ec785dca9 [file] [log] [blame]
[email protected]679facce2012-07-25 16:13:121// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]7ced67af2009-04-14 23:25:165#ifndef CHROME_BROWSER_ICON_LOADER_H_
6#define CHROME_BROWSER_ICON_LOADER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]864b1362010-08-19 03:49:388#include "build/build_config.h"
9
initial.commit09911bf2008-07-26 23:55:2910#include <string>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]56d01f62009-03-12 22:41:5412#include "base/basictypes.h"
[email protected]bc0147b2013-04-03 20:50:5913#include "base/files/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
15#include "base/memory/scoped_ptr.h"
pranay.kumar4b8db4d2015-04-29 11:12:0416#include "base/single_thread_task_runner.h"
[email protected]b3b6a372014-03-12 01:48:0417#include "content/public/browser/browser_thread.h"
[email protected]f08e0512011-06-13 18:10:4418#include "ui/gfx/image/image.h"
[email protected]982735c22010-10-29 13:58:5719
[email protected]0f38ceae2009-05-08 19:01:0220#if defined(OS_WIN)
21// On Windows, we group files by their extension, with several exceptions:
22// .dll, .exe, .ico. See IconManager.h for explanation.
23typedef std::wstring IconGroupID;
24#elif defined(OS_POSIX)
25// On POSIX, we group files by MIME type.
26typedef std::string IconGroupID;
27#endif
28
initial.commit09911bf2008-07-26 23:55:2929////////////////////////////////////////////////////////////////////////////////
30//
31// A facility to read a file containing an icon asynchronously in the IO
[email protected]679facce2012-07-25 16:13:1232// thread. Returns the icon in the form of an ImageSkia.
initial.commit09911bf2008-07-26 23:55:2933//
34////////////////////////////////////////////////////////////////////////////////
[email protected]46728b1f2009-05-07 20:42:2435class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
initial.commit09911bf2008-07-26 23:55:2936 public:
initial.commit09911bf2008-07-26 23:55:2937 enum IconSize {
38 SMALL = 0, // 16x16
39 NORMAL, // 32x32
[email protected]955c37b2011-06-08 21:26:3040 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
41 ALL, // All sizes available
initial.commit09911bf2008-07-26 23:55:2942 };
43
44 class Delegate {
45 public:
[email protected]bc0147b2013-04-03 20:50:5946 // Invoked when an icon group has been read, but before the icon data
47 // is read. If the icon is already cached, this method should call and
48 // return the results of OnImageLoaded with the cached image.
49 virtual bool OnGroupLoaded(IconLoader* source,
50 const IconGroupID& group) = 0;
initial.commit09911bf2008-07-26 23:55:2951 // Invoked when an icon has been read. |source| is the IconLoader. If the
52 // icon has been successfully loaded, result is non-null. This method must
[email protected]679facce2012-07-25 16:13:1253 // return true if it is taking ownership of the returned image.
[email protected]bc0147b2013-04-03 20:50:5954 virtual bool OnImageLoaded(IconLoader* source,
55 gfx::Image* result,
56 const IconGroupID& group) = 0;
[email protected]135fd3b62009-12-16 01:07:0857
58 protected:
59 virtual ~Delegate() {}
initial.commit09911bf2008-07-26 23:55:2960 };
61
[email protected]bc0147b2013-04-03 20:50:5962 IconLoader(const base::FilePath& file_path,
63 IconSize size,
64 Delegate* delegate);
initial.commit09911bf2008-07-26 23:55:2965
[email protected]46728b1f2009-05-07 20:42:2466 // Start reading the icon on the file thread.
[email protected]0f38ceae2009-05-08 19:01:0267 void Start();
initial.commit09911bf2008-07-26 23:55:2968
69 private:
[email protected]e6e6ba42009-11-07 01:56:1970 friend class base::RefCountedThreadSafe<IconLoader>;
71
72 virtual ~IconLoader();
73
[email protected]bc0147b2013-04-03 20:50:5974 // Get the identifying string for the given file. The implementation
75 // is in icon_loader_[platform].cc.
76 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path);
77
[email protected]681b4b82013-04-09 23:34:2178 // Some icons (exe's on windows) can change as they're loaded.
79 static bool IsIconMutableFromFilepath(const base::FilePath& path);
80
[email protected]b3b6a372014-03-12 01:48:0481 // The thread ReadIcon() should be called on.
82 static content::BrowserThread::ID ReadIconThreadID();
83
[email protected]bc0147b2013-04-03 20:50:5984 void ReadGroup();
85 void OnReadGroup();
[email protected]0f38ceae2009-05-08 19:01:0286 void ReadIcon();
87
88 void NotifyDelegate();
89
pranay.kumar4b8db4d2015-04-29 11:12:0490 // The task runner object of the thread in which we notify the delegate.
91 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_;
[email protected]0f38ceae2009-05-08 19:01:0292
[email protected]bc0147b2013-04-03 20:50:5993 base::FilePath file_path_;
94
[email protected]0f38ceae2009-05-08 19:01:0295 IconGroupID group_;
96
97 IconSize icon_size_;
98
[email protected]66171ab2011-03-03 15:50:0799 scoped_ptr<gfx::Image> image_;
[email protected]0f38ceae2009-05-08 19:01:02100
101 Delegate* delegate_;
102
[email protected]7ced67af2009-04-14 23:25:16103 DISALLOW_COPY_AND_ASSIGN(IconLoader);
initial.commit09911bf2008-07-26 23:55:29104};
105
[email protected]7ced67af2009-04-14 23:25:16106#endif // CHROME_BROWSER_ICON_LOADER_H_