OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/media/tab_desktop_media_list.h" | 5 #include "chrome/browser/media/tab_desktop_media_list.h" |
6 | 6 |
7 #include "base/hash.h" | 7 #include "base/hash.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "components/favicon/content/content_favicon_driver.h" | 14 #include "components/favicon/content/content_favicon_driver.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
18 #include "media/base/video_util.h" | 18 #include "media/base/video_util.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
20 #include "third_party/skia/include/core/SkImage.h" | 20 #include "third_party/skia/include/core/SkImage.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 using content::DesktopMediaID; | |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 // Returns a hash of a favicon to detect when the favicon of media source has | |
29 // changed. | |
30 uint32_t GetImageHash(const gfx::Image& favicon) { | |
31 SkBitmap bitmap = favicon.AsBitmap(); | |
32 bitmap.lockPixels(); | |
33 uint32_t value = | |
34 base::Hash(reinterpret_cast<char*>(bitmap.getPixels()), bitmap.getSize()); | |
35 bitmap.unlockPixels(); | |
36 | |
37 return value; | |
38 } | |
39 | |
40 gfx::ImageSkia CreateEnlargedFaviconImage(gfx::Size size, | 27 gfx::ImageSkia CreateEnlargedFaviconImage(gfx::Size size, |
41 const gfx::ImageSkia& favicon) { | 28 const gfx::ImageSkia& favicon) { |
42 DCHECK_GE(size.width(), 20); | 29 DCHECK_GE(size.width(), 20); |
43 DCHECK_GE(size.height(), 20); | 30 DCHECK_GE(size.height(), 20); |
44 | 31 |
45 // Create a bitmap. | 32 // Create a bitmap. |
46 SkBitmap result; | 33 SkBitmap result; |
47 result.allocN32Pixels(size.width(), size.height(), true); | 34 result.allocN32Pixels(size.width(), size.height(), true); |
48 SkCanvas canvas(result); | 35 SkCanvas canvas(result); |
49 | 36 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 favicon::FaviconDriver* favicon_driver = | 127 favicon::FaviconDriver* favicon_driver = |
141 favicon::ContentFaviconDriver::FromWebContents(contents); | 128 favicon::ContentFaviconDriver::FromWebContents(contents); |
142 if (!favicon_driver) | 129 if (!favicon_driver) |
143 continue; | 130 continue; |
144 | 131 |
145 gfx::Image favicon = favicon_driver->GetFavicon(); | 132 gfx::Image favicon = favicon_driver->GetFavicon(); |
146 if (favicon.IsEmpty()) | 133 if (favicon.IsEmpty()) |
147 continue; | 134 continue; |
148 | 135 |
149 // Only new or changed favicon need update. | 136 // Only new or changed favicon need update. |
150 new_favicon_hashes[media_id] = GetImageHash(favicon); | 137 new_favicon_hashes[media_id] = |
138 DesktopMediaListBase::GetImageHash(favicon); | |
Sergey Ulanov
2016/03/10 00:46:08
I don't think you need DesktopMediaListBase:: here
GeorgeZ
2016/03/10 21:18:46
Done.
| |
151 if (!favicon_hashes_.count(media_id) || | 139 if (!favicon_hashes_.count(media_id) || |
152 (favicon_hashes_[media_id] != new_favicon_hashes[media_id])) { | 140 (favicon_hashes_[media_id] != new_favicon_hashes[media_id])) { |
153 gfx::ImageSkia image = favicon.AsImageSkia(); | 141 gfx::ImageSkia image = favicon.AsImageSkia(); |
154 image.MakeThreadSafe(); | 142 image.MakeThreadSafe(); |
155 favicon_pairs.push_back(std::make_pair(media_id, image)); | 143 favicon_pairs.push_back(std::make_pair(media_id, image)); |
156 } | 144 } |
157 } | 145 } |
158 } | 146 } |
159 favicon_hashes_ = new_favicon_hashes; | 147 favicon_hashes_ = new_favicon_hashes; |
160 | 148 |
(...skipping 15 matching lines...) Expand all Loading... | |
176 | 164 |
177 // ScheduleNextRefresh() needs to be called after all calls for | 165 // ScheduleNextRefresh() needs to be called after all calls for |
178 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted | 166 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted |
179 // to the same sequenced task runner that CreateEnlargedFaviconImag() | 167 // to the same sequenced task runner that CreateEnlargedFaviconImag() |
180 // is posted. | 168 // is posted. |
181 thumbnail_task_runner_.get()->PostTaskAndReply( | 169 thumbnail_task_runner_.get()->PostTaskAndReply( |
182 FROM_HERE, base::Bind(&base::DoNothing), | 170 FROM_HERE, base::Bind(&base::DoNothing), |
183 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, | 171 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, |
184 weak_factory_.GetWeakPtr())); | 172 weak_factory_.GetWeakPtr())); |
185 } | 173 } |
OLD | NEW |