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

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

Issue 2919953002: Revert of Unpack theme data from extensions off of UI thread. (Closed)
Patch Set: 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 from |extension| into |pack|. This may be done on a 56 // Builds the theme pack from all data from |extension|. This is often done
57 // separate thread as it takes so long. This can fail in the case where the 57 // on a separate thread as it takes so long. This can fail and return NULL in
58 // theme has invalid data, in which case |pack->is_valid()| will be false. 58 // the case where the theme has invalid data.
59 static void BuildFromExtension(const extensions::Extension* extension, 59 static scoped_refptr<BrowserThemePack> BuildFromExtension(
60 scoped_refptr<BrowserThemePack> pack); 60 const extensions::Extension* extension);
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
77 // Builds a data pack on disk at |path| for future quick loading by 72 // Builds a data pack on disk at |path| for future quick loading by
78 // BuildFromDataPack(). Often (but not always) called from the file thread; 73 // BuildFromDataPack(). Often (but not always) called from the file thread;
79 // implementation should be threadsafe because neither thread will write to 74 // implementation should be threadsafe because neither thread will write to
80 // |image_memory_| and the worker thread will keep a reference to prevent 75 // |image_memory_| and the worker thread will keep a reference to prevent
81 // destruction. 76 // destruction.
82 bool WriteToDisk(const base::FilePath& path) const; 77 bool WriteToDisk(const base::FilePath& path) const;
83 78
84 // Overridden from CustomThemeSupplier: 79 // Overridden from CustomThemeSupplier:
85 bool GetTint(int id, color_utils::HSL* hsl) const override; 80 bool GetTint(int id, color_utils::HSL* hsl) const override;
86 bool GetColor(int id, SkColor* color) const override; 81 bool GetColor(int id, SkColor* color) const override;
(...skipping 14 matching lines...) Expand all
101 96
102 // The type passed to ui::DataPack::WritePack. 97 // The type passed to ui::DataPack::WritePack.
103 typedef std::map<uint16_t, base::StringPiece> RawDataForWriting; 98 typedef std::map<uint16_t, base::StringPiece> RawDataForWriting;
104 99
105 // Maps scale factors (enum values) to file paths. 100 // Maps scale factors (enum values) to file paths.
106 typedef std::map<ui::ScaleFactor, base::FilePath> ScaleFactorToFileMap; 101 typedef std::map<ui::ScaleFactor, base::FilePath> ScaleFactorToFileMap;
107 102
108 // Maps image ids to maps of scale factors to file paths. 103 // Maps image ids to maps of scale factors to file paths.
109 typedef std::map<int, ScaleFactorToFileMap> FilePathMap; 104 typedef std::map<int, ScaleFactorToFileMap> FilePathMap;
110 105
106 // Default. Everything is empty.
107 BrowserThemePack();
108
111 ~BrowserThemePack() override; 109 ~BrowserThemePack() override;
112 110
113 // Builds a header ready to write to disk. 111 // Builds a header ready to write to disk.
114 void BuildHeader(const extensions::Extension* extension); 112 void BuildHeader(const extensions::Extension* extension);
115 113
116 // Transforms the JSON tint values into their final versions in the |tints_| 114 // Transforms the JSON tint values into their final versions in the |tints_|
117 // array. 115 // array.
118 void BuildTintsFromJSON(const base::DictionaryValue* tints_value); 116 void BuildTintsFromJSON(const base::DictionaryValue* tints_value);
119 117
120 // Transforms the JSON color values into their final versions in the 118 // Transforms the JSON color values into their final versions in the
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // Header that is written to disk. 210 // Header that is written to disk.
213 struct BrowserThemePackHeader { 211 struct BrowserThemePackHeader {
214 // Numeric version to make sure we're compatible in the future. 212 // Numeric version to make sure we're compatible in the future.
215 int32_t version; 213 int32_t version;
216 214
217 // 1 if little_endian. 0 if big_endian. On mismatch, abort load. 215 // 1 if little_endian. 0 if big_endian. On mismatch, abort load.
218 int32_t little_endian; 216 int32_t little_endian;
219 217
220 // theme_id without NULL terminator. 218 // theme_id without NULL terminator.
221 uint8_t theme_id[16]; 219 uint8_t theme_id[16];
222 }* header_ = nullptr; 220 } *header_;
223 221
224 // The remaining structs represent individual entries in an array. For the 222 // The remaining structs represent individual entries in an array. For the
225 // following three structs, BrowserThemePack will either allocate an array or 223 // following three structs, BrowserThemePack will either allocate an array or
226 // will point directly to mmapped data. 224 // will point directly to mmapped data.
227 struct TintEntry { 225 struct TintEntry {
228 int32_t id; 226 int32_t id;
229 double h; 227 double h;
230 double s; 228 double s;
231 double l; 229 double l;
232 }* tints_ = nullptr; 230 } *tints_;
233 231
234 struct ColorPair { 232 struct ColorPair {
235 int32_t id; 233 int32_t id;
236 SkColor color; 234 SkColor color;
237 }* colors_ = nullptr; 235 } *colors_;
238 236
239 struct DisplayPropertyPair { 237 struct DisplayPropertyPair {
240 int32_t id; 238 int32_t id;
241 int32_t property; 239 int32_t property;
242 }* display_properties_ = nullptr; 240 } *display_properties_;
243 241
244 // A list of included source images. A pointer to a -1 terminated array of 242 // A list of included source images. A pointer to a -1 terminated array of
245 // our persistent IDs. 243 // our persistent IDs.
246 int* source_images_ = nullptr; 244 int* source_images_;
247 #pragma pack(pop) 245 #pragma pack(pop)
248 246
249 // The scale factors represented by the images in the theme pack. 247 // The scale factors represented by the images in the theme pack.
250 std::vector<ui::ScaleFactor> scale_factors_; 248 std::vector<ui::ScaleFactor> scale_factors_;
251 249
252 // References to raw PNG data. This map isn't touched when |data_pack_| is 250 // References to raw PNG data. This map isn't touched when |data_pack_| is
253 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any 251 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any
254 // image data that needs to be written to the DataPack during WriteToDisk() 252 // image data that needs to be written to the DataPack during WriteToDisk()
255 // needs to be in |image_memory_|. 253 // needs to be in |image_memory_|.
256 RawImages image_memory_; 254 RawImages image_memory_;
257 255
258 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|, 256 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|,
259 // and by BuildFromExtension(). 257 // and by BuildFromExtension(). These images should only be accessed on the UI
260 ImageCache images_; 258 // thread.
259 ImageCache images_on_ui_thread_;
261 260
262 // Cache of images created in BuildFromExtension(). Once the theme pack is 261 // Cache of images created in BuildFromExtension(). Once the theme pack is
263 // created, this cache should only be accessed on the file thread. There 262 // created, this cache should only be accessed on the file thread. There
264 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| 263 // should be no IDs in |image_memory_| that are in |images_on_file_thread_|
265 // or vice versa. 264 // or vice versa.
266 ImageCache images_on_file_thread_; 265 ImageCache images_on_file_thread_;
267 266
268 // Whether the theme pack has been succesfully initialized and is ready to
269 // use.
270 bool is_valid_ = false;
271
272 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); 267 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack);
273 }; 268 };
274 269
275 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 270 #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