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

Side by Side Diff: chrome/browser/task_management/providers/web_contents/renderer_task.cc

Issue 1338023002: Refactor TaskManager's favicon retrieval approach (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/task_management/providers/web_contents/renderer_task.h" 5 #include "chrome/browser/task_management/providers/web_contents/renderer_task.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 renderer_resources_sampler_( 71 renderer_resources_sampler_(
72 CreateRendererResourcesSampler(render_process_host_)), 72 CreateRendererResourcesSampler(render_process_host_)),
73 render_process_id_(render_process_host_->GetID()), 73 render_process_id_(render_process_host_->GetID()),
74 v8_memory_allocated_(0), 74 v8_memory_allocated_(0),
75 v8_memory_used_(0), 75 v8_memory_used_(0),
76 webcache_stats_(), 76 webcache_stats_(),
77 profile_name_(GetRendererProfileName(render_process_host_)) { 77 profile_name_(GetRendererProfileName(render_process_host_)) {
78 // All renderer tasks are capable of reporting network usage, so the default 78 // All renderer tasks are capable of reporting network usage, so the default
79 // invalid value of -1 doesn't apply here. 79 // invalid value of -1 doesn't apply here.
80 OnNetworkBytesRead(0); 80 OnNetworkBytesRead(0);
81
82 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that
83 // we can use it to observe favicons changes.
84 favicon::CreateContentFaviconDriverForWebContents(web_contents);
85 favicon::ContentFaviconDriver::FromWebContents(web_contents)->AddObserver(
86 this);
81 } 87 }
82 88
83 RendererTask::~RendererTask() { 89 RendererTask::~RendererTask() {
90 favicon::ContentFaviconDriver::FromWebContents(web_contents())->
91 RemoveObserver(this);
84 } 92 }
85 93
86 void RendererTask::Activate() { 94 void RendererTask::Activate() {
87 if (!web_contents_->GetDelegate()) 95 if (!web_contents_->GetDelegate())
88 return; 96 return;
89 97
90 web_contents_->GetDelegate()->ActivateContents(web_contents_); 98 web_contents_->GetDelegate()->ActivateContents(web_contents_);
91 } 99 }
92 100
93 void RendererTask::Refresh(const base::TimeDelta& update_interval, 101 void RendererTask::Refresh(const base::TimeDelta& update_interval,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 139 }
132 140
133 bool RendererTask::ReportsWebCacheStats() const { 141 bool RendererTask::ReportsWebCacheStats() const {
134 return true; 142 return true;
135 } 143 }
136 144
137 blink::WebCache::ResourceTypeStats RendererTask::GetWebCacheStats() const { 145 blink::WebCache::ResourceTypeStats RendererTask::GetWebCacheStats() const {
138 return webcache_stats_; 146 return webcache_stats_;
139 } 147 }
140 148
149 void RendererTask::OnFaviconAvailable(const gfx::Image& image) {
150 // We ignore this event because it means the |image| has been retrieved, but
151 // not necessarily updated.
pkotwicz 2015/09/11 23:51:33 Can you remove this comment? OnFaviconAvailable()
afakhry 2015/09/12 00:42:21 I removed the comment. But I have to say I don't k
pkotwicz 2015/09/14 14:39:17 It is safe to ignore apple-touch-icons were added
152 }
153
154 void RendererTask::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
155 bool icon_url_changed) {
156 if (icon_url_changed)
ncarter (slow) 2015/09/11 20:08:45 What does it mean if this is called but |icon_url_
pkotwicz 2015/09/11 23:51:33 You actually want to call UpdateFavicon() even if
afakhry 2015/09/12 00:42:21 Thanks for the clarification. Done!
157 UpdateFavicon();
158 }
159
141 // static 160 // static
142 base::string16 RendererTask::GetTitleFromWebContents( 161 base::string16 RendererTask::GetTitleFromWebContents(
143 content::WebContents* web_contents) { 162 content::WebContents* web_contents) {
144 DCHECK(web_contents); 163 DCHECK(web_contents);
145 base::string16 title = web_contents->GetTitle(); 164 base::string16 title = web_contents->GetTitle();
146 if (title.empty()) { 165 if (title.empty()) {
147 GURL url = web_contents->GetURL(); 166 GURL url = web_contents->GetURL();
148 title = base::UTF8ToUTF16(url.spec()); 167 title = base::UTF8ToUTF16(url.spec());
149 // Force URL to be LTR. 168 // Force URL to be LTR.
150 title = base::i18n::GetDisplayStringInLTRDirectionality(title); 169 title = base::i18n::GetDisplayStringInLTRDirectionality(title);
(...skipping 10 matching lines...) Expand all
161 base::i18n::AdjustStringForLocaleDirection(&title); 180 base::i18n::AdjustStringForLocaleDirection(&title);
162 } 181 }
163 return title; 182 return title;
164 } 183 }
165 184
166 // static 185 // static
167 const gfx::ImageSkia* RendererTask::GetFaviconFromWebContents( 186 const gfx::ImageSkia* RendererTask::GetFaviconFromWebContents(
168 content::WebContents* web_contents) { 187 content::WebContents* web_contents) {
169 DCHECK(web_contents); 188 DCHECK(web_contents);
170 189
171 // Tag the web_contents with a |ContentFaviconDriver| (if needed) so that
172 // we can use it to retrieve the favicon if there is one.
173 favicon::CreateContentFaviconDriverForWebContents(web_contents);
174 gfx::Image image = 190 gfx::Image image =
175 favicon::ContentFaviconDriver::FromWebContents(web_contents)-> 191 favicon::ContentFaviconDriver::FromWebContents(web_contents)->
176 GetFavicon(); 192 GetFavicon();
177 if (image.IsEmpty()) 193 if (image.IsEmpty())
178 return nullptr; 194 return nullptr;
179 195
180 return image.ToImageSkia(); 196 return image.ToImageSkia();
181 } 197 }
182 198
183 // static 199 // static
(...skipping 18 matching lines...) Expand all
202 if (is_incognito) 218 if (is_incognito)
203 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; 219 message_id = IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX;
204 else 220 else
205 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX; 221 message_id = IDS_TASK_MANAGER_EXTENSION_PREFIX;
206 } 222 }
207 223
208 return l10n_util::GetStringFUTF16(message_id, title); 224 return l10n_util::GetStringFUTF16(message_id, title);
209 } 225 }
210 226
211 } // namespace task_management 227 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698