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

Side by Side Diff: chrome/browser/themes/browser_theme_pack.h

Issue 2799003002: Unpack theme data from extensions off of UI thread. (Closed)
Patch Set: fix gtk case Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
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 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // BuildFromExtension() interface, we WriteToDisk() on a thread other than the 46 // BuildFromExtension() interface, we WriteToDisk() on a thread other than the
47 // UI thread that consumes a BrowserThemePack. There is no locking; thread 47 // UI thread that consumes a BrowserThemePack. There is no locking; thread
48 // safety between the writing thread and the UI thread is ensured by having the 48 // safety between the writing thread and the UI thread is ensured by having the
49 // data be immutable. 49 // data be immutable.
50 // 50 //
51 // BrowserThemePacks are always deleted on the file thread because in the 51 // BrowserThemePacks are always deleted on the file thread because in the
52 // common case, they are backed by mmapped data and the unmmapping operation 52 // common case, they are backed by mmapped data and the unmmapping operation
53 // will trip our IO on the UI thread detector. 53 // will trip our IO on the UI thread detector.
54 class BrowserThemePack : public CustomThemeSupplier { 54 class BrowserThemePack : public CustomThemeSupplier {
55 public: 55 public:
56 // Builds the theme pack from all data from |extension|. This is often done 56 // Builds the theme from |extension| into |pack|. This may be done on a
57 // on a separate thread as it takes so long. This can fail and return NULL in 57 // separate thread as it takes so long. This can fail in the case where the
58 // the case where the theme has invalid data. 58 // theme has invalid data, in which case |pack->is_valid()| will be false.
59 static scoped_refptr<BrowserThemePack> BuildFromExtension( 59 static void BuildFromExtension(const extensions::Extension* extension,
60 const extensions::Extension* extension); 60 scoped_refptr<BrowserThemePack> pack);
61 61
62 // Builds the theme pack from a previously performed WriteToDisk(). This 62 // Builds the theme pack from a previously performed WriteToDisk(). This
63 // operation should be relatively fast, as it should be an mmap() and some 63 // operation should be relatively fast, as it should be an mmap() and some
64 // pointer swizzling. Returns NULL on any error attempting to read |path|. 64 // pointer swizzling. Returns NULL on any error attempting to read |path|.
65 static scoped_refptr<BrowserThemePack> BuildFromDataPack( 65 static scoped_refptr<BrowserThemePack> BuildFromDataPack(
66 const base::FilePath& path, const std::string& expected_id); 66 const base::FilePath& path, const std::string& expected_id);
67 67
68 // Returns whether the specified identifier is one of the images we persist 68 // Returns whether the specified identifier is one of the images we persist
69 // in the data pack. 69 // in the data pack.
70 static bool IsPersistentImageID(int id); 70 static bool IsPersistentImageID(int id);
71 71
72 // Default. Everything is empty.
73 BrowserThemePack();
74
75 bool is_valid() const { return is_valid_; }
76
72 // Builds a data pack on disk at |path| for future quick loading by 77 // Builds a data pack on disk at |path| for future quick loading by
73 // BuildFromDataPack(). Often (but not always) called from the file thread; 78 // BuildFromDataPack(). Often (but not always) called from the file thread;
74 // implementation should be threadsafe because neither thread will write to 79 // implementation should be threadsafe because neither thread will write to
75 // |image_memory_| and the worker thread will keep a reference to prevent 80 // |image_memory_| and the worker thread will keep a reference to prevent
76 // destruction. 81 // destruction.
77 bool WriteToDisk(const base::FilePath& path) const; 82 bool WriteToDisk(const base::FilePath& path) const;
78 83
79 // Overridden from CustomThemeSupplier: 84 // Overridden from CustomThemeSupplier:
80 bool GetTint(int id, color_utils::HSL* hsl) const override; 85 bool GetTint(int id, color_utils::HSL* hsl) const override;
81 bool GetColor(int id, SkColor* color) const override; 86 bool GetColor(int id, SkColor* color) const override;
(...skipping 14 matching lines...) Expand all
96 101
97 // The type passed to ui::DataPack::WritePack. 102 // The type passed to ui::DataPack::WritePack.
98 typedef std::map<uint16_t, base::StringPiece> RawDataForWriting; 103 typedef std::map<uint16_t, base::StringPiece> RawDataForWriting;
99 104
100 // Maps scale factors (enum values) to file paths. 105 // Maps scale factors (enum values) to file paths.
101 typedef std::map<ui::ScaleFactor, base::FilePath> ScaleFactorToFileMap; 106 typedef std::map<ui::ScaleFactor, base::FilePath> ScaleFactorToFileMap;
102 107
103 // Maps image ids to maps of scale factors to file paths. 108 // Maps image ids to maps of scale factors to file paths.
104 typedef std::map<int, ScaleFactorToFileMap> FilePathMap; 109 typedef std::map<int, ScaleFactorToFileMap> FilePathMap;
105 110
106 // Default. Everything is empty.
107 BrowserThemePack();
108
109 ~BrowserThemePack() override; 111 ~BrowserThemePack() override;
110 112
111 // Builds a header ready to write to disk. 113 // Builds a header ready to write to disk.
112 void BuildHeader(const extensions::Extension* extension); 114 void BuildHeader(const extensions::Extension* extension);
113 115
114 // Transforms the JSON tint values into their final versions in the |tints_| 116 // Transforms the JSON tint values into their final versions in the |tints_|
115 // array. 117 // array.
116 void BuildTintsFromJSON(const base::DictionaryValue* tints_value); 118 void BuildTintsFromJSON(const base::DictionaryValue* tints_value);
117 119
118 // Transforms the JSON color values into their final versions in the 120 // Transforms the JSON color values into their final versions in the
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // Header that is written to disk. 212 // Header that is written to disk.
211 struct BrowserThemePackHeader { 213 struct BrowserThemePackHeader {
212 // Numeric version to make sure we're compatible in the future. 214 // Numeric version to make sure we're compatible in the future.
213 int32_t version; 215 int32_t version;
214 216
215 // 1 if little_endian. 0 if big_endian. On mismatch, abort load. 217 // 1 if little_endian. 0 if big_endian. On mismatch, abort load.
216 int32_t little_endian; 218 int32_t little_endian;
217 219
218 // theme_id without NULL terminator. 220 // theme_id without NULL terminator.
219 uint8_t theme_id[16]; 221 uint8_t theme_id[16];
220 } *header_; 222 }* header_ = nullptr;
221 223
222 // The remaining structs represent individual entries in an array. For the 224 // The remaining structs represent individual entries in an array. For the
223 // following three structs, BrowserThemePack will either allocate an array or 225 // following three structs, BrowserThemePack will either allocate an array or
224 // will point directly to mmapped data. 226 // will point directly to mmapped data.
225 struct TintEntry { 227 struct TintEntry {
226 int32_t id; 228 int32_t id;
227 double h; 229 double h;
228 double s; 230 double s;
229 double l; 231 double l;
230 } *tints_; 232 }* tints_ = nullptr;
231 233
232 struct ColorPair { 234 struct ColorPair {
233 int32_t id; 235 int32_t id;
234 SkColor color; 236 SkColor color;
235 } *colors_; 237 }* colors_ = nullptr;
236 238
237 struct DisplayPropertyPair { 239 struct DisplayPropertyPair {
238 int32_t id; 240 int32_t id;
239 int32_t property; 241 int32_t property;
240 } *display_properties_; 242 }* display_properties_ = nullptr;
241 243
242 // A list of included source images. A pointer to a -1 terminated array of 244 // A list of included source images. A pointer to a -1 terminated array of
243 // our persistent IDs. 245 // our persistent IDs.
244 int* source_images_; 246 int* source_images_ = nullptr;
245 #pragma pack(pop) 247 #pragma pack(pop)
246 248
247 // The scale factors represented by the images in the theme pack. 249 // The scale factors represented by the images in the theme pack.
248 std::vector<ui::ScaleFactor> scale_factors_; 250 std::vector<ui::ScaleFactor> scale_factors_;
249 251
250 // References to raw PNG data. This map isn't touched when |data_pack_| is 252 // References to raw PNG data. This map isn't touched when |data_pack_| is
251 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any 253 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any
252 // image data that needs to be written to the DataPack during WriteToDisk() 254 // image data that needs to be written to the DataPack during WriteToDisk()
253 // needs to be in |image_memory_|. 255 // needs to be in |image_memory_|.
254 RawImages image_memory_; 256 RawImages image_memory_;
255 257
256 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|, 258 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|,
257 // and by BuildFromExtension(). These images should only be accessed on the UI 259 // and by BuildFromExtension().
258 // thread. 260 ImageCache images_;
259 ImageCache images_on_ui_thread_;
260 261
261 // Cache of images created in BuildFromExtension(). Once the theme pack is 262 // Cache of images created in BuildFromExtension(). Once the theme pack is
262 // created, this cache should only be accessed on the file thread. There 263 // created, this cache should only be accessed on the file thread. There
263 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| 264 // should be no IDs in |image_memory_| that are in |images_on_file_thread_|
264 // or vice versa. 265 // or vice versa.
265 ImageCache images_on_file_thread_; 266 ImageCache images_on_file_thread_;
266 267
268 // Whether the theme pack has been succesfully initialized and is ready to
269 // use.
270 bool is_valid_ = false;
271
267 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); 272 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack);
268 }; 273 };
269 274
270 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 275 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/two_client_themes_sync_test.cc ('k') | chrome/browser/themes/browser_theme_pack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698