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

Side by Side Diff: chrome/browser/ui/cocoa/task_manager_mac.mm

Issue 2187993002: Remove the TableRowNSImageCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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/cocoa/task_manager_mac.h" 5 #include "chrome/browser/ui/cocoa/task_manager_mac.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>
11 11
12 #include "base/mac/bundle_locations.h" 12 #include "base/mac/bundle_locations.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/task_management/task_manager_interface.h" 16 #include "chrome/browser/task_management/task_manager_interface.h"
17 #include "chrome/browser/task_manager/task_manager.h" 17 #include "chrome/browser/task_manager/task_manager.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_dialogs.h" 19 #include "chrome/browser/ui/browser_dialogs.h"
20 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" 20 #import "chrome/browser/ui/cocoa/window_size_autosaver.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/base/l10n/l10n_util_mac.h" 25 #include "ui/base/l10n/l10n_util_mac.h"
26 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
27 #include "ui/gfx/image/image_skia_util_mac.h"
27 28
28 namespace { 29 namespace {
29 30
30 // Width of "a" and most other letters/digits in "small" table views. 31 // Width of "a" and most other letters/digits in "small" table views.
31 const int kCharWidth = 6; 32 const int kCharWidth = 6;
32 33
33 // Some of the strings below have spaces at the end or are missing letters, to 34 // Some of the strings below have spaces at the end or are missing letters, to
34 // make the columns look nicer, and to take potentially longer localized strings 35 // make the columns look nicer, and to take potentially longer localized strings
35 // into account. 36 // into account.
36 const struct ColumnWidth { 37 const struct ColumnWidth {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 [self reloadData]; // Sorts. 505 [self reloadData]; // Sorts.
505 } 506 }
506 507
507 @end 508 @end
508 509
509 //////////////////////////////////////////////////////////////////////////////// 510 ////////////////////////////////////////////////////////////////////////////////
510 // TaskManagerMac implementation: 511 // TaskManagerMac implementation:
511 512
512 TaskManagerMac::TaskManagerMac(TaskManager* task_manager) 513 TaskManagerMac::TaskManagerMac(TaskManager* task_manager)
513 : task_manager_(task_manager), 514 : task_manager_(task_manager),
514 model_(task_manager->model()), 515 model_(task_manager->model()) {
515 icon_cache_(this) {
516 window_controller_ = 516 window_controller_ =
517 [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this]; 517 [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this];
518 model_->AddObserver(this); 518 model_->AddObserver(this);
519 } 519 }
520 520
521 // static 521 // static
522 TaskManagerMac* TaskManagerMac::instance_ = NULL; 522 TaskManagerMac* TaskManagerMac::instance_ = NULL;
523 523
524 TaskManagerMac::~TaskManagerMac() { 524 TaskManagerMac::~TaskManagerMac() {
525 if (this == instance_) { 525 if (this == instance_) {
526 // Do not do this when running in unit tests: |StartUpdating()| never got 526 // Do not do this when running in unit tests: |StartUpdating()| never got
527 // called in that case. 527 // called in that case.
528 task_manager_->OnWindowClosed(); 528 task_manager_->OnWindowClosed();
529 } 529 }
530 model_->RemoveObserver(this); 530 model_->RemoveObserver(this);
531 } 531 }
532 532
533 //////////////////////////////////////////////////////////////////////////////// 533 ////////////////////////////////////////////////////////////////////////////////
534 // TaskManagerMac, TaskManagerModelObserver implementation: 534 // TaskManagerMac, TaskManagerModelObserver implementation:
535 535
536 void TaskManagerMac::OnModelChanged() { 536 void TaskManagerMac::OnModelChanged() {
537 icon_cache_.OnModelChanged();
538 [window_controller_ deselectRows]; 537 [window_controller_ deselectRows];
539 [window_controller_ reloadData]; 538 [window_controller_ reloadData];
540 } 539 }
541 540
542 void TaskManagerMac::OnItemsChanged(int start, int length) { 541 void TaskManagerMac::OnItemsChanged(int start, int length) {
543 icon_cache_.OnItemsChanged(start, length);
544 [window_controller_ reloadData]; 542 [window_controller_ reloadData];
545 } 543 }
546 544
547 void TaskManagerMac::OnItemsAdded(int start, int length) { 545 void TaskManagerMac::OnItemsAdded(int start, int length) {
548 icon_cache_.OnItemsAdded(start, length);
549 [window_controller_ deselectRows]; 546 [window_controller_ deselectRows];
550 [window_controller_ reloadData]; 547 [window_controller_ reloadData];
551 } 548 }
552 549
553 void TaskManagerMac::OnItemsRemoved(int start, int length) { 550 void TaskManagerMac::OnItemsRemoved(int start, int length) {
554 icon_cache_.OnItemsRemoved(start, length);
555 [window_controller_ deselectRows]; 551 [window_controller_ deselectRows];
556 [window_controller_ reloadData]; 552 [window_controller_ reloadData];
557 } 553 }
558 554
559 NSImage* TaskManagerMac::GetImageForRow(int row) { 555 NSImage* TaskManagerMac::GetImageForRow(int row) {
560 return icon_cache_.GetImageForRow(row); 556 return gfx::NSImageFromImageSkia(model_->GetResourceIcon(row));
561 } 557 }
562 558
563 //////////////////////////////////////////////////////////////////////////////// 559 ////////////////////////////////////////////////////////////////////////////////
564 // TaskManagerMac, public: 560 // TaskManagerMac, public:
565 561
566 void TaskManagerMac::WindowWasClosed() { 562 void TaskManagerMac::WindowWasClosed() {
567 delete this; 563 delete this;
568 instance_ = NULL; // |instance_| is static 564 instance_ = NULL; // |instance_| is static
569 } 565 }
570 566
571 int TaskManagerMac::RowCount() const {
572 return model_->ResourceCount();
573 }
574
575 gfx::ImageSkia TaskManagerMac::GetIcon(int r) const {
576 return model_->GetResourceIcon(r);
577 }
578
579 // static 567 // static
580 void TaskManagerMac::Show() { 568 void TaskManagerMac::Show() {
581 if (instance_) { 569 if (instance_) {
582 [[instance_->window_controller_ window] 570 [[instance_->window_controller_ window]
583 makeKeyAndOrderFront:instance_->window_controller_]; 571 makeKeyAndOrderFront:instance_->window_controller_];
584 return; 572 return;
585 } 573 }
586 // Create a new instance. 574 // Create a new instance.
587 instance_ = new TaskManagerMac(TaskManager::GetInstance()); 575 instance_ = new TaskManagerMac(TaskManager::GetInstance());
588 instance_->model_->StartUpdating(); 576 instance_->model_->StartUpdating();
(...skipping 29 matching lines...) Expand all
618 int64_t bytes_read) { 606 int64_t bytes_read) {
619 if (task_management::TaskManagerInterface::IsNewTaskManagerEnabled()) 607 if (task_management::TaskManagerInterface::IsNewTaskManagerEnabled())
620 return false; 608 return false;
621 609
622 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read); 610 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
623 return true; 611 return true;
624 } 612 }
625 613
626 } // namespace chrome 614 } // namespace chrome
627 615
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698