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

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: no change for indeterminate size dls Created 4 years, 11 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 (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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (sampling_event_.get()) 234 if (sampling_event_.get())
235 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); 235 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore);
236 } 236 }
237 237
238 // Progress animation handlers. 238 // Progress animation handlers.
239 239
240 void DownloadItemView::StartDownloadProgress() { 240 void DownloadItemView::StartDownloadProgress() {
241 if (progress_timer_.IsRunning()) 241 if (progress_timer_.IsRunning())
242 return; 242 return;
243 progress_start_time_ = base::TimeTicks::Now(); 243 progress_start_time_ = base::TimeTicks::Now();
244 progress_timer_.Start( 244 progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
245 FROM_HERE, 245 DownloadShelf::kProgressRateMs),
246 base::TimeDelta::FromMilliseconds(DownloadShelf::kProgressRateMs), 246 base::Bind(&DownloadItemView::ProgressTimerFired,
247 base::Bind(&DownloadItemView::SchedulePaint, base::Unretained(this))); 247 base::Unretained(this)));
248 } 248 }
249 249
250 void DownloadItemView::StopDownloadProgress() { 250 void DownloadItemView::StopDownloadProgress() {
251 if (!progress_timer_.IsRunning()) 251 if (!progress_timer_.IsRunning())
252 return; 252 return;
253 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_; 253 previous_progress_elapsed_ += base::TimeTicks::Now() - progress_start_time_;
254 progress_start_time_ = base::TimeTicks(); 254 progress_start_time_ = base::TimeTicks();
255 progress_timer_.Stop(); 255 progress_timer_.Stop();
256 } 256 }
257 257
(...skipping 12 matching lines...) Expand all
270 if (!model_.ShouldShowInShelf()) { 270 if (!model_.ShouldShowInShelf()) {
271 shelf_->RemoveDownloadView(this); // This will delete us! 271 shelf_->RemoveDownloadView(this); // This will delete us!
272 return; 272 return;
273 } 273 }
274 274
275 if (IsShowingWarningDialog() && !model_.IsDangerous()) { 275 if (IsShowingWarningDialog() && !model_.IsDangerous()) {
276 // We have been approved. 276 // We have been approved.
277 ClearWarningDialog(); 277 ClearWarningDialog();
278 } else if (!IsShowingWarningDialog() && model_.IsDangerous()) { 278 } else if (!IsShowingWarningDialog() && model_.IsDangerous()) {
279 ShowWarningDialog(); 279 ShowWarningDialog();
280 // Force the shelf to layout again as our size has changed. 280 // Force the shelf to layout again as our size has changed.
sky 2016/01/06 21:47:21 If you hit this, don't you need to SchedulePaint o
Evan Stade 2016/01/07 00:06:05 Indeed. ClearWarningDialog() does this but ShowWar
281 shelf_->Layout(); 281 shelf_->Layout();
282 SchedulePaint(); 282 SchedulePaint();
283 } else { 283 } else {
284 base::string16 status_text = model_.GetStatusText(); 284 base::string16 status_text = model_.GetStatusText();
285 switch (download()->GetState()) { 285 switch (download()->GetState()) {
286 case DownloadItem::IN_PROGRESS: 286 case DownloadItem::IN_PROGRESS:
287 download()->IsPaused() ? 287 download()->IsPaused() ?
288 StopDownloadProgress() : StartDownloadProgress(); 288 StopDownloadProgress() : StartDownloadProgress();
289 SchedulePaint();
289 LoadIconIfItemPathChanged(); 290 LoadIconIfItemPathChanged();
290 break; 291 break;
291 case DownloadItem::INTERRUPTED: 292 case DownloadItem::INTERRUPTED:
292 StopDownloadProgress(); 293 StopDownloadProgress();
293 complete_animation_.reset(new gfx::SlideAnimation(this)); 294 complete_animation_.reset(new gfx::SlideAnimation(this));
294 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs); 295 complete_animation_->SetSlideDuration(kInterruptedAnimationDurationMs);
295 complete_animation_->SetTweenType(gfx::Tween::LINEAR); 296 complete_animation_->SetTweenType(gfx::Tween::LINEAR);
296 complete_animation_->Show(); 297 complete_animation_->Show();
297 SchedulePaint(); 298 SchedulePaint();
298 LoadIcon(); 299 LoadIcon();
(...skipping 23 matching lines...) Expand all
322 status_text_ = status_text; 323 status_text_ = status_text;
323 } 324 }
324 325
325 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth); 326 base::string16 new_tip = model_.GetTooltipText(font_list_, kTooltipMaxWidth);
326 if (new_tip != tooltip_text_) { 327 if (new_tip != tooltip_text_) {
327 tooltip_text_ = new_tip; 328 tooltip_text_ = new_tip;
328 TooltipTextChanged(); 329 TooltipTextChanged();
329 } 330 }
330 331
331 UpdateAccessibleName(); 332 UpdateAccessibleName();
332
333 // We use the parent's (DownloadShelfView's) SchedulePaint, since there
334 // are spaces between each DownloadItemView that the parent is responsible
335 // for painting.
336 shelf_->SchedulePaint();
337 } 333 }
338 334
339 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) { 335 void DownloadItemView::OnDownloadDestroyed(DownloadItem* download) {
340 shelf_->RemoveDownloadView(this); // This will delete us! 336 shelf_->RemoveDownloadView(this); // This will delete us!
341 } 337 }
342 338
343 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { 339 void DownloadItemView::OnDownloadOpened(DownloadItem* download) {
344 disabled_while_opening_ = true; 340 disabled_while_opening_ = true;
345 SetEnabled(false); 341 SetEnabled(false);
346 base::MessageLoop::current()->task_runner()->PostDelayedTask( 342 base::MessageLoop::current()->task_runner()->PostDelayedTask(
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 void DownloadItemView::AnimateStateTransition(State from, State to, 1387 void DownloadItemView::AnimateStateTransition(State from, State to,
1392 gfx::SlideAnimation* animation) { 1388 gfx::SlideAnimation* animation) {
1393 if (from == NORMAL && to == HOT) { 1389 if (from == NORMAL && to == HOT) {
1394 animation->Show(); 1390 animation->Show();
1395 } else if (from == HOT && to == NORMAL) { 1391 } else if (from == HOT && to == NORMAL) {
1396 animation->Hide(); 1392 animation->Hide();
1397 } else if (from != to) { 1393 } else if (from != to) {
1398 animation->Reset((to == HOT) ? 1.0 : 0.0); 1394 animation->Reset((to == HOT) ? 1.0 : 0.0);
1399 } 1395 }
1400 } 1396 }
1397
1398 void DownloadItemView::ProgressTimerFired() {
1399 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only
1400 // when there's an update notified via OnDownloadUpdated().
1401 if (model_.PercentComplete() < 0)
1402 SchedulePaint();
Evan Stade 2016/01/06 19:34:10 I reverted the change for indeterminate size downl
asanka 2016/01/06 19:44:28 Understood. I agree that we aren't conveying 30fps
1403 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_item_view.h ('k') | chrome/browser/ui/views/download/download_item_view_md.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698