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

Side by Side 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: schedule next refresh 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 thumbnail_task_runner_ = 66 thumbnail_task_runner_ =
67 worker_pool->GetSequencedTaskRunner(worker_pool->GetSequenceToken()); 67 worker_pool->GetSequencedTaskRunner(worker_pool->GetSequenceToken());
68 } 68 }
69 69
70 TabDesktopMediaList::~TabDesktopMediaList() {} 70 TabDesktopMediaList::~TabDesktopMediaList() {}
71 71
72 void TabDesktopMediaList::Refresh() { 72 void TabDesktopMediaList::Refresh() {
73 DCHECK_CURRENTLY_ON(BrowserThread::UI); 73 DCHECK_CURRENTLY_ON(BrowserThread::UI);
74 74
75 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); 75 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
76 if (!profile) {
77 ScheduleNextRefresh();
78 return;
79 }
80
76 std::vector<Browser*> browsers; 81 std::vector<Browser*> browsers;
77 for (auto* browser : *BrowserList::GetInstance()) { 82 for (auto* browser : *BrowserList::GetInstance()) {
78 if (browser->profile()->GetOriginalProfile() == 83 if (browser->profile()->GetOriginalProfile() ==
79 profile->GetOriginalProfile()) { 84 profile->GetOriginalProfile()) {
80 browsers.push_back(browser); 85 browsers.push_back(browser);
81 } 86 }
82 } 87 }
83 88
84 ImageHashesMap new_favicon_hashes; 89 ImageHashesMap new_favicon_hashes;
85 std::vector<SourceDescription> sources; 90 std::vector<SourceDescription> sources;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 (favicon_hashes_[media_id] != new_favicon_hashes[media_id])) { 128 (favicon_hashes_[media_id] != new_favicon_hashes[media_id])) {
124 gfx::ImageSkia image = favicon.AsImageSkia(); 129 gfx::ImageSkia image = favicon.AsImageSkia();
125 image.MakeThreadSafe(); 130 image.MakeThreadSafe();
126 favicon_pairs.push_back(std::make_pair(media_id, image)); 131 favicon_pairs.push_back(std::make_pair(media_id, image));
127 } 132 }
128 } 133 }
129 } 134 }
130 favicon_hashes_ = new_favicon_hashes; 135 favicon_hashes_ = new_favicon_hashes;
131 136
132 // Sort tab sources by time. Most recent one first. Then update sources list. 137 // Sort tab sources by time. Most recent one first. Then update sources list.
133 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) { 138 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it)
134 sources.push_back(it->second); 139 sources.push_back(it->second);
135 } 140
136 UpdateSourcesList(sources); 141 UpdateSourcesList(sources);
137 142
138 for (const auto& it : favicon_pairs) { 143 for (const auto& it : favicon_pairs) {
139 // Create a thumbail in a different thread and update the thumbnail in 144 // Create a thumbail in a different thread and update the thumbnail in
140 // current thread. 145 // current thread.
141 base::PostTaskAndReplyWithResult( 146 base::PostTaskAndReplyWithResult(
142 thumbnail_task_runner_.get(), FROM_HERE, 147 thumbnail_task_runner_.get(), FROM_HERE,
143 base::Bind(&CreateEnclosedFaviconImage, thumbnail_size_, it.second), 148 base::Bind(&CreateEnclosedFaviconImage, thumbnail_size_, it.second),
144 base::Bind(&TabDesktopMediaList::UpdateSourceThumbnail, 149 base::Bind(&TabDesktopMediaList::UpdateSourceThumbnail,
145 weak_factory_.GetWeakPtr(), it.first)); 150 weak_factory_.GetWeakPtr(), it.first));
146 } 151 }
147 152
148 // ScheduleNextRefresh() needs to be called after all calls for 153 // ScheduleNextRefresh() needs to be called after all calls for
149 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted 154 // UpdateSourceThumbnail() have done. Therefore, a DoNothing task is posted
150 // to the same sequenced task runner that CreateEnlargedFaviconImag() 155 // to the same sequenced task runner that CreateEnlargedFaviconImag()
151 // is posted. 156 // is posted.
152 thumbnail_task_runner_.get()->PostTaskAndReply( 157 thumbnail_task_runner_.get()->PostTaskAndReply(
153 FROM_HERE, base::Bind(&base::DoNothing), 158 FROM_HERE, base::Bind(&base::DoNothing),
154 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh, 159 base::Bind(&TabDesktopMediaList::ScheduleNextRefresh,
155 weak_factory_.GetWeakPtr())); 160 weak_factory_.GetWeakPtr()));
156 } 161 }
OLDNEW
« 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