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

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 1538773002: Reduce CPU usage of download shelf UI. (both MD and pre-MD shelves) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/download/download_item_view.h" 5 #include "chrome/browser/ui/views/download/download_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // ExperienceSampling: If the user took no action to remove the warning 229 // ExperienceSampling: If the user took no action to remove the warning
230 // before it disappeared, then the user effectively dismissed the download 230 // before it disappeared, then the user effectively dismissed the download
231 // without keeping it. 231 // without keeping it.
232 if (sampling_event_.get()) 232 if (sampling_event_.get())
233 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); 233 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore);
234 } 234 }
235 235
236 // Progress animation handlers. 236 // Progress animation handlers.
237 237
238 void DownloadItemView::StartDownloadProgress() { 238 void DownloadItemView::StartDownloadProgress() {
239 if (progress_timer_.IsRunning()) 239 if (progress_start_time_ != base::TimeTicks())
240 return; 240 return;
241 progress_start_time_ = base::TimeTicks::Now(); 241 progress_start_time_ = base::TimeTicks::Now();
242 progress_timer_.Start(
243 FROM_HERE,
244 base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs),
asanka 2015/12/18 03:39:16 Would you be willing to get rid of this 30ms timer
Evan Stade 2015/12/18 19:01:38 yea I meant to look at doing that, thanks for remi
Evan Stade 2015/12/29 18:50:49 This seems complicated enough that I'd want someon
245 base::Bind(&DownloadItemView::SchedulePaint, base::Unretained(this)));
246 } 242 }
247 243
248 void DownloadItemView::StopDownloadProgress() { 244 void DownloadItemView::StopDownloadProgress() {
249 if (!progress_timer_.IsRunning()) 245 if (progress_start_time_ == base::TimeTicks())
250 return; 246 return;
251 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; 247 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_;
252 progress_start_time_ = base::TimeTicks(); 248 progress_start_time_ = base::TimeTicks();
253 progress_timer_.Stop();
254 } 249 }
255 250
256 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { 251 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) {
257 if (icon_bitmap) 252 if (icon_bitmap)
258 shelf_->SchedulePaint(); 253 shelf_->SchedulePaint();
259 } 254 }
260 255
261 // DownloadObserver interface. 256 // DownloadObserver interface.
262 257
263 // Update the progress graphic on the icon and our text status label 258 // Update the progress graphic on the icon and our text status label
(...skipping 13 matching lines...) Expand all
277 ShowWarningDialog(); 272 ShowWarningDialog();
278 // Force the shelf to layout again as our size has changed. 273 // Force the shelf to layout again as our size has changed.
279 shelf_->Layout(); 274 shelf_->Layout();
280 SchedulePaint(); 275 SchedulePaint();
281 } else { 276 } else {
282 base::string16 status_text = model_.GetStatusText(); 277 base::string16 status_text = model_.GetStatusText();
283 switch (download()->GetState()) { 278 switch (download()->GetState()) {
284 case DownloadItem::IN_PROGRESS: 279 case DownloadItem::IN_PROGRESS:
285 download()->IsPaused() ? 280 download()->IsPaused() ?
286 StopDownloadProgress() : StartDownloadProgress(); 281 StopDownloadProgress() : StartDownloadProgress();
282 SchedulePaint();
287 LoadIconIfItemPathChanged(); 283 LoadIconIfItemPathChanged();
288 break; 284 break;
289 case DownloadItem::INTERRUPTED: 285 case DownloadItem::INTERRUPTED:
290 StopDownloadProgress(); 286 StopDownloadProgress();
291 complete_animation_.reset(new gfx::SlideAnimation(this)); 287 complete_animation_.reset(new gfx::SlideAnimation(this));
292 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); 288 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs);
293 complete_animation_->SetTweenType(gfx::Tween::LINEAR); 289 complete_animation_->SetTweenType(gfx::Tween::LINEAR);
294 complete_animation_->Show(); 290 complete_animation_->Show();
295 SchedulePaint(); 291 SchedulePaint();
296 LoadIcon(); 292 LoadIcon();
(...skipping 23 matching lines...) Expand all
320 status_text_ = status_text; 316 status_text_ = status_text;
321 } 317 }
322 318
323 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); 319 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth);
324 if (new_tip != tooltip_text_) { 320 if (new_tip != tooltip_text_) {
325 tooltip_text_ = new_tip; 321 tooltip_text_ = new_tip;
326 TooltipTextChanged(); 322 TooltipTextChanged();
327 } 323 }
328 324
329 UpdateAccessibleName(); 325 UpdateAccessibleName();
330
331 // We use the parent's (DownloadShelfView's) SchedulePaint, since there
332 // are spaces between each DownloadItemView that the parent is responsible
333 // for painting.
334 shelf_->SchedulePaint();
335 } 326 }
336 327
337 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) { 328 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) {
338 shelf_->RemoveDownloadView(this); // This will delete us! 329 shelf_->RemoveDownloadView(this); // This will delete us!
339 } 330 }
340 331
341 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { 332 void DownloadItemView::OnDownloadOpened(DownloadItem* download) {
342 disabled_while_opening_ = true; 333 disabled_while_opening_ = true;
343 SetEnabled(false); 334 SetEnabled(false);
344 base::MessageLoop::current()->task_runner()->PostDelayedTask( 335 base::MessageLoop::current()->task_runner()->PostDelayedTask(
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 void DownloadItemView::AnimateStateTransition(State from, State to, 1380 void DownloadItemView::AnimateStateTransition(State from, State to,
1390 gfx::SlideAnimation* animation) { 1381 gfx::SlideAnimation* animation) {
1391 if (from == NORMAL && to == HOT) { 1382 if (from == NORMAL && to == HOT) {
1392 animation->Show(); 1383 animation->Show();
1393 } else if (from == HOT && to == NORMAL) { 1384 } else if (from == HOT && to == NORMAL) {
1394 animation->Hide(); 1385 animation->Hide();
1395 } else if (from != to) { 1386 } else if (from != to) {
1396 animation->Reset((to == HOT) ? 1.0 : 0.0); 1387 animation->Reset((to == HOT) ? 1.0 : 0.0);
1397 } 1388 }
1398 } 1389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698