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

Side by Side Diff: ash/system/cast/tray_cast.cc

Issue 1169903002: Fix crash when opening up the status tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Perform initialization in class body Created 5 years, 6 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/system/cast/tray_cast.h" 5 #include "ash/system/cast/tray_cast.h"
6 6
7 #include "ash/session/session_state_delegate.h" 7 #include "ash/session/session_state_delegate.h"
8 #include "ash/shelf/shelf_types.h" 8 #include "ash/shelf/shelf_types.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/screen_security/screen_tray_item.h" 10 #include "ash/system/chromeos/screen_security/screen_tray_item.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // Updates the label based on the current set of receivers (if there are or 54 // Updates the label based on the current set of receivers (if there are or
55 // are not any available receivers). 55 // are not any available receivers).
56 void UpdateLabel(); 56 void UpdateLabel();
57 57
58 private: 58 private:
59 void UpdateLabelCallback( 59 void UpdateLabelCallback(
60 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); 60 const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
61 61
62 CastConfigDelegate* cast_config_delegate_; 62 CastConfigDelegate* cast_config_delegate_;
63 base::WeakPtrFactory<CastSelectDefaultView> weak_ptr_factory_;
63 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); 64 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView);
64 }; 65 };
65 66
66 CastSelectDefaultView::CastSelectDefaultView( 67 CastSelectDefaultView::CastSelectDefaultView(
67 SystemTrayItem* owner, 68 SystemTrayItem* owner,
68 CastConfigDelegate* cast_config_delegate, 69 CastConfigDelegate* cast_config_delegate,
69 bool show_more) 70 bool show_more)
70 : TrayItemMore(owner, show_more), 71 : TrayItemMore(owner, show_more),
71 cast_config_delegate_(cast_config_delegate) { 72 cast_config_delegate_(cast_config_delegate),
73 weak_ptr_factory_(this) {
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
73 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); 75 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia());
74 76
75 // We first set a default label before we actually know what the label will 77 // We first set a default label before we actually know what the label will
76 // be, because it could take awhile before UpdateLabel() actually applies 78 // be, because it could take awhile before UpdateLabel() actually applies
77 // the correct label. 79 // the correct label.
78 SetLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE)); 80 SetLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE));
79 UpdateLabel(); 81 UpdateLabel();
80 } 82 }
81 83
(...skipping 10 matching lines...) Expand all
92 SetLabel(label); 94 SetLabel(label);
93 SetAccessibleName(label); 95 SetAccessibleName(label);
94 SetVisible(true); 96 SetVisible(true);
95 } 97 }
96 98
97 void CastSelectDefaultView::UpdateLabel() { 99 void CastSelectDefaultView::UpdateLabel() {
98 if (cast_config_delegate_ == nullptr || 100 if (cast_config_delegate_ == nullptr ||
99 cast_config_delegate_->HasCastExtension() == false) 101 cast_config_delegate_->HasCastExtension() == false)
100 return; 102 return;
101 103
102 cast_config_delegate_->GetReceiversAndActivities(base::Bind( 104 cast_config_delegate_->GetReceiversAndActivities(
103 &CastSelectDefaultView::UpdateLabelCallback, base::Unretained(this))); 105 base::Bind(&CastSelectDefaultView::UpdateLabelCallback,
106 weak_ptr_factory_.GetWeakPtr()));
104 } 107 }
105 108
106 // This view is displayed when the screen is actively being casted; it allows 109 // This view is displayed when the screen is actively being casted; it allows
107 // the user to easily stop casting. It fully replaces the 110 // the user to easily stop casting. It fully replaces the
108 // |CastSelectDefaultView| view inside of the |CastDuplexView|. 111 // |CastSelectDefaultView| view inside of the |CastDuplexView|.
109 class CastCastView : public views::View, public views::ButtonListener { 112 class CastCastView : public views::View, public views::ButtonListener {
110 public: 113 public:
111 explicit CastCastView(CastConfigDelegate* cast_config_delegate); 114 explicit CastCastView(CastConfigDelegate* cast_config_delegate);
112 ~CastCastView() override; 115 ~CastCastView() override;
113 116
114 // Updates the label for the stop view to include information about the 117 // Updates the label for the stop view to include information about the
115 // current device that is being casted. 118 // current device that is being casted.
116 void UpdateLabel(); 119 void UpdateLabel();
117 120
118 private: 121 private:
119 void UpdateLabelCallback( 122 void UpdateLabelCallback(
120 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); 123 const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
121 124
122 // Overridden from views::View. 125 // Overridden from views::View.
123 void Layout() override; 126 void Layout() override;
124 // Overridden from views::ButtonListener 127 // Overridden from views::ButtonListener
125 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 128 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
126 129
127 CastConfigDelegate* cast_config_delegate_; 130 CastConfigDelegate* cast_config_delegate_;
128 views::ImageView* icon_; 131 views::ImageView* icon_;
129 views::View* label_container_; 132 views::View* label_container_;
130 views::Label* title_; 133 views::Label* title_;
131 views::Label* details_; 134 views::Label* details_;
132 TrayPopupLabelButton* stop_button_; 135 TrayPopupLabelButton* stop_button_;
136 base::WeakPtrFactory<CastCastView> weak_ptr_factory_;
133 137
134 DISALLOW_COPY_AND_ASSIGN(CastCastView); 138 DISALLOW_COPY_AND_ASSIGN(CastCastView);
135 }; 139 };
136 140
137 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) 141 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate)
138 : cast_config_delegate_(cast_config_delegate) { 142 : cast_config_delegate_(cast_config_delegate), weak_ptr_factory_(this) {
139 // We will initialize the primary tray view which shows a stop button here. 143 // We will initialize the primary tray view which shows a stop button here.
140 144
141 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 145 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
142 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 146 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
143 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 147 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
144 kTrayPopupPaddingHorizontal, 0, 148 kTrayPopupPaddingHorizontal, 0,
145 kTrayPopupPaddingBetweenItems)); 149 kTrayPopupPaddingBetweenItems));
146 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); 150 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
147 icon_->SetImage( 151 icon_->SetImage(
148 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); 152 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const int extra_height = 213 const int extra_height =
210 height() - label_container_->GetPreferredSize().height(); 214 height() - label_container_->GetPreferredSize().height();
211 label_container_->SetY(extra_height / 2); 215 label_container_->SetY(extra_height / 2);
212 } 216 }
213 217
214 void CastCastView::UpdateLabel() { 218 void CastCastView::UpdateLabel() {
215 if (cast_config_delegate_ == nullptr || 219 if (cast_config_delegate_ == nullptr ||
216 cast_config_delegate_->HasCastExtension() == false) 220 cast_config_delegate_->HasCastExtension() == false)
217 return; 221 return;
218 222
219 cast_config_delegate_->GetReceiversAndActivities( 223 cast_config_delegate_->GetReceiversAndActivities(base::Bind(
220 base::Bind(&CastCastView::UpdateLabelCallback, base::Unretained(this))); 224 &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr()));
221 } 225 }
222 226
223 void CastCastView::UpdateLabelCallback( 227 void CastCastView::UpdateLabelCallback(
224 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { 228 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
225 for (auto& i : receivers_activities) { 229 for (auto& i : receivers_activities) {
226 const CastConfigDelegate::Receiver receiver = i.second.receiver; 230 const CastConfigDelegate::Receiver receiver = i.second.receiver;
227 const CastConfigDelegate::Activity activity = i.second.activity; 231 const CastConfigDelegate::Activity activity = i.second.activity;
228 if (!activity.id.empty()) { 232 if (!activity.id.empty()) {
229 // We want to display different labels inside of the title depending on 233 // We want to display different labels inside of the title depending on
230 // what we are actually casting - either the desktop, a tab, or a fallback 234 // what we are actually casting - either the desktop, a tab, or a fallback
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); 402 const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
399 403
400 void AppendSettingsEntries(); 404 void AppendSettingsEntries();
401 void AppendHeaderEntry(); 405 void AppendHeaderEntry();
402 406
403 // Overridden from ViewClickListener. 407 // Overridden from ViewClickListener.
404 void OnViewClicked(views::View* sender) override; 408 void OnViewClicked(views::View* sender) override;
405 409
406 CastConfigDelegate* cast_config_delegate_; 410 CastConfigDelegate* cast_config_delegate_;
407 user::LoginStatus login_; 411 user::LoginStatus login_;
408 views::View* options_; 412 views::View* options_ = nullptr;
409 CastConfigDelegate::ReceiversAndActivites receivers_and_activities_; 413 CastConfigDelegate::ReceiversAndActivites receivers_and_activities_;
410 // A mapping from the view pointer to the associated activity id 414 // A mapping from the view pointer to the associated activity id
411 std::map<views::View*, std::string> receiver_activity_map_; 415 std::map<views::View*, std::string> receiver_activity_map_;
416 base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_;
412 417
413 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); 418 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
414 }; 419 };
415 420
416 CastDetailedView::CastDetailedView(SystemTrayItem* owner, 421 CastDetailedView::CastDetailedView(SystemTrayItem* owner,
417 CastConfigDelegate* cast_config_delegate, 422 CastConfigDelegate* cast_config_delegate,
418 user::LoginStatus login) 423 user::LoginStatus login)
419 : TrayDetailsView(owner), 424 : TrayDetailsView(owner),
420 cast_config_delegate_(cast_config_delegate), 425 cast_config_delegate_(cast_config_delegate),
421 login_(login), 426 login_(login),
422 options_(nullptr) { 427 weak_ptr_factory_(this) {
423 CreateItems(); 428 CreateItems();
424 UpdateReceiverList(); 429 UpdateReceiverList();
425 } 430 }
426 431
427 CastDetailedView::~CastDetailedView() { 432 CastDetailedView::~CastDetailedView() {
428 } 433 }
429 434
430 void CastDetailedView::CreateItems() { 435 void CastDetailedView::CreateItems() {
431 CreateScrollableList(); 436 CreateScrollableList();
432 AppendSettingsEntries(); 437 AppendSettingsEntries();
433 AppendHeaderEntry(); 438 AppendHeaderEntry();
434 } 439 }
435 440
436 void CastDetailedView::UpdateReceiverList() { 441 void CastDetailedView::UpdateReceiverList() {
437 cast_config_delegate_->GetReceiversAndActivities(base::Bind( 442 cast_config_delegate_->GetReceiversAndActivities(
438 &CastDetailedView::UpdateReceiverListCallback, base::Unretained(this))); 443 base::Bind(&CastDetailedView::UpdateReceiverListCallback,
444 weak_ptr_factory_.GetWeakPtr()));
439 } 445 }
440 446
441 void CastDetailedView::UpdateReceiverListCallback( 447 void CastDetailedView::UpdateReceiverListCallback(
442 const CastConfigDelegate::ReceiversAndActivites& 448 const CastConfigDelegate::ReceiversAndActivites&
443 new_receivers_and_activities) { 449 new_receivers_and_activities) {
444 // Add/update existing. 450 // Add/update existing.
445 for (auto i = new_receivers_and_activities.begin(); 451 for (auto i = new_receivers_and_activities.begin();
446 i != new_receivers_and_activities.end(); ++i) { 452 i != new_receivers_and_activities.end(); ++i) {
447 receivers_and_activities_[i->first] = i->second; 453 receivers_and_activities_[i->first] = i->second;
448 } 454 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 is_casting_ = started; 621 is_casting_ = started;
616 UpdatePrimaryView(); 622 UpdatePrimaryView();
617 } 623 }
618 624
619 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 625 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
620 if (tray_) 626 if (tray_)
621 tray_->UpdateAlignment(alignment); 627 tray_->UpdateAlignment(alignment);
622 } 628 }
623 629
624 } // namespace ash 630 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698