OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 5 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop_helpers.h" | 15 #include "base/message_loop_helpers.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
19 | 19 |
20 class FilePath; | 20 class FilePath; |
21 class RefCountedMemory; | |
22 namespace ui { | 21 namespace ui { |
23 class DataPack; | 22 class DataPack; |
24 } | 23 } |
25 namespace gfx { | 24 namespace gfx { |
26 class Image; | 25 class Image; |
27 } | 26 } |
28 namespace base { | 27 namespace base { |
29 class DictionaryValue; | 28 class DictionaryValue; |
| 29 class RefCountedMemory; |
30 } | 30 } |
31 | 31 |
32 // An optimized representation of a theme, backed by a mmapped DataPack. | 32 // An optimized representation of a theme, backed by a mmapped DataPack. |
33 // | 33 // |
34 // The idea is to pre-process all images (tinting, compositing, etc) at theme | 34 // The idea is to pre-process all images (tinting, compositing, etc) at theme |
35 // install time, save all the PNG-ified data into an mmappable file so we don't | 35 // install time, save all the PNG-ified data into an mmappable file so we don't |
36 // suffer multiple file system access times, therefore solving two of the | 36 // suffer multiple file system access times, therefore solving two of the |
37 // problems with the previous implementation. | 37 // problems with the previous implementation. |
38 // | 38 // |
39 // A note on const-ness. All public, non-static methods are const. We do this | 39 // A note on const-ness. All public, non-static methods are const. We do this |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // that this is separate from HasCustomImage() which returns whether a custom | 80 // that this is separate from HasCustomImage() which returns whether a custom |
81 // image |id| was included in the unprocessed theme and is used as a proxy | 81 // image |id| was included in the unprocessed theme and is used as a proxy |
82 // for making layout decisions in the interface. | 82 // for making layout decisions in the interface. |
83 SkBitmap* GetBitmapNamed(int id) const; | 83 SkBitmap* GetBitmapNamed(int id) const; |
84 | 84 |
85 // Returns an image if we have a custom image for |id|, otherwise NULL. | 85 // Returns an image if we have a custom image for |id|, otherwise NULL. |
86 const gfx::Image* GetImageNamed(int id) const; | 86 const gfx::Image* GetImageNamed(int id) const; |
87 | 87 |
88 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only | 88 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only |
89 // supposed to work for the NTP attribution and background resources. | 89 // supposed to work for the NTP attribution and background resources. |
90 RefCountedMemory* GetRawData(int id) const; | 90 base::RefCountedMemory* GetRawData(int id) const; |
91 | 91 |
92 // Whether this theme provides an image for |id|. | 92 // Whether this theme provides an image for |id|. |
93 bool HasCustomImage(int id) const; | 93 bool HasCustomImage(int id) const; |
94 | 94 |
95 private: | 95 private: |
96 friend struct content::BrowserThread::DeleteOnThread< | 96 friend struct content::BrowserThread::DeleteOnThread< |
97 content::BrowserThread::FILE>; | 97 content::BrowserThread::FILE>; |
98 friend class base::DeleteHelper<BrowserThemePack>; | 98 friend class base::DeleteHelper<BrowserThemePack>; |
99 friend class BrowserThemePackTest; | 99 friend class BrowserThemePackTest; |
100 | 100 |
101 // Cached images. We cache all retrieved and generated bitmaps and keep | 101 // Cached images. We cache all retrieved and generated bitmaps and keep |
102 // track of the pointers. We own these and will delete them when we're done | 102 // track of the pointers. We own these and will delete them when we're done |
103 // using them. | 103 // using them. |
104 typedef std::map<int, const gfx::Image*> ImageCache; | 104 typedef std::map<int, const gfx::Image*> ImageCache; |
105 | 105 |
106 // The raw PNG memory associated with a certain id. | 106 // The raw PNG memory associated with a certain id. |
107 typedef std::map<int, scoped_refptr<RefCountedMemory> > RawImages; | 107 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages; |
108 | 108 |
109 // The type passed to ui::DataPack::WritePack. | 109 // The type passed to ui::DataPack::WritePack. |
110 typedef std::map<uint16, base::StringPiece> RawDataForWriting; | 110 typedef std::map<uint16, base::StringPiece> RawDataForWriting; |
111 | 111 |
112 // An association between an id and the FilePath that has the image data. | 112 // An association between an id and the FilePath that has the image data. |
113 typedef std::map<int, FilePath> FilePathMap; | 113 typedef std::map<int, FilePath> FilePathMap; |
114 | 114 |
115 // Default. Everything is empty. | 115 // Default. Everything is empty. |
116 BrowserThemePack(); | 116 BrowserThemePack(); |
117 | 117 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // in |image_memory_| that are in |prepared_images_| or vice versa. | 236 // in |image_memory_| that are in |prepared_images_| or vice versa. |
237 ImageCache prepared_images_; | 237 ImageCache prepared_images_; |
238 | 238 |
239 // Loaded images. These are loaded from |image_memory_| or the |data_pack_|. | 239 // Loaded images. These are loaded from |image_memory_| or the |data_pack_|. |
240 mutable ImageCache loaded_images_; | 240 mutable ImageCache loaded_images_; |
241 | 241 |
242 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); | 242 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); |
243 }; | 243 }; |
244 | 244 |
245 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 245 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
OLD | NEW |