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

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

Issue 19471005: Add custom default theme support and create a managed user default theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 5 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 | Annotate | Revision Log
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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/sequenced_task_runner_helpers.h" 14 #include "base/sequenced_task_runner_helpers.h"
15 #include "chrome/browser/themes/custom_theme_supplier.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
20 #include "ui/gfx/color_utils.h" 19 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
pkotwicz 2013/07/19 18:33:20 Nit: You should not need to include image.h now th
Adrian Kuegel 2013/07/22 12:58:08 Right. I forgot to remove the include here. Done.
22 21
23 namespace base { 22 namespace base {
24 class DictionaryValue; 23 class DictionaryValue;
25 class FilePath; 24 class FilePath;
26 class RefCountedMemory; 25 class RefCountedMemory;
27 } 26 }
28 27
29 namespace extensions { 28 namespace extensions {
30 class Extensions; 29 class Extensions;
31 } 30 }
32 31
32 namespace gfx {
33 class Image;
34 }
35
33 namespace ui { 36 namespace ui {
34 class DataPack; 37 class DataPack;
35 } 38 }
36 39
37 // An optimized representation of a theme, backed by a mmapped DataPack. 40 // An optimized representation of a theme, backed by a mmapped DataPack.
38 // 41 //
39 // The idea is to pre-process all images (tinting, compositing, etc) at theme 42 // The idea is to pre-process all images (tinting, compositing, etc) at theme
40 // install time, save all the PNG-ified data into an mmappable file so we don't 43 // install time, save all the PNG-ified data into an mmappable file so we don't
41 // suffer multiple file system access times, therefore solving two of the 44 // suffer multiple file system access times, therefore solving two of the
42 // problems with the previous implementation. 45 // problems with the previous implementation.
43 // 46 //
44 // A note on const-ness. All public, non-static methods are const. We do this 47 // A note on const-ness. All public, non-static methods are const. We do this
45 // because once we've constructed a BrowserThemePack through the 48 // because once we've constructed a BrowserThemePack through the
46 // BuildFromExtension() interface, we WriteToDisk() on a thread other than the 49 // BuildFromExtension() interface, we WriteToDisk() on a thread other than the
47 // UI thread that consumes a BrowserThemePack. There is no locking; thread 50 // 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 51 // safety between the writing thread and the UI thread is ensured by having the
49 // data be immutable. 52 // data be immutable.
50 // 53 //
51 // BrowserThemePacks are always deleted on the file thread because in the 54 // BrowserThemePacks are always deleted on the file thread because in the
52 // common case, they are backed by mmapped data and the unmmapping operation 55 // common case, they are backed by mmapped data and the unmmapping operation
53 // will trip our IO on the UI thread detector. 56 // will trip our IO on the UI thread detector.
54 class BrowserThemePack : public base::RefCountedThreadSafe< 57 class BrowserThemePack : public CustomThemeSupplier {
55 BrowserThemePack, content::BrowserThread::DeleteOnFileThread> {
56 public: 58 public:
57 // Builds the theme pack from all data from |extension|. This is often done 59 // Builds the theme pack from all data from |extension|. This is often done
58 // on a separate thread as it takes so long. This can fail and return NULL in 60 // on a separate thread as it takes so long. This can fail and return NULL in
59 // the case where the theme has invalid data. 61 // the case where the theme has invalid data.
60 static scoped_refptr<BrowserThemePack> BuildFromExtension( 62 static scoped_refptr<BrowserThemePack> BuildFromExtension(
61 const extensions::Extension* extension); 63 const extensions::Extension* extension);
62 64
63 // Builds the theme pack from a previously performed WriteToDisk(). This 65 // Builds the theme pack from a previously performed WriteToDisk(). This
64 // operation should be relatively fast, as it should be an mmap() and some 66 // operation should be relatively fast, as it should be an mmap() and some
65 // pointer swizzling. Returns NULL on any error attempting to read |path|. 67 // pointer swizzling. Returns NULL on any error attempting to read |path|.
66 static scoped_refptr<BrowserThemePack> BuildFromDataPack( 68 static scoped_refptr<BrowserThemePack> BuildFromDataPack(
67 const base::FilePath& path, const std::string& expected_id); 69 const base::FilePath& path, const std::string& expected_id);
68 70
71 // Returns the set of image idrs which can be overwritten by a user provided
72 // theme.
73 static void GetThemeableImageIDRs(std::set<int>* result);
74
69 // Builds a data pack on disk at |path| for future quick loading by 75 // Builds a data pack on disk at |path| for future quick loading by
70 // BuildFromDataPack(). Often (but not always) called from the file thread; 76 // BuildFromDataPack(). Often (but not always) called from the file thread;
71 // implementation should be threadsafe because neither thread will write to 77 // implementation should be threadsafe because neither thread will write to
72 // |image_memory_| and the worker thread will keep a reference to prevent 78 // |image_memory_| and the worker thread will keep a reference to prevent
73 // destruction. 79 // destruction.
74 bool WriteToDisk(const base::FilePath& path) const; 80 bool WriteToDisk(const base::FilePath& path) const;
75 81
76 // If this theme specifies data for the corresponding |id|, return true and 82 // Overridden from CustomThemeSupplier:
77 // write the corresponding value to the output parameter. These functions 83 virtual bool GetTint(int id, color_utils::HSL* hsl) const OVERRIDE;
78 // don't return the default data. These methods should only be called from 84 virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
79 // the UI thread. (But this isn't enforced because of unit tests). 85 virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE;
80 bool GetTint(int id, color_utils::HSL* hsl) const; 86 virtual gfx::Image GetImageNamed(int id) OVERRIDE;
81 bool GetColor(int id, SkColor* color) const; 87 virtual base::RefCountedMemory* GetRawData(
82 bool GetDisplayProperty(int id, int* result) const; 88 int id, ui::ScaleFactor scale_factor) const OVERRIDE;
83 89 virtual bool HasCustomImage(int id) const OVERRIDE;
84 // Returns the theme pack image for |id|. Returns an empty image if an image
85 // is not found.
86 gfx::Image GetImageNamed(int id);
87
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.
90 base::RefCountedMemory* GetRawData(int id,
91 ui::ScaleFactor scale_factor) const;
92
93 // Returns the set of image idrs which can be overwritten by a user provided
94 // theme.
95 static void GetThemeableImageIDRs(std::set<int>* result);
96
97 // Whether this theme provides an image for |id|.
98 bool HasCustomImage(int id) const;
99 90
100 private: 91 private:
101 friend struct content::BrowserThread::DeleteOnThread<
102 content::BrowserThread::FILE>;
103 friend class base::DeleteHelper<BrowserThemePack>;
104 friend class BrowserThemePackTest; 92 friend class BrowserThemePackTest;
105 93
106 // Cached images. 94 // Cached images.
107 typedef std::map<int, gfx::Image> ImageCache; 95 typedef std::map<int, gfx::Image> ImageCache;
108 96
109 // The raw PNG memory associated with a certain id. 97 // The raw PNG memory associated with a certain id.
110 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages; 98 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages;
111 99
112 // The type passed to ui::DataPack::WritePack. 100 // The type passed to ui::DataPack::WritePack.
113 typedef std::map<uint16, base::StringPiece> RawDataForWriting; 101 typedef std::map<uint16, base::StringPiece> RawDataForWriting;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Cache of images created in BuildFromExtension(). Once the theme pack is 269 // Cache of images created in BuildFromExtension(). Once the theme pack is
282 // created, this cache should only be accessed on the file thread. There 270 // created, this cache should only be accessed on the file thread. There
283 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| 271 // should be no IDs in |image_memory_| that are in |images_on_file_thread_|
284 // or vice versa. 272 // or vice versa.
285 ImageCache images_on_file_thread_; 273 ImageCache images_on_file_thread_;
286 274
287 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); 275 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack);
288 }; 276 };
289 277
290 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ 278 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698