OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ |
6 #define CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ | 6 #define CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "chrome/browser/android/thumbnail/scoped_ptr_expiring_cache.h" | 21 #include "chrome/browser/android/thumbnail/scoped_ptr_expiring_cache.h" |
22 #include "chrome/browser/android/thumbnail/thumbnail.h" | 22 #include "chrome/browser/android/thumbnail/thumbnail.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "third_party/skia/include/core/SkRefCnt.h" |
24 #include "ui/android/resources/ui_resource_provider.h" | 25 #include "ui/android/resources/ui_resource_provider.h" |
25 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
26 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
27 #include "ui/gfx/geometry/size_f.h" | 28 #include "ui/gfx/geometry/size_f.h" |
28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
29 | 30 |
30 namespace base { | 31 namespace base { |
31 class File; | 32 class File; |
32 class Time; | 33 class Time; |
33 } | 34 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 base::Time capture_time_; | 93 base::Time capture_time_; |
93 GURL url_; | 94 GURL url_; |
94 }; | 95 }; |
95 | 96 |
96 typedef ScopedPtrExpiringCache<TabId, Thumbnail> ExpiringThumbnailCache; | 97 typedef ScopedPtrExpiringCache<TabId, Thumbnail> ExpiringThumbnailCache; |
97 typedef base::hash_map<TabId, ThumbnailMetaData> ThumbnailMetaDataMap; | 98 typedef base::hash_map<TabId, ThumbnailMetaData> ThumbnailMetaDataMap; |
98 | 99 |
99 void RemoveFromDisk(TabId tab_id); | 100 void RemoveFromDisk(TabId tab_id); |
100 static void RemoveFromDiskTask(TabId tab_id); | 101 static void RemoveFromDiskTask(TabId tab_id); |
101 void WriteThumbnailIfNecessary(TabId tab_id, | 102 void WriteThumbnailIfNecessary(TabId tab_id, |
102 skia::RefPtr<SkPixelRef> compressed_data, | 103 sk_sp<SkPixelRef> compressed_data, |
103 float scale, | 104 float scale, |
104 const gfx::Size& content_size); | 105 const gfx::Size& content_size); |
105 void CompressThumbnailIfNecessary(TabId tab_id, | 106 void CompressThumbnailIfNecessary(TabId tab_id, |
106 const base::Time& time_stamp, | 107 const base::Time& time_stamp, |
107 const SkBitmap& bitmap, | 108 const SkBitmap& bitmap, |
108 float scale); | 109 float scale); |
109 void ReadNextThumbnail(); | 110 void ReadNextThumbnail(); |
110 void MakeSpaceForNewItemIfNecessary(TabId tab_id); | 111 void MakeSpaceForNewItemIfNecessary(TabId tab_id); |
111 void RemoveFromReadQueue(TabId tab_id); | 112 void RemoveFromReadQueue(TabId tab_id); |
112 static void WriteTask(TabId tab_id, | 113 static void WriteTask(TabId tab_id, |
113 skia::RefPtr<SkPixelRef> compressed_data, | 114 sk_sp<SkPixelRef> compressed_data, |
114 float scale, | 115 float scale, |
115 const gfx::Size& content_size, | 116 const gfx::Size& content_size, |
116 const base::Callback<void()>& post_write_task); | 117 const base::Callback<void()>& post_write_task); |
117 void PostWriteTask(); | 118 void PostWriteTask(); |
118 static void CompressionTask( | 119 static void CompressionTask( |
119 SkBitmap raw_data, | 120 SkBitmap raw_data, |
120 gfx::Size encoded_size, | 121 gfx::Size encoded_size, |
121 const base::Callback<void(skia::RefPtr<SkPixelRef>, const gfx::Size&)>& | 122 const base::Callback<void(sk_sp<SkPixelRef>, const gfx::Size&)>& |
122 post_compression_task); | 123 post_compression_task); |
123 void PostCompressionTask(TabId tab_id, | 124 void PostCompressionTask(TabId tab_id, |
124 const base::Time& time_stamp, | 125 const base::Time& time_stamp, |
125 float scale, | 126 float scale, |
126 skia::RefPtr<SkPixelRef> compressed_data, | 127 sk_sp<SkPixelRef> compressed_data, |
127 const gfx::Size& content_size); | 128 const gfx::Size& content_size); |
128 static void DecompressionTask( | 129 static void DecompressionTask( |
129 const base::Callback<void(bool, SkBitmap)>& | 130 const base::Callback<void(bool, SkBitmap)>& |
130 post_decompress_callback, | 131 post_decompress_callback, |
131 skia::RefPtr<SkPixelRef> compressed_data, | 132 sk_sp<SkPixelRef> compressed_data, |
132 float scale, | 133 float scale, |
133 const gfx::Size& encoded_size); | 134 const gfx::Size& encoded_size); |
134 static void ReadTask( | 135 static void ReadTask( |
135 bool decompress, | 136 bool decompress, |
136 TabId tab_id, | 137 TabId tab_id, |
137 const base::Callback< | 138 const base::Callback< |
138 void(skia::RefPtr<SkPixelRef>, float, const gfx::Size&)>& | 139 void(sk_sp<SkPixelRef>, float, const gfx::Size&)>& |
139 post_read_task); | 140 post_read_task); |
140 void PostReadTask(TabId tab_id, | 141 void PostReadTask(TabId tab_id, |
141 skia::RefPtr<SkPixelRef> compressed_data, | 142 sk_sp<SkPixelRef> compressed_data, |
142 float scale, | 143 float scale, |
143 const gfx::Size& content_size); | 144 const gfx::Size& content_size); |
144 void NotifyObserversOfThumbnailRead(TabId tab_id); | 145 void NotifyObserversOfThumbnailRead(TabId tab_id); |
145 void RemoveOnMatchedTimeStamp(TabId tab_id, const base::Time& time_stamp); | 146 void RemoveOnMatchedTimeStamp(TabId tab_id, const base::Time& time_stamp); |
146 static std::pair<SkBitmap, float> CreateApproximation(const SkBitmap& bitmap, | 147 static std::pair<SkBitmap, float> CreateApproximation(const SkBitmap& bitmap, |
147 float scale); | 148 float scale); |
148 | 149 |
149 const size_t compression_queue_max_size_; | 150 const size_t compression_queue_max_size_; |
150 const size_t write_queue_max_size_; | 151 const size_t write_queue_max_size_; |
151 const bool use_approximation_thumbnail_; | 152 const bool use_approximation_thumbnail_; |
(...skipping 10 matching lines...) Expand all Loading... |
162 TabIdList visible_ids_; | 163 TabIdList visible_ids_; |
163 | 164 |
164 ui::UIResourceProvider* ui_resource_provider_; | 165 ui::UIResourceProvider* ui_resource_provider_; |
165 | 166 |
166 base::WeakPtrFactory<ThumbnailCache> weak_factory_; | 167 base::WeakPtrFactory<ThumbnailCache> weak_factory_; |
167 | 168 |
168 DISALLOW_COPY_AND_ASSIGN(ThumbnailCache); | 169 DISALLOW_COPY_AND_ASSIGN(ThumbnailCache); |
169 }; | 170 }; |
170 | 171 |
171 #endif // CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ | 172 #endif // CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_CACHE_H_ |
OLD | NEW |