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

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

Issue 2240823003: Avoid a crash in ProfileManager::GetLastUsedProfileAllowedByPolicy() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid a crash in ProfileManager::GetLastUsedProfileAllowedByPolicy() Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 76a1bb839512bbec99851123f95a128613097068..c370f1bef615fccfe21191bece1b03a302c61780 100644
--- a/chrome/browser/media/tab_desktop_media_list.cc
+++ b/chrome/browser/media/tab_desktop_media_list.cc
@@ -73,78 +73,80 @@ void TabDesktopMediaList::Refresh() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
- std::vector<Browser*> browsers;
- for (auto* browser : *BrowserList::GetInstance()) {
- if (browser->profile()->GetOriginalProfile() ==
- profile->GetOriginalProfile()) {
- browsers.push_back(browser);
+ if (profile) {
tommi (sloooow) - chröme 2016/08/17 11:38:00 nit: Change to an early return?
afakhry 2016/08/17 15:33:00 Do we need to execute the ScheduleNextRefresh at t
Sergey Ulanov 2016/08/18 05:42:26 If profile can change then the answer is yes. Mayb
afakhry 2016/08/18 16:36:51 It seems from the comment above the PostTaskAndRep
+ 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));
+ 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;
+ 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));
+ // 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()
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698