Remove the dependency of PasswordStore on BrowserContextKeyedService
[chromium-blink-merge.git] / chrome / browser / icon_loader.h
blobef602128276df9465020585112b8a6785a44703b
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 "ui/gfx/image/image.h"
19 #if defined(OS_WIN)
20 // On Windows, we group files by their extension, with several exceptions:
21 // .dll, .exe, .ico. See IconManager.h for explanation.
22 typedef std::wstring IconGroupID;
23 #elif defined(OS_POSIX)
24 // On POSIX, we group files by MIME type.
25 typedef std::string IconGroupID;
26 #endif
28 ////////////////////////////////////////////////////////////////////////////////
30 // A facility to read a file containing an icon asynchronously in the IO
31 // thread. Returns the icon in the form of an ImageSkia.
33 ////////////////////////////////////////////////////////////////////////////////
34 class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
35 public:
36 enum IconSize {
37 SMALL = 0, // 16x16
38 NORMAL, // 32x32
39 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
40 ALL, // All sizes available
43 class Delegate {
44 public:
45 // Invoked when an icon group has been read, but before the icon data
46 // is read. If the icon is already cached, this method should call and
47 // return the results of OnImageLoaded with the cached image.
48 virtual bool OnGroupLoaded(IconLoader* source,
49 const IconGroupID& group) = 0;
50 // Invoked when an icon has been read. |source| is the IconLoader. If the
51 // icon has been successfully loaded, result is non-null. This method must
52 // return true if it is taking ownership of the returned image.
53 virtual bool OnImageLoaded(IconLoader* source,
54 gfx::Image* result,
55 const IconGroupID& group) = 0;
57 protected:
58 virtual ~Delegate() {}
61 IconLoader(const base::FilePath& file_path,
62 IconSize size,
63 Delegate* delegate);
65 // Start reading the icon on the file thread.
66 void Start();
68 private:
69 friend class base::RefCountedThreadSafe<IconLoader>;
71 virtual ~IconLoader();
73 // Get the identifying string for the given file. The implementation
74 // is in icon_loader_[platform].cc.
75 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path);
77 // Some icons (exe's on windows) can change as they're loaded.
78 static bool IsIconMutableFromFilepath(const base::FilePath& path);
80 void ReadGroup();
81 void OnReadGroup();
82 void ReadIcon();
84 void NotifyDelegate();
86 // The message loop object of the thread in which we notify the delegate.
87 scoped_refptr<base::MessageLoopProxy> target_message_loop_;
89 base::FilePath file_path_;
91 IconGroupID group_;
93 IconSize icon_size_;
95 scoped_ptr<gfx::Image> image_;
97 Delegate* delegate_;
99 DISALLOW_COPY_AND_ASSIGN(IconLoader);
102 #endif // CHROME_BROWSER_ICON_LOADER_H_