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

Unified Diff: chrome/browser/media/tab_desktop_media_list.cc

Issue 2307083002: Cleanup: move WebRTC related files from chrome/browser/media to chrome/browser/media/webrtc/ (Closed)
Patch Set: Removed file wrongly resuscitated during rebase Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/tab_desktop_media_list.cc
diff --git a/chrome/browser/media/tab_desktop_media_list.cc b/chrome/browser/media/tab_desktop_media_list.cc
deleted file mode 100644
index 39136c9650b80892ace9a4a524bfeb66c05b6f12..0000000000000000000000000000000000000000
--- a/chrome/browser/media/tab_desktop_media_list.cc
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/media/tab_desktop_media_list.h"
-
-#include "base/hash.h"
-#include "base/threading/sequenced_worker_pool.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "components/favicon/content/content_favicon_driver.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_process_host.h"
-#include "media/base/video_util.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "third_party/skia/include/core/SkImage.h"
-#include "ui/gfx/image/image.h"
-
-using content::BrowserThread;
-using content::DesktopMediaID;
-
-namespace {
-
-gfx::ImageSkia CreateEnclosedFaviconImage(gfx::Size size,
- const gfx::ImageSkia& favicon) {
- DCHECK_GE(size.width(), 20);
- DCHECK_GE(size.height(), 20);
-
- // Create a bitmap.
- SkBitmap result;
- result.allocN32Pixels(size.width(), size.height(), false);
- SkCanvas canvas(result);
- canvas.clear(SK_ColorTRANSPARENT);
-
- // Draw the favicon image into the center of result image. If the favicon is
- // too big, scale it down.
- gfx::Size fill_size = favicon.size();
- if (result.width() < favicon.width() || result.height() < favicon.height())
- fill_size = media::ScaleSizeToFitWithinTarget(favicon.size(), size);
-
- gfx::Rect center_rect(result.width(), result.height());
- center_rect.ClampToCenteredSize(fill_size);
- SkRect dest_rect =
- SkRect::MakeLTRB(center_rect.x(), center_rect.y(), center_rect.right(),
- center_rect.bottom());
- canvas.drawBitmapRect(*favicon.bitmap(), dest_rect, nullptr);
-
- return gfx::ImageSkia::CreateFrom1xBitmap(result);
-}
-
-// Update the list once per second.
-const int kDefaultUpdatePeriod = 1000;
-
-} // namespace
-
-TabDesktopMediaList::TabDesktopMediaList()
- : DesktopMediaListBase(
- base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)),
- weak_factory_(this) {
- base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool();
- thumbnail_task_runner_ =
- worker_pool->GetSequencedTaskRunner(worker_pool->GetSequenceToken());
-}
-
-TabDesktopMediaList::~TabDesktopMediaList() {}
-
-void TabDesktopMediaList::Refresh() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
- if (!profile) {
- ScheduleNextRefresh();
- return;
- }
-
- std::vector<Browser*> browsers;
- for (auto* browser : *BrowserList::GetInstance()) {
- if (browser->profile()->GetOriginalProfile() ==
- profile->GetOriginalProfile()) {
- browsers.push_back(browser);
- }
- }
-
- ImageHashesMap new_favicon_hashes;
- std::vector<SourceDescription> sources;
- std::map<base::TimeTicks, SourceDescription> tab_map;
- std::vector<std::pair<DesktopMediaID, gfx::ImageSkia>> favicon_pairs;
-
- // Enumerate all tabs with their titles and favicons for a user profile.
- for (auto* browser : browsers) {
- const TabStripModel* tab_strip_model = browser->tab_strip_model();
- DCHECK(tab_strip_model);
-
- for (int i = 0; i < tab_strip_model->count(); i++) {
- // Create id for tab.
- content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
- DCHECK(contents);
- content::RenderFrameHost* main_frame = contents->GetMainFrame();
- DCHECK(main_frame);
- DesktopMediaID media_id(
- DesktopMediaID::TYPE_WEB_CONTENTS, DesktopMediaID::kNullId,
- content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(),
- main_frame->GetRoutingID()));
-
- // Get tab's last active time stamp.
- const base::TimeTicks t = contents->GetLastActiveTime();
- tab_map.insert(
- std::make_pair(t, SourceDescription(media_id, contents->GetTitle())));
-
- // Get favicon for tab.
- favicon::FaviconDriver* favicon_driver =
- favicon::ContentFaviconDriver::FromWebContents(contents);
- if (!favicon_driver)
- continue;
-
- gfx::Image favicon = favicon_driver->GetFavicon();
- if (favicon.IsEmpty())
- continue;
-
- // Only new or changed favicon need update.
- new_favicon_hashes[media_id] = GetImageHash(favicon);
- if (!favicon_hashes_.count(media_id) ||
- (favicon_hashes_[media_id] != new_favicon_hashes[media_id])) {
- gfx::ImageSkia image = favicon.AsImageSkia();
- image.MakeThreadSafe();
- favicon_pairs.push_back(std::make_pair(media_id, image));
- }
- }
- }
- favicon_hashes_ = new_favicon_hashes;
-
- // Sort tab sources by time. Most recent one first. Then update sources list.
- for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it)
- sources.push_back(it->second);
-
- UpdateSourcesList(sources);
-
- for (const auto& it : favicon_pairs) {
- // Create a thumbail in a different thread and update the thumbnail in
- // current thread.
- base::PostTaskAndReplyWithResult(
- thumbnail_task_runner_.get(), FROM_HERE,
- base::Bind(&CreateEnclosedFaviconImage, thumbnail_size_, it.second),
- base::Bind(&TabDesktopMediaList::UpdateSourceThumbnail,
- weak_factory_.GetWeakPtr(), it.first));
- }
-
- // ScheduleNextRefresh() needs to be called after all calls for
- // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted
- // to the same sequenced task runner that CreateEnlargedFaviconImag()
- // is posted.
- thumbnail_task_runner_.get()->PostTaskAndReply(
- FROM_HERE, base::Bind(&base::DoNothing),
- base::Bind(&TabDesktopMediaList::ScheduleNextRefresh,
- weak_factory_.GetWeakPtr()));
-}
« no previous file with comments | « chrome/browser/media/tab_desktop_media_list.h ('k') | chrome/browser/media/tab_desktop_media_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698