Remove no longer needed toolbar layer method.
[chromium-blink-merge.git] / chrome / browser / icon_loader.h
blob0e48a45fe33a3bf798aaeff14393ac01f0e81a4a
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ICON_LOADER_H_
6 #define CHROME_BROWSER_ICON_LOADER_H_
8 #include "build/build_config.h"
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop_proxy.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "ui/gfx/image/image.h"
20 #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.
23 typedef std::wstring IconGroupID;
24 #elif defined(OS_POSIX)
25 // On POSIX, we group files by MIME type.
26 typedef std::string IconGroupID;
27 #endif
29 ////////////////////////////////////////////////////////////////////////////////
31 // A facility to read a file containing an icon asynchronously in the IO
32 // thread. Returns the icon in the form of an ImageSkia.
34 ////////////////////////////////////////////////////////////////////////////////
35 class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
36 public:
37 enum IconSize {
38 SMALL = 0, // 16x16
39 NORMAL, // 32x32
40 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
41 ALL, // All sizes available
44 class Delegate {
45 public:
46 // 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;
51 // 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
53 // return true if it is taking ownership of the returned image.
54 virtual bool OnImageLoaded(IconLoader* source,
55 gfx::Image* result,
56 const IconGroupID& group) = 0;
58 protected:
59 virtual ~Delegate() {}
62 IconLoader(const base::FilePath& file_path,
63 IconSize size,
64 Delegate* delegate);
66 // Start reading the icon on the file thread.
67 void Start();
69 private:
70 friend class base::RefCountedThreadSafe<IconLoader>;
72 virtual ~IconLoader();
74 // 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);
78 // Some icons (exe's on windows) can change as they're loaded.
79 static bool IsIconMutableFromFilepath(const base::FilePath& path);
81 // The thread ReadIcon() should be called on.
82 static content::BrowserThread::ID ReadIconThreadID();
84 void ReadGroup();
85 void OnReadGroup();
86 void ReadIcon();
88 void NotifyDelegate();
90 // The message loop object of the thread in which we notify the delegate.
91 scoped_refptr<base::MessageLoopProxy> target_message_loop_;
93 base::FilePath file_path_;
95 IconGroupID group_;
97 IconSize icon_size_;
99 scoped_ptr<gfx::Image> image_;
101 Delegate* delegate_;
103 DISALLOW_COPY_AND_ASSIGN(IconLoader);
106 #endif // CHROME_BROWSER_ICON_LOADER_H_